decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // eax
int v4; // eax
char *v5; // rax
int *v6; // rax
char *v7; // rax
int *v8; // rax
char *v9; // rax
char *v10; // rax
int v11; // eax
char *v13; // rax
struct sigevent v14; // [rsp+0h] [rbp-68h] BYREF
struct itimerspec value; // [rsp+40h] [rbp-28h] BYREF

v14.sigev_notify = 2;
v14.sigev_value.sival_ptr = &timer_id;
v14._sigev_un._sigev_thread._function = (void (*)(sigval_t))timer_thread;
v14._sigev_un._sigev_thread._attribute = 0LL;
value.it_value.tv_sec = 5LL;
value.it_value.tv_nsec = 0LL;
value.it_interval.tv_sec = 5LL;
value.it_interval.tv_nsec = 0LL;
puts("Creating timer");
if ( timer_create(0, &v14, &timer_id) == -1 )
{
v6 = __errno_location();
v7 = strerror(*v6);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Create timer", "sigev_thread.c", 77LL, v7);
abort();
}
printf("Setting timer %p for 5-second expiration...\n", timer_id);
if ( timer_settime(timer_id, 0, &value, 0LL) == -1 )
{
v8 = __errno_location();
v9 = strerror(*v8);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Set timer", "sigev_thread.c", 83LL, v9);
abort();
}
v3 = pthread_mutex_lock(&mutex);
if ( v3 )
{
v10 = strerror(v3);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "sigev_thread.c", 87LL, v10);
abort();
}
while ( counter <= 4 )
{
v4 = pthread_cond_wait(&cond, &mutex);
if ( v4 )
{
v5 = strerror(v4);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Wait on condition", "sigev_thread.c", 91LL, v5);
abort();
}
}
v11 = pthread_mutex_unlock(&mutex);
if ( v11 )
{
v13 = strerror(v11);
fprintf(stderr, "%s at \"%s\":%d: %s\n", "Unlock mutex", "sigev_thread.c", 95LL, v13);
abort();
}
return 0;
}

original_code:
int main()
{
    int status;
    struct itimerspec ts;
    struct sigevent se;
    se.sigev_notify = SIGEV_THREAD;
    se.sigev_value.sival_ptr = &timer_id;
    se._sigev_un._sigev_thread._function = timer_thread;
    se._sigev_un._sigev_thread._attribute = ((void *)0);
    ts.it_value.tv_sec = 5;
    ts.it_value.tv_nsec = 0;
    ts.it_interval.tv_sec = 5;
    ts.it_interval.tv_nsec = 0;
    printf("Creating timer\n");
    status = timer_create(0, &se, &timer_id);
    if (status == -1)
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Create timer", "sigev_thread.c", 77, strerror ((*__errno_location ()))); abort (); } while (0);
    printf(
        "Setting timer %p for 5-second expiration...\n", timer_id);
    status = timer_settime(timer_id, 0, &ts, 0);
    if (status == -1)
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Set timer", "sigev_thread.c", 83, strerror ((*__errno_location ()))); abort (); } while (0);
    status = pthread_mutex_lock (&mutex);
    if (status != 0)
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Lock mutex", "sigev_thread.c", 87, strerror (status)); abort (); } while (0);
    while (counter < 5) {
        status = pthread_cond_wait (&cond, &mutex);
        if (status != 0)
            do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Wait on condition", "sigev_thread.c", 91, strerror (status)); abort (); } while (0);
    }
    status = pthread_mutex_unlock (&mutex);
    if (status != 0)
        do { fprintf (stderr, "%s at \"%s\":%d: %s\n", "Unlock mutex", "sigev_thread.c", 95, strerror (status)); abort (); } while (0);
    return 0;
}

variable_types: struct itimerspec { struct timespec { long tv_sec; long tv_nsec; } it_interval; struct timespec it_value; }

variable_types: struct sigevent { union sigval { int sival_int; void *sival_ptr; } sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t { char __size[56]; long __align; } *_attribute; } _sigev_thread; } _sigev_un; }

user_defined_types: struct itimerspec { struct timespec it_interval; struct timespec it_value; }

user_defined_types: struct sigevent { union sigval sigev_value; int sigev_signo; int sigev_notify; union { int _pad[-1]; int _tid; struct { void (*_function)(union sigval); union pthread_attr_t *_attribute; } _sigev_thread; } _sigev_un; }


repo: pjantrania/perfect-hashing

decompiled_code:
void *__fastcall table_init(size_t *a1, size_t a2, __int64 a3)
{
void *result; // rax

*a1 = a2;
_gmpz_init(a1 + 1);
_gmpz_set(a1 + 1, a3);
hash_fn_init(a1 + 3, a2);
hash_fn_generate(a1 + 3, a3);
result = calloc(a2, 0x78uLL);
a1[15] = (size_t)result;
return result;
}

canonical_decompiled_code:
void *__fastcall func0(size_t *a1, size_t a2, __int64 a3)
{
void *result; // rax

*a1 = a2;
_gmpz_init(a1 + 1);
_gmpz_set(a1 + 1, a3);
hash_fn_init(a1 + 3, a2);
hash_fn_generate(a1 + 3, a3);
result = calloc(a2, 0x78uLL);
a1[15] = (size_t)result;
return result;
}

original_code:
void table_init(table *t, ulint size, mpz_t universe_size) {
  t->size = size;
  __gmpz_init(t->universe_size);
  __gmpz_set(t->universe_size, universe_size);
  hash_fn_init(&t->primary_hash_function, size);
  hash_fn_generate(&t->primary_hash_function, universe_size);
  t->primary_table = (table_node *) calloc( size, sizeof(table_node) );
}

canonical_original_code:
void table_init(struct table_t *t, unsigned long size, struct __mpz_struct universe_size[1]) {
  t->size = size;
  __gmpz_init(t->universe_size);
  __gmpz_set(t->universe_size, universe_size);
  hash_fn_init(&t->primary_hash_function, size);
  hash_fn_generate(&t->primary_hash_function, universe_size);
  t->primary_table = (struct table_node_t *) calloc( size, sizeof(table_node) );
}

variable_types: struct table_t { unsigned long size; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } universe_size[1]; struct hash_fn_t { struct __mpz_struct p[1]; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct m[1]; struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } state[1]; } primary_hash_function; struct table_node_t { unsigned long count; struct bucket_node_t { unsigned long long value; struct bucket_node_t *next; } *bucket_head; struct hash_fn_t secondary_hash_function; unsigned long long *secondary_table; } *primary_table; } *

variable_types:
size
unsigned long

return_type: void

user_defined_types: struct table_t { unsigned long size; struct __mpz_struct universe_size[1]; struct hash_fn_t primary_hash_function; struct table_node_t *primary_table; }

user_defined_types: struct table_node_t { unsigned long count; struct bucket_node_t *bucket_head; struct hash_fn_t secondary_hash_function; unsigned long long *secondary_table; }

user_defined_types: struct hash_fn_t { struct __mpz_struct p[1]; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct m[1]; struct __gmp_randstate_struct state[1]; }

user_defined_types: struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t _mp_alg; union { void *_mp_lc; } _mp_algdata; }


decompiled_code:
__int64 __fastcall table_insert(__int64 a1, __int64 a2)
{
__int64 v2; // rax
_BYTE v4[16]; // [rsp+0h] [rbp-38h] BYREF
char v5[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_init(v5);
_gmpz_init(v4);
_gmpz_set_ui(v5, a2);
hash_integer(a1 + 24, v4, v5);
v2 = _gmpz_get_ui(v4);
add_to_bucket((_QWORD *)(*(_QWORD *)(a1 + 120) + 120 * v2), a2);
_gmpz_clear(v5);
return _gmpz_clear(v4);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
__int64 v2; // rax
_BYTE v4[16]; // [rsp+0h] [rbp-38h] BYREF
char v5[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_init(v5);
_gmpz_init(v4);
_gmpz_set_ui(v5, a2);
hash_integer(a1 + 24, v4, v5);
v2 = _gmpz_get_ui(v4);
add_to_bucket((_QWORD *)(*(_QWORD *)(a1 + 120) + 120 * v2), a2);
_gmpz_clear(v5);
return _gmpz_clear(v4);
}

original_code:
void table_insert(table *t, unsigned long long v) {
  mpz_t value, position;
  ulint p;
  __gmpz_init(value);
  __gmpz_init(position);
  __gmpz_set_ui(value, v);
  hash_integer((const hash_fn *) &t->primary_hash_function, position, value);
  add_to_bucket(&t->primary_table[__gmpz_get_ui(position)], v);
  __gmpz_clear(value);
  __gmpz_clear(position);
}

canonical_original_code:
void table_insert(struct table_t *t, unsigned long long v) {
  struct __mpz_struct value[1]; struct __mpz_struct position[1];
  unsigned long p;
  __gmpz_init(value);
  __gmpz_init(position);
  __gmpz_set_ui(value, v);
  hash_integer((struct hash_fn_t *) &t->primary_hash_function, position, value);
  add_to_bucket(&t->primary_table[__gmpz_get_ui(position)], v);
  __gmpz_clear(value);
  __gmpz_clear(position);
}

variable_types:
v
unsigned long long

variable_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } [1]

variable_types:
p
unsigned long

user_defined_types: enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr }

user_defined_types: struct bucket_node_t { unsigned long long value; struct bucket_node_t *next; }


original_code:
unsigned long long pop_bucket(table_node *node) {
  unsigned long long value;
  bucket_node *temp;
  value = node->bucket_head->value;
  temp = node->bucket_head;
  node->bucket_head = node->bucket_head->next;
  free(temp);
  return value;
}

canonical_original_code:
unsigned long long pop_bucket(struct table_node_t *node) {
  unsigned long long value;
  struct bucket_node_t *temp;
  value = node->bucket_head->value;
  temp = node->bucket_head;
  node->bucket_head = node->bucket_head->next;
  free(temp);
  return value;
}

variable_types: struct table_node_t { unsigned long count; struct bucket_node_t { unsigned long long value; struct bucket_node_t *next; } *bucket_head; struct hash_fn_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } p[1]; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct m[1]; struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } state[1]; } secondary_hash_function; unsigned long long *secondary_table; } *

variable_types:
value
unsigned long long

return_type: unsigned long long


decompiled_code:
__int64 __fastcall table_node_insert(__int64 a1, __int64 a2)
{
__int64 v2; // r12
_QWORD *v3; // rcx
__int64 result; // rax
_BYTE v5[16]; // [rsp+0h] [rbp-38h] BYREF
char v6[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_init(v6);
_gmpz_init(v5);
_gmpz_set_ui(v6, a2);
hash_integer(a1 + 16, v5, v6);
v2 = _gmpz_get_ui(v5);
_gmpz_clear(v6);
_gmpz_clear(v5);
v3 = (_QWORD *)(*(_QWORD *)(a1 + 112) + 8 * v2);
result = 0LL;
if ( *v3 != a2 )
{
result = 1LL;
if ( !*v3 )
{
*v3 = a2;
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1, __int64 a2)
{
__int64 v2; // r12
_QWORD *v3; // rcx
__int64 result; // rax
_BYTE v5[16]; // [rsp+0h] [rbp-38h] BYREF
char v6[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_init(v6);
_gmpz_init(v5);
_gmpz_set_ui(v6, a2);
hash_integer(a1 + 16, v5, v6);
v2 = _gmpz_get_ui(v5);
_gmpz_clear(v6);
_gmpz_clear(v5);
v3 = (_QWORD *)(*(_QWORD *)(a1 + 112) + 8 * v2);
result = 0LL;
if ( *v3 != a2 )
{
result = 1LL;
if ( !*v3 )
{
*v3 = a2;
result = 0LL;
}
}
return result;
}

original_code:
int table_node_insert(table_node *node, unsigned long long v) {
  mpz_t value, position;
  ulint p;
  __gmpz_init(value);
  __gmpz_init(position);
  __gmpz_set_ui(value, v);
  hash_integer((const hash_fn *) &node->secondary_hash_function, position, value);
  p = __gmpz_get_ui(position);
  __gmpz_clear(value);
  __gmpz_clear(position);
  if ( node->secondary_table[p] == v ) {
    return 0;
  } else if ( node->secondary_table[p] != 0 ) {
    return 1;
  } else {
    node->secondary_table[p] = v;
    return 0;
  }
}

canonical_original_code:
int table_node_insert(struct table_node_t *node, unsigned long long v) {
  struct __mpz_struct value[1]; struct __mpz_struct position[1];
  unsigned long p;
  __gmpz_init(value);
  __gmpz_init(position);
  __gmpz_set_ui(value, v);
  hash_integer((struct hash_fn_t *) &node->secondary_hash_function, position, value);
  p = __gmpz_get_ui(position);
  __gmpz_clear(value);
  __gmpz_clear(position);
  if ( node->secondary_table[p] == v ) {
    return 0;
  } else if ( node->secondary_table[p] != 0 ) {
    return 1;
  } else {
    node->secondary_table[p] = v;
    return 0;
  }
}

return_type: int

user_defined_types: struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; }


decompiled_code:
_BOOL8 __fastcall table_node_find(__int64 a1, __int64 a2)
{
__int64 v2; // r12
_BYTE v4[16]; // [rsp+0h] [rbp-38h] BYREF
char v5[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_init(v5);
_gmpz_init(v4);
_gmpz_set_ui(v5, a2);
hash_integer(a1 + 16, v4, v5);
v2 = _gmpz_get_ui(v4);
_gmpz_clear(v5);
_gmpz_clear(v4);
return *(_QWORD *)(*(_QWORD *)(a1 + 112) + 8 * v2) == a2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 v2; // r12
_BYTE v4[16]; // [rsp+0h] [rbp-38h] BYREF
char v5[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_init(v5);
_gmpz_init(v4);
_gmpz_set_ui(v5, a2);
hash_integer(a1 + 16, v4, v5);
v2 = _gmpz_get_ui(v4);
_gmpz_clear(v5);
_gmpz_clear(v4);
return *(_QWORD *)(*(_QWORD *)(a1 + 112) + 8 * v2) == a2;
}

original_code:
int table_node_find(table_node *node, unsigned long long v) {
  mpz_t value, position;
  ulint p;
  __gmpz_init(value);
  __gmpz_init(position);
  __gmpz_set_ui(value, v);
  hash_integer((const hash_fn *) &node->secondary_hash_function, position, value);
  p = __gmpz_get_ui(position);
  __gmpz_clear(value);
  __gmpz_clear(position);
  return (node->secondary_table[p] == v ? 1 : 0);
}

canonical_original_code:
int table_node_find(struct table_node_t *node, unsigned long long v) {
  struct __mpz_struct value[1]; struct __mpz_struct position[1];
  unsigned long p;
  __gmpz_init(value);
  __gmpz_init(position);
  __gmpz_set_ui(value, v);
  hash_integer((struct hash_fn_t *) &node->secondary_hash_function, position, value);
  p = __gmpz_get_ui(position);
  __gmpz_clear(value);
  __gmpz_clear(position);
  return (node->secondary_table[p] == v ? 1 : 0);
}


decompiled_code:
_BOOL8 __fastcall table_find(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
_QWORD *v3; // rdi
_BOOL8 result; // rax
_BYTE v5[16]; // [rsp+0h] [rbp-38h] BYREF
char v6[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_init(v6);
_gmpz_init(v5);
_gmpz_set_ui(v6, a2);
hash_integer(a1 + 24, v5, v6);
v2 = _gmpz_get_ui(v5);
_gmpz_clear(v6);
_gmpz_clear(v5);
v3 = (_QWORD *)(*(_QWORD *)(a1 + 120) + 120 * v2);
result = 0LL;
if ( *v3 )
result = table_node_find((__int64)v3, a2);
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 v2; // rbp
_QWORD *v3; // rdi
_BOOL8 result; // rax
_BYTE v5[16]; // [rsp+0h] [rbp-38h] BYREF
char v6[40]; // [rsp+10h] [rbp-28h] BYREF

_gmpz_init(v6);
_gmpz_init(v5);
_gmpz_set_ui(v6, a2);
hash_integer(a1 + 24, v5, v6);
v2 = _gmpz_get_ui(v5);
_gmpz_clear(v6);
_gmpz_clear(v5);
v3 = (_QWORD *)(*(_QWORD *)(a1 + 120) + 120 * v2);
result = 0LL;
if ( *v3 )
result = func4((__int64)v3, a2);
return result;
}

original_code:
int table_find(table *t, unsigned long long v) {
  mpz_t value, position;
  ulint p;
  __gmpz_init(value);
  __gmpz_init(position);
  __gmpz_set_ui(value, v);
  hash_integer((const hash_fn *) &t->primary_hash_function, position, value);
  p = __gmpz_get_ui(position);
  __gmpz_clear(value);
  __gmpz_clear(position);
  return (t->primary_table[p].count == 0 ? 0 : table_node_find(&t->primary_table[p], v));
}

canonical_original_code:
int table_find(struct table_t *t, unsigned long long v) {
  struct __mpz_struct value[1]; struct __mpz_struct position[1];
  unsigned long p;
  __gmpz_init(value);
  __gmpz_init(position);
  __gmpz_set_ui(value, v);
  hash_integer((struct hash_fn_t *) &t->primary_hash_function, position, value);
  p = __gmpz_get_ui(position);
  __gmpz_clear(value);
  __gmpz_clear(position);
  return (t->primary_table[p].count == 0 ? 0 : table_node_find(&t->primary_table[p], v));
}


decompiled_code:
void __fastcall destroy_bucket(__int64 a1)
{
unsigned __int64 v1; // rbx

if ( *(_QWORD *)a1 )
{
v1 = 0LL;
do
{
pop_bucket(a1);
++v1;
}
while ( *(_QWORD *)a1 > v1 );
}
hash_fn_destroy(a1 + 16);
free(*(void **)(a1 + 112));
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
unsigned __int64 v1; // rbx

if ( *(_QWORD *)a1 )
{
v1 = 0LL;
do
{
func2(a1);
++v1;
}
while ( *(_QWORD *)a1 > v1 );
}
hash_fn_destroy(a1 + 16);
free(*(void **)(a1 + 112));
}

original_code:
void destroy_bucket(table_node *node) {
  ulint i;
  for ( i = 0; i < node->count; i++ ) {
    pop_bucket(node);
  }
  hash_fn_destroy(&node->secondary_hash_function);
  free(node->secondary_table);
}

canonical_original_code:
void destroy_bucket(struct table_node_t *node) {
  unsigned long i;
  for ( i = 0; i < node->count; i++ ) {
    pop_bucket(node);
  }
  hash_fn_destroy(&node->secondary_hash_function);
  free(node->secondary_table);
}

variable_types:
i
unsigned long


original_code:
void table_destroy(table *t) {
  ulint i;
  hash_fn_destroy(&t->primary_hash_function);
  __gmpz_clear(t->universe_size);
  for ( i = 0; i < t->size; i++ ) {
    if ( t->primary_table[i].bucket_head != ((void *)0) )
      destroy_bucket(&t->primary_table[i]);
    else if ( t->primary_table[i].count > 0 ) {
      hash_fn_destroy(&t->primary_table[i].secondary_hash_function);
      free(t->primary_table[i].secondary_table);
    }
  }
  free(t->primary_table);
}

canonical_original_code:
void table_destroy(struct table_t *t) {
  unsigned long i;
  hash_fn_destroy(&t->primary_hash_function);
  __gmpz_clear(t->universe_size);
  for ( i = 0; i < t->size; i++ ) {
    if ( t->primary_table[i].bucket_head != ((void *)0) )
      destroy_bucket(&t->primary_table[i]);
    else if ( t->primary_table[i].count > 0 ) {
      hash_fn_destroy(&t->primary_table[i].secondary_hash_function);
      free(t->primary_table[i].secondary_table);
    }
  }
  free(t->primary_table);
}


decompiled_code:
size_t *__fastcall table_rehash(void *ptr)
{
size_t *v2; // r14
__int64 v3; // rbp
unsigned __int64 v4; // r13
unsigned __int64 *v5; // rdi
unsigned __int64 v6; // rbx
__int64 v7; // rax

v2 = (size_t *)calloc(1uLL, 0x80uLL);
table_init(v2, *(_QWORD *)ptr, (__int64)ptr + 8);
if ( *(_QWORD *)ptr )
{
v3 = 0LL;
v4 = 0LL;
do
{
v5 = (unsigned __int64 *)(*((_QWORD *)ptr + 15) + v3);
if ( *v5 )
{
v6 = 0LL;
do
{
v7 = pop_bucket((__int64)v5);
table_insert((__int64)v2, v7);
++v6;
v5 = (unsigned __int64 *)(*((_QWORD *)ptr + 15) + v3);
}
while ( *v5 > v6 );
*v5 = 0LL;
}
++v4;
v3 += 120LL;
}
while ( *(_QWORD *)ptr > v4 );
}
table_destroy((__int64)ptr);
free(ptr);
return v2;
}

canonical_decompiled_code:
size_t *__fastcall func8(void *ptr)
{
size_t *v2; // r14
__int64 v3; // rbp
unsigned __int64 v4; // r13
unsigned __int64 *v5; // rdi
unsigned __int64 v6; // rbx
__int64 v7; // rax

v2 = (size_t *)calloc(1uLL, 0x80uLL);
func0(v2, *(_QWORD *)ptr, (__int64)ptr + 8);
if ( *(_QWORD *)ptr )
{
v3 = 0LL;
v4 = 0LL;
do
{
v5 = (unsigned __int64 *)(*((_QWORD *)ptr + 15) + v3);
if ( *v5 )
{
v6 = 0LL;
do
{
v7 = func2((__int64)v5);
func1((__int64)v2, v7);
++v6;
v5 = (unsigned __int64 *)(*((_QWORD *)ptr + 15) + v3);
}
while ( *v5 > v6 );
*v5 = 0LL;
}
++v4;
v3 += 120LL;
}
while ( *(_QWORD *)ptr > v4 );
}
func7((__int64)ptr);
free(ptr);
return v2;
}

original_code:
table * table_rehash(table *t) {
  table *new_table;
  ulint i, j;
  new_table = (table *) calloc( 1, sizeof(table) );
  table_init(new_table, t->size, t->universe_size);
  for ( i = 0; i < t->size; i++ ) {
    if ( t->primary_table[i].count > 0 ) {
      for ( j = 0; j < t->primary_table[i].count; j++ ) {
 table_insert(new_table, pop_bucket(&t->primary_table[i]));
      }
      t->primary_table[i].count = 0;
    }
  }
  table_destroy(t);
  free(t);
  return new_table;
}

canonical_original_code:
struct table_t *table_rehash(struct table_t *t) {
  struct table_t *new_table;
  unsigned long i; unsigned long j;
  new_table = (struct table_t *) calloc( 1, sizeof(table) );
  table_init(new_table, t->size, t->universe_size);
  for ( i = 0; i < t->size; i++ ) {
    if ( t->primary_table[i].count > 0 ) {
      for ( j = 0; j < t->primary_table[i].count; j++ ) {
 table_insert(new_table, pop_bucket(&t->primary_table[i]));
      }
      t->primary_table[i].count = 0;
    }
  }
  table_destroy(t);
  free(t);
  return new_table;
}

variable_types:
t
struct table_t *

variable_types:
j
unsigned long

return_type: struct table_t { unsigned long size; struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } universe_size[1]; struct hash_fn_t { struct __mpz_struct p[1]; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct m[1]; struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } state[1]; } primary_hash_function; struct table_node_t { unsigned long count; struct bucket_node_t { unsigned long long value; struct bucket_node_t *next; } *bucket_head; struct hash_fn_t secondary_hash_function; unsigned long long *secondary_table; } *primary_table; } *


decompiled_code:
__int64 __fastcall table_build(void *ptr)
{
__int64 v2; // r12
__int64 v3; // rax
unsigned __int64 v4; // rbp
unsigned __int64 v5; // r12
size_t v6; // rax
__int64 *v7; // r14
unsigned __int64 v8; // r13
unsigned __int64 v9; // r13
__int64 v10; // rbp
size_t v11; // rax
__int64 v12; // rax
char v14[16]; // [rsp+10h] [rbp-58h] BYREF
char v15[72]; // [rsp+20h] [rbp-48h] BYREF

_gmpz_init(v15);
_gmpz_set_ui(v15, 0LL);
puts("Checking space constraint...");
v2 = 21LL;
while ( 1 )
{
v3 = *(_QWORD *)ptr;
if ( *(_QWORD *)ptr )
{
v4 = 0LL;
do
{
_gmpz_add_ui(
v15,
v15,
*(_QWORD *)(*((_QWORD *)ptr + 15) + 120 * v4) * *(_QWORD *)(*((_QWORD *)ptr + 15) + 120 * v4));
++v4;
v3 = *(_QWORD *)ptr;
}
while ( *(_QWORD *)ptr > v4 );
}
if ( (int)_gmpz_cmp_ui(v15, 6 * v3) <= 0 )
break;
if ( !--v2 )
{
puts("Too many iterations of size control loop");
exit(1);
}
ptr = table_rehash(ptr);
}
_gmpz_clear(v15);
_gmpz_init(v14);
puts("Constructing secondary tables...");
if ( *(_QWORD *)ptr )
{
v5 = 0LL;
do
{
v10 = *((_QWORD *)ptr + 15) + 120 * v5;
if ( *(_QWORD *)v10 )
{
_gmpz_set_ui(v14, *(_QWORD *)v10 * *(_QWORD *)v10);
_gmpz_nextprime(v14);
v11 = _gmpz_get_ui(v14);
*(_QWORD *)(v10 + 112) = calloc(v11, 8uLL);
v12 = _gmpz_get_ui(v14);
hash_fn_init(v10 + 16, v12);
hash_fn_generate(v10 + 16, (char *)ptr + 8);
v7 = *(__int64 **)(v10 + 8);
if ( *(_QWORD *)v10 )
{
v8 = 0LL;
do
{
if ( (unsigned int)table_node_insert(v10, *v7) == 1 )
{
hash_fn_generate(v10 + 16, (char *)ptr + 8);
free(*(void **)(v10 + 112));
v6 = _gmpz_get_ui(v14);
*(_QWORD *)(v10 + 112) = calloc(v6, 8uLL);
v7 = *(__int64 **)(v10 + 8);
v8 = 0LL;
}
else
{
if ( *(_QWORD *)v10 - 1LL > v8 )
v7 = (__int64 *)v7[1];
++v8;
}
}
while ( *(_QWORD *)v10 > v8 );
if ( *(_QWORD *)v10 )
{
v9 = 0LL;
do
{
pop_bucket(v10);
++v9;
}
while ( *(_QWORD *)v10 > v9 );
}
}
}
++v5;
}
while ( *(_QWORD *)ptr > v5 );
}
return _gmpz_clear(v14);
}

canonical_decompiled_code:
__int64 __fastcall func9(void *ptr)
{
__int64 v2; // r12
__int64 v3; // rax
unsigned __int64 v4; // rbp
unsigned __int64 v5; // r12
size_t v6; // rax
__int64 *v7; // r14
unsigned __int64 v8; // r13
unsigned __int64 v9; // r13
__int64 v10; // rbp
size_t v11; // rax
__int64 v12; // rax
char v14[16]; // [rsp+10h] [rbp-58h] BYREF
char v15[72]; // [rsp+20h] [rbp-48h] BYREF

_gmpz_init(v15);
_gmpz_set_ui(v15, 0LL);
puts("Checking space constraint...");
v2 = 21LL;
while ( 1 )
{
v3 = *(_QWORD *)ptr;
if ( *(_QWORD *)ptr )
{
v4 = 0LL;
do
{
_gmpz_add_ui(
v15,
v15,
*(_QWORD *)(*((_QWORD *)ptr + 15) + 120 * v4) * *(_QWORD *)(*((_QWORD *)ptr + 15) + 120 * v4));
++v4;
v3 = *(_QWORD *)ptr;
}
while ( *(_QWORD *)ptr > v4 );
}
if ( (int)_gmpz_cmp_ui(v15, 6 * v3) <= 0 )
break;
if ( !--v2 )
{
puts("Too many iterations of size control loop");
exit(1);
}
ptr = func8(ptr);
}
_gmpz_clear(v15);
_gmpz_init(v14);
puts("Constructing secondary tables...");
if ( *(_QWORD *)ptr )
{
v5 = 0LL;
do
{
v10 = *((_QWORD *)ptr + 15) + 120 * v5;
if ( *(_QWORD *)v10 )
{
_gmpz_set_ui(v14, *(_QWORD *)v10 * *(_QWORD *)v10);
_gmpz_nextprime(v14);
v11 = _gmpz_get_ui(v14);
*(_QWORD *)(v10 + 112) = calloc(v11, 8uLL);
v12 = _gmpz_get_ui(v14);
hash_fn_init(v10 + 16, v12);
hash_fn_generate(v10 + 16, (char *)ptr + 8);
v7 = *(__int64 **)(v10 + 8);
if ( *(_QWORD *)v10 )
{
v8 = 0LL;
do
{
if ( (unsigned int)func3(v10, *v7) == 1 )
{
hash_fn_generate(v10 + 16, (char *)ptr + 8);
free(*(void **)(v10 + 112));
v6 = _gmpz_get_ui(v14);
*(_QWORD *)(v10 + 112) = calloc(v6, 8uLL);
v7 = *(__int64 **)(v10 + 8);
v8 = 0LL;
}
else
{
if ( *(_QWORD *)v10 - 1LL > v8 )
v7 = (__int64 *)v7[1];
++v8;
}
}
while ( *(_QWORD *)v10 > v8 );
if ( *(_QWORD *)v10 )
{
v9 = 0LL;
do
{
func2(v10);
++v9;
}
while ( *(_QWORD *)v10 > v9 );
}
}
}
++v5;
}
while ( *(_QWORD *)ptr > v5 );
}
return _gmpz_clear(v14);
}

original_code:
void table_build(table *t) {
  ulint i, j, r, bucket_size, count_iter;
  mpz_t total_size, node_size;
  table_node *n;
  bucket_node *iter;
  __gmpz_init(total_size);
  __gmpz_set_ui(total_size, 0);
  count_iter = 0;
  printf("Checking space constraint...\n");
  for ( ;; ) {
    for ( i = 0; i < t->size; i++ ) {
      bucket_size = t->primary_table[i].count;
      bucket_size *= bucket_size;
      __gmpz_add_ui(total_size, total_size, bucket_size);
    }
    count_iter++;
    if ( (__builtin_constant_p ((t->size * 6)) && ((t->size * 6)) == 0 ? ((total_size)->_mp_size < 0 ? -1 : (total_size)->_mp_size > 0) : __gmpz_cmp_ui (total_size,(t->size * 6))) > 0 ) {
      if ( count_iter > 20 ) {
 printf("Too many iterations of size control loop\n");
 exit(1);
      }
      t = table_rehash(t);
    } else
      break;
  }
  __gmpz_clear(total_size);
  __gmpz_init(node_size);
  printf("Constructing secondary tables...\n");
  count_iter = 0;
  for ( i = 0; i < t->size; i++ ) {
    if ( t->primary_table[i].count > 0 ) {
      n = &t->primary_table[i];
      __gmpz_set_ui(node_size, n->count * n->count);
      __gmpz_nextprime(node_size, node_size);
      n->secondary_table = (unsigned long long*) calloc(__gmpz_get_ui(node_size), sizeof(unsigned long long));
      hash_fn_init(&n->secondary_hash_function, __gmpz_get_ui(node_size));
      hash_fn_generate(&n->secondary_hash_function, t->universe_size);
      j = 0;
      iter = n->bucket_head;
      while ( j < n->count ) {
 r = table_node_insert(n, iter->value);
 if ( r == 1 ) {
   hash_fn_generate(&n->secondary_hash_function, t->universe_size);
   free(n->secondary_table);
   n->secondary_table = (unsigned long long*) calloc(__gmpz_get_ui(node_size), sizeof(unsigned long long));
   iter = n->bucket_head;
   j = 0;
   continue;
 } else if ( j < n->count - 1 ) {
   iter = iter->next;
 }
 j++;
      }
      for ( j = 0; j < n->count; j++ )
 pop_bucket(n);
    }
  }
  __gmpz_clear(node_size);
}

canonical_original_code:
void table_build(struct table_t *t) {
  unsigned long i; unsigned long j; unsigned long r; unsigned long bucket_size; unsigned long count_iter;
  struct __mpz_struct total_size[1]; struct __mpz_struct node_size[1];
  struct table_node_t *n;
  struct bucket_node_t *iter;
  __gmpz_init(total_size);
  __gmpz_set_ui(total_size, 0);
  count_iter = 0;
  printf("Checking space constraint...\n");
  for ( ;; ) {
    for ( i = 0; i < t->size; i++ ) {
      bucket_size = t->primary_table[i].count;
      bucket_size *= bucket_size;
      __gmpz_add_ui(total_size, total_size, bucket_size);
    }
    count_iter++;
    if ( (__builtin_constant_p ((t->size * 6)) && ((t->size * 6)) == 0 ? ((total_size)->_mp_size < 0 ? -1 : (total_size)->_mp_size > 0) : __gmpz_cmp_ui (total_size,(t->size * 6))) > 0 ) {
      if ( count_iter > 20 ) {
 printf("Too many iterations of size control loop\n");
 exit(1);
      }
      t = table_rehash(t);
    } else
      break;
  }
  __gmpz_clear(total_size);
  __gmpz_init(node_size);
  printf("Constructing secondary tables...\n");
  count_iter = 0;
  for ( i = 0; i < t->size; i++ ) {
    if ( t->primary_table[i].count > 0 ) {
      n = &t->primary_table[i];
      __gmpz_set_ui(node_size, n->count * n->count);
      __gmpz_nextprime(node_size, node_size);
      n->secondary_table = (unsigned long long *) calloc(__gmpz_get_ui(node_size), sizeof(unsigned long long));
      hash_fn_init(&n->secondary_hash_function, __gmpz_get_ui(node_size));
      hash_fn_generate(&n->secondary_hash_function, t->universe_size);
      j = 0;
      iter = n->bucket_head;
      while ( j < n->count ) {
 r = table_node_insert(n, iter->value);
 if ( r == 1 ) {
   hash_fn_generate(&n->secondary_hash_function, t->universe_size);
   free(n->secondary_table);
   n->secondary_table = (unsigned long long *) calloc(__gmpz_get_ui(node_size), sizeof(unsigned long long));
   iter = n->bucket_head;
   j = 0;
   continue;
 } else if ( j < n->count - 1 ) {
   iter = iter->next;
 }
 j++;
      }
      for ( j = 0; j < n->count; j++ )
 pop_bucket(n);
    }
  }
  __gmpz_clear(node_size);
}

variable_types:
r
unsigned long

variable_types: struct bucket_node_t { unsigned long long value; struct bucket_node_t *next; } *


decompiled_code:
__int64 __fastcall hash_fn_init(__int64 a1, __int64 a2)
{
_gmpz_init(a1 + 16);
_gmpz_init(a1 + 32);
_gmpz_init(a1);
_gmpz_init(a1 + 48);
_gmp_randinit_default(a1 + 64);
return _gmpz_set_ui(a1 + 48, a2);
}

canonical_decompiled_code:
__int64 __fastcall func0(__int64 a1, __int64 a2)
{
_gmpz_init(a1 + 16);
_gmpz_init(a1 + 32);
_gmpz_init(a1);
_gmpz_init(a1 + 48);
_gmp_randinit_default(a1 + 64);
return _gmpz_set_ui(a1 + 48, a2);
}

original_code:
void hash_fn_init(hash_fn *f, ulint table_size) {
  __gmpz_init(f->a);
  __gmpz_init(f->b);
  __gmpz_init(f->p);
  __gmpz_init(f->m);
  __gmp_randinit_default(f->state);
  __gmpz_set_ui(f->m, table_size);
}

canonical_original_code:
void hash_fn_init(struct hash_fn_t *f, unsigned long table_size) {
  __gmpz_init(f->a);
  __gmpz_init(f->b);
  __gmpz_init(f->p);
  __gmpz_init(f->m);
  __gmp_randinit_default(f->state);
  __gmpz_set_ui(f->m, table_size);
}

variable_types: struct hash_fn_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } p[1]; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct m[1]; struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } state[1]; } *


decompiled_code:
__int64 __fastcall hash_fn_generate(__int64 a1, __int64 a2)
{
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v4, 0LL);
_gmp_randseed_ui(a1 + 64, v4.tv_usec + 1000000 * v4.tv_sec);
_gmpz_nextprime(a1, a2);
_gmpz_urandomm(a1 + 16, a1 + 64, a1);
return _gmpz_urandomm(a1 + 32, a1 + 64, a1);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
struct timeval v4; // [rsp+0h] [rbp-28h] BYREF

gettimeofday(&v4, 0LL);
_gmp_randseed_ui(a1 + 64, v4.tv_usec + 1000000 * v4.tv_sec);
_gmpz_nextprime(a1, a2);
_gmpz_urandomm(a1 + 16, a1 + 64, a1);
return _gmpz_urandomm(a1 + 32, a1 + 64, a1);
}

original_code:
void hash_fn_generate(hash_fn *f, mpz_t u) {
  struct timeval time;
  ulint microtime;
  gettimeofday(&time, ((void *)0));
  microtime = (ulint)time.tv_sec*1000000 + (ulint)time.tv_usec;
  __gmp_randseed_ui(f->state, microtime);
  __gmpz_nextprime(f->p, u);
  __gmpz_urandomm(f->a, f->state, f->p);
  __gmpz_urandomm(f->b, f->state, f->p);
}

canonical_original_code:
void hash_fn_generate(struct hash_fn_t *f, struct __mpz_struct u[1]) {
  struct timeval time;
  unsigned long microtime;
  gettimeofday(&time, ((void *)0));
  microtime = (unsigned long)time.tv_sec*1000000 + (unsigned long)time.tv_usec;
  __gmp_randseed_ui(f->state, microtime);
  __gmpz_nextprime(f->p, u);
  __gmpz_urandomm(f->a, f->state, f->p);
  __gmpz_urandomm(f->b, f->state, f->p);
}

variable_types:
u
struct __mpz_struct [1]

variable_types: struct timeval { long tv_sec; long tv_usec; }

variable_types:
microtime
unsigned long


decompiled_code:
__int64 __fastcall hash_integer(__int64 a1, __int64 a2, __int64 a3)
{
_gmpz_set_ui(a2, 0LL);
_gmpz_mul(a2, a1 + 16, a3);
_gmpz_add(a2, a2, a1 + 32);
_gmpz_mod(a2, a2, a1);
return _gmpz_mod(a2, a2, a1 + 48);
}

original_code:
void hash_integer(const hash_fn *f, mpz_t out, mpz_t integer) {
  __gmpz_set_ui(out, 0);
  __gmpz_mul(out, f->a, integer);
  __gmpz_add(out, out, f->b);
  __gmpz_mod(out, out, f->p);
  __gmpz_mod(out, out, f->m);
}

canonical_original_code:
void hash_integer(struct hash_fn_t *f, struct __mpz_struct out[1], struct __mpz_struct integer[1]) {
  __gmpz_set_ui(out, 0);
  __gmpz_mul(out, f->a, integer);
  __gmpz_add(out, out, f->b);
  __gmpz_mod(out, out, f->p);
  __gmpz_mod(out, out, f->m);
}

variable_types:
out
struct __mpz_struct [1]

variable_types:
integer
struct __mpz_struct [1]


decompiled_code:
__int64 __fastcall hash_string(__int64 a1, __int64 a2, const char *a3)
{
size_t v5; // rax
unsigned __int64 v6; // r14
unsigned int v7; // ebp
__int64 v8; // rbx
__int64 v9; // rsi
char v10; // si
_BYTE v12[16]; // [rsp+0h] [rbp-C8h] BYREF
char v13[16]; // [rsp+10h] [rbp-B8h] BYREF
char v14[16]; // [rsp+20h] [rbp-A8h] BYREF
char v15[16]; // [rsp+30h] [rbp-98h] BYREF
char v16[136]; // [rsp+40h] [rbp-88h] BYREF

_gmpz_init(v14);
_gmpz_init(v13);
_gmpz_init(v12);
_gmpz_set_ui(v14, 26LL);
_gmpz_set_ui(a2, 0LL);
hash_fn_init((__int64)v15, 26LL);
hash_fn_generate((__int64)v15, a1 + 48);
v5 = strlen(a3);
if ( v5 )
{
v6 = v5;
v7 = 0;
v8 = 0LL;
do
{
v10 = a3[v8];
if ( v10 > 122 )
v9 = v10 - 65;
else
v9 = v10 - 97;
_gmpz_set_ui(v13, v9);
_gmpz_powm_ui(v12, v16, v8, v15);
_gmpz_addmul(a2, v12, v13);
v8 = ++v7;
}
while ( v7 < v6 );
}
_gmpz_mod(a2, a2, v15);
return hash_integer(a1, a2, a2);
}

original_code:
void hash_string(const hash_fn *f, mpz_t out, const char *string) {
  hash_fn inner_hash;
  mpz_t u, xi, ai;
  size_t l;
  unsigned int i;
  __gmpz_init(u);
  __gmpz_init(xi);
  __gmpz_init(ai);
  __gmpz_set_ui(u, 26);
  __gmpz_set_ui(out, 0);
  hash_fn_init(&inner_hash, 26);
  hash_fn_generate(&inner_hash, f->m);
  l = strlen(string);
  for ( i = 0; i < l; i++ ) {
    ulint x = ( string[i] <= 'z' ?
  string[i] - 'a' :
  string[i] - 'A' );
    __gmpz_set_ui(xi, x);
    __gmpz_powm_ui(ai, inner_hash.a, (ulint)i, inner_hash.p);
    __gmpz_addmul(out, ai, xi);
  }
  __gmpz_mod(out, out, inner_hash.p);
  hash_integer(f, out, out);
}

canonical_original_code:
void hash_string(struct hash_fn_t *f, struct __mpz_struct out[1], char *string) {
  struct hash_fn_t inner_hash;
  struct __mpz_struct u[1]; struct __mpz_struct xi[1]; struct __mpz_struct ai[1];
  unsigned long l;
  unsigned int i;
  __gmpz_init(u);
  __gmpz_init(xi);
  __gmpz_init(ai);
  __gmpz_set_ui(u, 26);
  __gmpz_set_ui(out, 0);
  hash_fn_init(&inner_hash, 26);
  hash_fn_generate(&inner_hash, f->m);
  l = strlen(string);
  for ( i = 0; i < l; i++ ) {
    unsigned long x = ( string[i] <= 'z' ?
  string[i] - 'a' :
  string[i] - 'A' );
    __gmpz_set_ui(xi, x);
    __gmpz_powm_ui(ai, inner_hash.a, (unsigned long)i, inner_hash.p);
    __gmpz_addmul(out, ai, xi);
  }
  __gmpz_mod(out, out, inner_hash.p);
  hash_integer(f, out, out);
}

variable_types:
string
char *

variable_types: struct hash_fn_t { struct __mpz_struct { int _mp_alloc; int _mp_size; unsigned long *_mp_d; } p[1]; struct __mpz_struct a[1]; struct __mpz_struct b[1]; struct __mpz_struct m[1]; struct __gmp_randstate_struct { struct __mpz_struct _mp_seed[1]; enum gmp_randalg_t { GMP_RAND_ALG_DEFAULT=0, GMP_RAND_ALG_LC=expr } _mp_alg; union { void *_mp_lc; } _mp_algdata; } state[1]; }

variable_types:
l
unsigned long

variable_types:
i
unsigned int

variable_types:
x
unsigned long


decompiled_code:
__int64 __fastcall hash_fn_destroy(__int64 a1)
{
_gmpz_clear(a1 + 16);
_gmpz_clear(a1 + 32);
_gmpz_clear(a1);
_gmpz_clear(a1 + 48);
return _gmp_randclear(a1 + 64);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
_gmpz_clear(a1 + 16);
_gmpz_clear(a1 + 32);
_gmpz_clear(a1);
_gmpz_clear(a1 + 48);
return _gmp_randclear(a1 + 64);
}

original_code:
void hash_fn_destroy(hash_fn *f) {
  __gmpz_clear(f->a);
  __gmpz_clear(f->b);
  __gmpz_clear(f->p);
  __gmpz_clear(f->m);
  __gmp_randclear(f->state);
}

canonical_original_code:
void hash_fn_destroy(struct hash_fn_t *f) {
  __gmpz_clear(f->a);
  __gmpz_clear(f->b);
  __gmpz_clear(f->p);
  __gmpz_clear(f->m);
  __gmp_randclear(f->state);
}


repo: pjherring/task

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

result = a1;
if ( a1 )
{
if ( *(_QWORD *)(a1 + 8) != -1LL )
_InterlockedAdd64((volatile signed __int64 *)(a1 + 8), 1uLL);
}
return result;
}

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

result = a1;
if ( a1 )
{
if ( *(_QWORD *)(a1 + 8) != -1LL )
_InterlockedAdd64((volatile signed __int64 *)(a1 + 8), 1uLL);
}
return result;
}

original_code:
static inline
json_t *json_incref(json_t *json)
{
    if(json && json->refcount != (size_t)-1)
        __atomic_add_fetch(&json->refcount, 1, 2);
    return json;
}

canonical_original_code:
static inline struct json_t *json_incref(struct json_t *json)
{
    if(json && json->refcount != (unsigned long)-1)
        __atomic_add_fetch(&json->refcount, 1, 2);
    return json;
}

variable_types:
json
struct json_t *

return_type: struct json_t { enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 } type; unsigned long refcount; } *

user_defined_types: struct json_t { enum json_type type; unsigned long refcount; }


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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 )
{
result = _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 8), 0xFFFFFFFFFFFFFFFFLL);
if ( result == 1 )
result = json_delete();
}
}
return result;
}

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

if ( a1 )
{
result = *(_QWORD *)(a1 + 8);
if ( result != -1 )
{
result = _InterlockedExchangeAdd64((volatile signed __int64 *)(a1 + 8), 0xFFFFFFFFFFFFFFFFLL);
if ( result == 1 )
result = json_delete();
}
}
return result;
}

original_code:
static inline
void json_decref(json_t *json)
{
    if(json && json->refcount != (size_t)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

canonical_original_code:
static inline void json_decref(struct json_t *json)
{
    if(json && json->refcount != (unsigned long)-1 && __atomic_sub_fetch(&json->refcount, 1, 3) == 0)
        json_delete(json);
}

variable_types: struct json_t { enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 } type; unsigned long refcount; } *


decompiled_code:
__int64 __fastcall write_children_to_task(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r13
unsigned int v4; // ebp
__int64 v5; // rbx
__int64 v6; // rax

result = *(_QWORD *)(a2 + 16);
if ( result && *(int *)(result + 16) > 0 )
{
v3 = json_array();
if ( *(int *)(*(_QWORD *)(a2 + 16) + 16LL) > 0 )
{
v4 = 0;
do
{
v5 = json_object();
v6 = list_obj_at_idx(*(_QWORD *)(a2 + 16), v4);
write_task(v5, v6);
json_array_append(v3, v5);
json_decref(v5);
++v4;
}
while ( *(_DWORD *)(*(_QWORD *)(a2 + 16) + 16LL) > (signed int)v4 );
}
json_object_set(a1, (__int64)kTaskJsonChildrenKey, v3);
result = json_decref(v3);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
__int64 result; // rax
__int64 v3; // r13
unsigned int v4; // ebp
__int64 v5; // rbx
__int64 v6; // rax

result = *(_QWORD *)(a2 + 16);
if ( result && *(int *)(result + 16) > 0 )
{
v3 = json_array();
if ( *(int *)(*(_QWORD *)(a2 + 16) + 16LL) > 0 )
{
v4 = 0;
do
{
v5 = json_object();
v6 = list_obj_at_idx(*(_QWORD *)(a2 + 16), v4);
func5(v5, v6);
func2(v3, v5);
func3(v5);
++v4;
}
while ( *(_DWORD *)(*(_QWORD *)(a2 + 16) + 16LL) > (signed int)v4 );
}
func1(a1, (__int64)kTaskJsonChildrenKey, v3);
result = func3(v3);
}
return result;
}

original_code:
static void write_children_to_task(json_t* json_obj, TaskT* task) {
    if (task->children != ((void *)0) && task->children->size > 0) {
        json_t * children_json_arr;
        int child_idx;
        children_json_arr = json_array();
        for (child_idx = 0; child_idx < task->children->size; child_idx++) {
            json_t *child_json_obj;
            TaskT* child_task;
            child_json_obj = json_object();
            child_task = list_obj_at_idx(task->children, child_idx);
            write_task(child_json_obj, child_task);
            json_array_append(children_json_arr, child_json_obj);
            json_decref(child_json_obj);
        }
        json_object_set(json_obj, kTaskJsonChildrenKey, children_json_arr);
        json_decref(children_json_arr);
    }
}

canonical_original_code:
static void write_children_to_task(struct json_t *json_obj, struct TaskT *task) {
    if (task->children != ((void *)0) && task->children->size > 0) {
        struct json_t *children_json_arr;
        int child_idx;
        children_json_arr = json_array();
        for (child_idx = 0; child_idx < task->children->size; child_idx++) {
            struct json_t *child_json_obj;
            struct TaskT *child_task;
            child_json_obj = json_object();
            child_task = list_obj_at_idx(task->children, child_idx);
            write_task(child_json_obj, child_task);
            json_array_append(children_json_arr, child_json_obj);
            json_decref(child_json_obj);
        }
        json_object_set(json_obj, kTaskJsonChildrenKey, children_json_arr);
        json_decref(children_json_arr);
    }
}

variable_types: struct TaskT { char *text; struct ListT { void **values; void **last_value; int size; int capacity; } *notes; struct ListT *children; int is_complete; struct TaskT *parent; } *

user_defined_types: struct TaskT { char *text; struct ListT *notes; struct ListT *children; int is_complete; struct TaskT *parent; }

user_defined_types: enum json_type { JSON_OBJECT=0, JSON_ARRAY=1, JSON_STRING=2, JSON_INTEGER=3, JSON_REAL=4, JSON_TRUE=5, JSON_FALSE=6, JSON_NULL=7 }


decompiled_code:
__int64 __fastcall write_task(__int64 a1, __int64 a2)
{
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rax
__int64 v7; // r13
__int64 v8; // rdi
unsigned int v9; // ebx
__int64 v10; // rax
__int64 v11; // rax

v3 = json_string(*(_QWORD *)a2);
json_object_set_new(a1, kTaskJsonTextKey, v3);
if ( *(_DWORD *)(a2 + 24) == 1 )
v4 = json_true();
else
v4 = json_false();
json_object_set_new(a1, kTaskJsonIsCompleteKey, v4);
v5 = *(_QWORD *)(a2 + 8);
if ( v5 && *(int *)(v5 + 16) > 0 )
{
v7 = json_array();
v8 = *(_QWORD *)(a2 + 8);
if ( *(int *)(v8 + 16) > 0 )
{
v9 = 0;
do
{
v10 = list_obj_at_idx(v8, v9);
v11 = json_string(v10);
json_array_append_new(v7, v11);
++v9;
v8 = *(_QWORD *)(a2 + 8);
}
while ( *(_DWORD *)(v8 + 16) > (signed int)v9 );
}
json_object_set(a1, (__int64)kTaskJsonNotesKey, v7);
json_decref(v7);
}
return write_children_to_task(a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1, __int64 a2)
{
__int64 v3; // rax
__int64 v4; // rdx
__int64 v5; // rax
__int64 v7; // r13
__int64 v8; // rdi
unsigned int v9; // ebx
__int64 v10; // rax
__int64 v11; // rax

v3 = json_string(*(_QWORD *)a2);
json_object_set_new(a1, kTaskJsonTextKey, v3);
if ( *(_DWORD *)(a2 + 24) == 1 )
v4 = json_true();
else
v4 = json_false();
json_object_set_new(a1, kTaskJsonIsCompleteKey, v4);
v5 = *(_QWORD *)(a2 + 8);
if ( v5 && *(int *)(v5 + 16) > 0 )
{
v7 = json_array();
v8 = *(_QWORD *)(a2 + 8);
if ( *(int *)(v8 + 16) > 0 )
{
v9 = 0;
do
{
v10 = list_obj_at_idx(v8, v9);
v11 = json_string(v10);
json_array_append_new(v7, v11);
++v9;
v8 = *(_QWORD *)(a2 + 8);
}
while ( *(_DWORD *)(v8 + 16) > (signed int)v9 );
}
func1(a1, (__int64)kTaskJsonNotesKey, v7);
func3(v7);
}
return func4(a1, a2);
}

original_code:
static void write_task(json_t* json_obj, TaskT* task) {
    json_object_set_new(json_obj, kTaskJsonTextKey, json_string(task->text));
    json_object_set_new(
        json_obj,
        kTaskJsonIsCompleteKey,
        (task->is_complete == 1 ? json_true() : json_false())
    );
    if (task->notes != ((void *)0) && task->notes->size > 0) {
        json_t *notes_json_arr;
        int note_idx;
        notes_json_arr = json_array();
        for (note_idx = 0; note_idx < task->notes->size; note_idx++) {
            char *note;
            note = list_obj_at_idx(task->notes, note_idx);
            json_array_append_new(notes_json_arr, json_string(note));
        }
        json_object_set(json_obj, kTaskJsonNotesKey, notes_json_arr);
        json_decref(notes_json_arr);
    }
    write_children_to_task(json_obj, task);
}

canonical_original_code:
static void write_task(struct json_t *json_obj, struct TaskT *task) {
    json_object_set_new(json_obj, kTaskJsonTextKey, json_string(task->text));
    json_object_set_new(
        json_obj,
        kTaskJsonIsCompleteKey,
        (task->is_complete == 1 ? json_true() : json_false())
    );
    if (task->notes != ((void *)0) && task->notes->size > 0) {
        struct json_t *notes_json_arr;
        int note_idx;
        notes_json_arr = json_array();
        for (note_idx = 0; note_idx < task->notes->size; note_idx++) {
            char *note;
            note = list_obj_at_idx(task->notes, note_idx);
            json_array_append_new(notes_json_arr, json_string(note));
        }
        json_object_set(json_obj, kTaskJsonNotesKey, notes_json_arr);
        json_decref(notes_json_arr);
    }
    write_children_to_task(json_obj, task);
}

variable_types:
note
char *

user_defined_types: struct ListT { void **values; void **last_value; int size; int capacity; }


decompiled_code:
void __fastcall print_notes(__int64 a1)
{
int v1; // er12
char *v2; // rbx
char *v3; // rsi

if ( a1 && *(int *)(a1 + 16) > 0 )
{
puts("Notes:");
v1 = 0;
while ( 1 )
{
v2 = (char *)list_iterate(a1);
if ( !v2 )
break;
printf("%d)\n", (unsigned int)++v1);
while ( 1 )
{
v3 = strtok(v2, "\n");
if ( !v3 )
break;
printf(" %s\n", v3);
v2 = 0LL;
}
}
}
}

canonical_decompiled_code:
void __fastcall func6(__int64 a1)
{
int v1; // er12
char *v2; // rbx
char *v3; // rsi

if ( a1 && *(int *)(a1 + 16) > 0 )
{
puts("Notes:");
v1 = 0;
while ( 1 )
{
v2 = (char *)list_iterate(a1);
if ( !v2 )
break;
printf("%d)\n", (unsigned int)++v1);
while ( 1 )
{
v3 = strtok(v2, "\n");
if ( !v3 )
break;
printf(" %s\n", v3);
v2 = 0LL;
}
}
}
}

original_code:
void print_notes(ListT* notes) {
    if (notes != ((void *)0) && notes->size > 0) {
        char* note;
        int note_idx = 0;
        printf("Notes:\n");
        while ((note = list_iterate(notes)) != ((void *)0)) {
            char* token;
            printf("%d)\n", note_idx++ + 1);
            while ((token = strtok(note, "\n")) != ((void *)0)) {
                printf("  %s\n", token);
                note = ((void *)0);
            }
        }
    }
}

canonical_original_code:
void print_notes(struct ListT *notes) {
    if (notes != ((void *)0) && notes->size > 0) {
        char *note;
        int note_idx = 0;
        printf("Notes:\n");
        while ((note = list_iterate(notes)) != ((void *)0)) {
            char *token;
            printf("%d)\n", note_idx++ + 1);
            while ((token = strtok(note, "\n")) != ((void *)0)) {
                printf("  %s\n", token);
                note = ((void *)0);
            }
        }
    }
}

variable_types: struct ListT { void **values; void **last_value; int size; int capacity; } *

variable_types:
token
char *


decompiled_code:
void __fastcall task_destroy(void *ptr)
{
__int64 v2; // rdi
unsigned int i; // ebx
void *v4; // rax

if ( !ptr )
_assert_fail("self != NULL", "src/task.c", 0x2Cu, "task_destroy");
v2 = *((_QWORD *)ptr + 1);
for ( i = 0; *(_DWORD *)(v2 + 16) > (signed int)i; v2 = *((_QWORD *)ptr + 1) )
{
v4 = (void *)list_obj_at_idx(v2, i);
free(v4);
++i;
}
((void (*)(void))list_destroy)();
list_destroy(*((_QWORD *)ptr + 2));
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
__int64 v2; // rdi
unsigned int i; // ebx
void *v4; // rax

if ( !ptr )
_assert_fail("self != NULL", "src/task.c", 0x2Cu, "task_destroy");
v2 = *((_QWORD *)ptr + 1);
for ( i = 0; *(_DWORD *)(v2 + 16) > (signed int)i; v2 = *((_QWORD *)ptr + 1) )
{
v4 = (void *)list_obj_at_idx(v2, i);
free(v4);
++i;
}
((void (*)(void))list_destroy)();
list_destroy(*((_QWORD *)ptr + 2));
free(*(void **)ptr);
free(ptr);
}

original_code:
void task_destroy(TaskT* self) {
    ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "src/task.c", 44, __extension__ __PRETTY_FUNCTION__); }));
    int note_idx;
    int child_idx;
    for (note_idx = 0; note_idx < self->notes->size; note_idx++) {
        free(list_obj_at_idx(self->notes, note_idx));
    }
    list_destroy(self->notes);
    list_destroy(self->children);
    free(self->text);
    free(self);
}

canonical_original_code:
void task_destroy(struct TaskT *self) {
    ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "src/task.c", 44, __extension__ __PRETTY_FUNCTION__); }));
    int note_idx;
    int child_idx;
    for (note_idx = 0; note_idx < self->notes->size; note_idx++) {
        free(list_obj_at_idx(self->notes, note_idx));
    }
    list_destroy(self->notes);
    list_destroy(self->children);
    free(self->text);
    free(self);
}


decompiled_code:
__int64 __fastcall task_add_note(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("self != NULL", "src/task.c", 0x3Du, "task_add_note");
if ( !a2 )
_assert_fail("note != NULL", "src/task.c", 0x3Eu, "task_add_note");
return list_append(*(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("self != NULL", "src/task.c", 0x3Du, "task_add_note");
if ( !a2 )
_assert_fail("note != NULL", "src/task.c", 0x3Eu, "task_add_note");
return list_append(*(_QWORD *)(a1 + 8));
}

original_code:
void task_add_note(TaskT* self, char* note) {
    ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "src/task.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((note != ((void *)0)) ? 1 : 0), __extension__ ({ if (note != ((void *)0)) ; else __assert_fail ("note != NULL", "src/task.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    list_append(self->notes, note);
}

canonical_original_code:
void task_add_note(struct TaskT *self, char *note) {
    ((void) sizeof ((self != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0)) ; else __assert_fail ("self != NULL", "src/task.c", 61, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((note != ((void *)0)) ? 1 : 0), __extension__ ({ if (note != ((void *)0)) ; else __assert_fail ("note != NULL", "src/task.c", 62, __extension__ __PRETTY_FUNCTION__); }));
    list_append(self->notes, note);
}


decompiled_code:
void __fastcall task_complete(__int64 a1)
{
*(_DWORD *)(a1 + 24) = 1;
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
*(_DWORD *)(a1 + 24) = 1;
}

original_code:
void task_complete(TaskT* self) {
    self->is_complete = 1;
}

canonical_original_code:
void task_complete(struct TaskT *self) {
    self->is_complete = 1;
}


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

if ( !a1 || !a2 )
_assert_fail("self != NULL && child != NULL", "src/task.c", 0x48u, "task_add_child");
result = list_append(*(_QWORD *)(a1 + 16));
*(_QWORD *)(a2 + 32) = a1;
return result;
}

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

if ( !a1 || !a2 )
_assert_fail("self != NULL && child != NULL", "src/task.c", 0x48u, "task_add_child");
result = list_append(*(_QWORD *)(a1 + 16));
*(_QWORD *)(a2 + 32) = a1;
return result;
}

original_code:
void task_add_child(TaskT* self, TaskT* child) {
    ((void) sizeof ((self != ((void *)0) && child != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0) && child != ((void *)0)) ; else __assert_fail ("self != NULL && child != NULL", "src/task.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    list_append(self->children, child);
    child->parent = self;
}

canonical_original_code:
void task_add_child(struct TaskT *self, struct TaskT *child) {
    ((void) sizeof ((self != ((void *)0) && child != ((void *)0)) ? 1 : 0), __extension__ ({ if (self != ((void *)0) && child != ((void *)0)) ; else __assert_fail ("self != NULL && child != NULL", "src/task.c", 72, __extension__ __PRETTY_FUNCTION__); }));
    list_append(self->children, child);
    child->parent = self;
}

variable_types:
child
struct TaskT *


decompiled_code:
void __fastcall task_print(__int64 a1)
{
const char *v1; // rdx

v1 = "COMPLTED";
if ( !*(_DWORD *)(a1 + 24) )
v1 = "NOT COMPLETED";
printf("%s (%s)\n", *(const char **)a1, v1);
print_notes(*(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
void __fastcall func12(__int64 a1)
{
const char *v1; // rdx

v1 = "COMPLTED";
if ( !*(_DWORD *)(a1 + 24) )
v1 = "NOT COMPLETED";
printf("%s (%s)\n", *(const char **)a1, v1);
func6(*(_QWORD *)(a1 + 8));
}

original_code:
void task_print(TaskT* task) {
    printf("%s (%s)\n", task->text, (task->is_complete ? "COMPLTED" : "NOT COMPLETED"));
    print_notes(task->notes);
}

canonical_original_code:
void task_print(struct TaskT *task) {
    printf("%s (%s)\n", task->text, (task->is_complete ? "COMPLTED" : "NOT COMPLETED"));
    print_notes(task->notes);
}


decompiled_code:
void __fastcall get_user_input(_QWORD *a1)
{
_BYTE *v1; // rbp
__int64 v2; // rbx
size_t v3; // r12
char v4; // al

v1 = calloc(0x64uLL, 1uLL);
*a1 = v1;
v2 = 0LL;
v3 = 100LL;
while ( 1 )
{
v4 = getchar();
if ( v4 == 10 || v4 == -1 )
break;
v1[v2++] = v4;
if ( v3 == v2 )
{
v3 += 100LL;
v1 = realloc(v1, v3);
}
}
*a1 = trim(v1);
free(v1);
}

original_code:
void get_user_input(char** command) {
    char* _command;
    char c;
    int user_input_idx;
    size_t current_command_size;
    *command = calloc(kUserInputInitSize, sizeof(char));
    _command = *command;
    c = (-1);
    user_input_idx = 0;
    current_command_size = kUserInputInitSize;
    while ((c = getchar()) != (-1) && c != '\n') {
        _command[user_input_idx++] = c;
        if (user_input_idx == current_command_size) {
            current_command_size += kUserInputInitSize;
            _command = realloc(_command, sizeof(char) * current_command_size);
        }
    }
    *command = trim(_command);
    free(_command);
}

canonical_original_code:
void get_user_input(char **command) {
    char *_command;
    char c;
    int user_input_idx;
    unsigned long current_command_size;
    *command = calloc(kUserInputInitSize, sizeof(char));
    _command = *command;
    c = (-1);
    user_input_idx = 0;
    current_command_size = kUserInputInitSize;
    while ((c = getchar()) != (-1) && c != '\n') {
        _command[user_input_idx++] = c;
        if (user_input_idx == current_command_size) {
            current_command_size += kUserInputInitSize;
            _command = realloc(_command, sizeof(char) * current_command_size);
        }
    }
    *command = trim(_command);
    free(_command);
}

variable_types:
command
char **

variable_types: c char


decompiled_code:
void __fastcall get_user_input_msg(_QWORD *a1, const char *a2)
{
printf("%s", a2);
get_user_input(a1);
}

canonical_decompiled_code:
void __fastcall func1(_QWORD *a1, const char *a2)
{
printf("%s", a2);
func0(a1);
}

original_code:
void get_user_input_msg(char** command, const char* message) {
    printf("%s", message);
    get_user_input(command);
}

canonical_original_code:
void get_user_input_msg(char **command, char *message) {
    printf("%s", message);
    get_user_input(command);
}

variable_types:
message
char *


decompiled_code:
__int64 __fastcall get_numeric_input(const char *a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
if ( a1 )
printf("%s", a1);
do
get_user_input(&v2);
while ( !v2 );
return strtodigit();
}

canonical_decompiled_code:
__int64 __fastcall func2(const char *a1)
{
__int64 v2; // [rsp+8h] [rbp-10h] BYREF

v2 = 0LL;
if ( a1 )
printf("%s", a1);
do
func0(&v2);
while ( !v2 );
return strtodigit();
}

original_code:
int get_numeric_input(char* msg) {
    char* user_input_str = ((void *)0);
    int numeric;
    if (msg != ((void *)0)) {
        printf("%s", msg);
    }
    while (user_input_str == ((void *)0)) {
        get_user_input(&user_input_str);
    }
    numeric = strtodigit(user_input_str);
    return numeric;
}

canonical_original_code:
int get_numeric_input(char *msg) {
    char *user_input_str = ((void *)0);
    int numeric;
    if (msg != ((void *)0)) {
        printf("%s", msg);
    }
    while (user_input_str == ((void *)0)) {
        get_user_input(&user_input_str);
    }
    numeric = strtodigit(user_input_str);
    return numeric;
}

variable_types:
msg
char *

variable_types: numeric int


decompiled_code:
void __fastcall get_multiline_input(_QWORD *a1, const char *a2)
{
char *v2; // r12
__int64 v3; // rbp
size_t v4; // r13
char v5; // bl

printf(a2, 0LL);
v2 = (char *)calloc(0x64uLL, 1uLL);
v3 = 0LL;
v4 = 100LL;
while ( 1 )
{
v5 = getchar();
if ( v5 == -1 || strstr(v2, "\n\n") )
break;
v2[v3++] = v5;
if ( v4 == v3 )
{
v4 += 100LL;
v2 = (char *)realloc(v2, v4);
}
}
*a1 = trim(v2);
free(v2);
}

canonical_decompiled_code:
void __fastcall func3(_QWORD *a1, const char *a2)
{
char *v2; // r12
__int64 v3; // rbp
size_t v4; // r13
char v5; // bl

printf(a2, 0LL);
v2 = (char *)calloc(0x64uLL, 1uLL);
v3 = 0LL;
v4 = 100LL;
while ( 1 )
{
v5 = getchar();
if ( v5 == -1 || strstr(v2, "\n\n") )
break;
v2[v3++] = v5;
if ( v4 == v3 )
{
v4 += 100LL;
v2 = (char *)realloc(v2, v4);
}
}
*a1 = trim(v2);
free(v2);
}

original_code:
void get_multiline_input(char** input, const char* msg) {
    char* _input;
    char c;
    int input_idx;
    size_t current_size;
    printf(msg, ((void *)0));
    _input = calloc(kUserInputInitSize, 1);
    c = (-1);
    input_idx = 0;
    current_size = kUserInputInitSize;
    while ((c = getchar()) != (-1) && strstr(_input, "\n\n") == ((void *)0)) {
        _input[input_idx++] = c;
        if (input_idx == current_size) {
            current_size += kUserInputInitSize;
            _input = realloc(_input, current_size);
        }
    }
    *input = trim(_input);
    free(_input);
}

canonical_original_code:
void get_multiline_input(char **input, char *msg) {
    char *_input;
    char c;
    int input_idx;
    unsigned long current_size;
    printf(msg, ((void *)0));
    _input = calloc(kUserInputInitSize, 1);
    c = (-1);
    input_idx = 0;
    current_size = kUserInputInitSize;
    while ((c = getchar()) != (-1) && strstr(_input, "\n\n") == ((void *)0)) {
        _input[input_idx++] = c;
        if (input_idx == current_size) {
            current_size += kUserInputInitSize;
            _input = realloc(_input, current_size);
        }
    }
    *input = trim(_input);
    free(_input);
}

variable_types:
input
char **


decompiled_code:
__int64 get_command_dict()
{
if ( !command_dict_1 )
{
command_dict_1 = Dict();
dict_add(command_dict_1, "n", &execute_new);
dict_add(command_dict_1, "new", &execute_new);
dict_add(command_dict_1, "f", &execute_finish);
dict_add(command_dict_1, "finish", &execute_finish);
dict_add(command_dict_1, "s", &execute_show);
dict_add(command_dict_1, "show", &execute_show);
dict_add(command_dict_1, "a", &execute_add_note);
dict_add(command_dict_1, "add", &execute_add_note);
dict_add(command_dict_1, "l", &execute_load);
dict_add(command_dict_1, "load", &execute_load);
dict_add(command_dict_1, "w", &execute_save);
dict_add(command_dict_1, "write", &execute_save);
dict_add(command_dict_1, "print", &execute_print);
dict_add(command_dict_1, "p", &execute_print);
dict_add(command_dict_1, "c", &execute_change);
dict_add(command_dict_1, "change", &execute_change);
}
return command_dict_1;
}

canonical_decompiled_code:
__int64 func0()
{
if ( !command_dict_1 )
{
command_dict_1 = Dict();
dict_add(command_dict_1, "n", &execute_new);
dict_add(command_dict_1, "new", &execute_new);
dict_add(command_dict_1, "f", &execute_finish);
dict_add(command_dict_1, "finish", &execute_finish);
dict_add(command_dict_1, "s", &execute_show);
dict_add(command_dict_1, "show", &execute_show);
dict_add(command_dict_1, "a", &execute_add_note);
dict_add(command_dict_1, "add", &execute_add_note);
dict_add(command_dict_1, "l", &execute_load);
dict_add(command_dict_1, "load", &execute_load);
dict_add(command_dict_1, "w", &execute_save);
dict_add(command_dict_1, "write", &execute_save);
dict_add(command_dict_1, "print", &execute_print);
dict_add(command_dict_1, "p", &execute_print);
dict_add(command_dict_1, "c", &execute_change);
dict_add(command_dict_1, "change", &execute_change);
}
return command_dict_1;
}

original_code:
DictionaryT* get_command_dict() {
    static DictionaryT* command_dict = ((void *)0);
    if (command_dict == ((void *)0)) {
        command_dict = Dict();
        dict_add(command_dict, "n", &execute_new);
        dict_add(command_dict, "new", &execute_new);
        dict_add(command_dict, "f", &execute_finish);
        dict_add(command_dict, "finish", &execute_finish);
        dict_add(command_dict, "s", &execute_show);
        dict_add(command_dict, "show", &execute_show);
        dict_add(command_dict, "a", &execute_add_note);
        dict_add(command_dict, "add", &execute_add_note);
        dict_add(command_dict, "l", &execute_load);
        dict_add(command_dict, "load", &execute_load);
        dict_add(command_dict, "w", &execute_save);
        dict_add(command_dict, "write", &execute_save);
        dict_add(command_dict, "print", &execute_print);
        dict_add(command_dict, "p", &execute_print);
        dict_add(command_dict, "c", &execute_change);
        dict_add(command_dict, "change", &execute_change);
    }
    return command_dict;
}

canonical_original_code:
struct DictionaryT *get_command_dict() {
    static struct DictionaryT *command_dict = ((void *)0);
    if (command_dict == ((void *)0)) {
        command_dict = Dict();
        dict_add(command_dict, "n", &execute_new);
        dict_add(command_dict, "new", &execute_new);
        dict_add(command_dict, "f", &execute_finish);
        dict_add(command_dict, "finish", &execute_finish);
        dict_add(command_dict, "s", &execute_show);
        dict_add(command_dict, "show", &execute_show);
        dict_add(command_dict, "a", &execute_add_note);
        dict_add(command_dict, "add", &execute_add_note);
        dict_add(command_dict, "l", &execute_load);
        dict_add(command_dict, "load", &execute_load);
        dict_add(command_dict, "w", &execute_save);
        dict_add(command_dict, "write", &execute_save);
        dict_add(command_dict, "print", &execute_print);
        dict_add(command_dict, "p", &execute_print);
        dict_add(command_dict, "c", &execute_change);
        dict_add(command_dict, "change", &execute_change);
    }
    return command_dict;
}

variable_types: struct DictionaryT { struct DictionaryNodeT { char *key; void *value; unsigned int hash; struct DictionaryNodeT *next; } **list; int capacity; int size; } *

user_defined_types: struct DictionaryT { struct DictionaryNodeT **list; int capacity; int size; }


decompiled_code:
int __fastcall execute_command(char *src, __int64 a2, __int64 a3)
{
signed __int64 v4; // rax
int v5; // ebp
__int64 v6; // rax
__int64 (__fastcall *v7)(char *, __int64, __int64); // rbp
char *v9; // r14
__int64 v10; // rax

if ( !src || !*src )
_assert_fail("command != NULL && strlen(command) != 0", "src/main.c", 0x5Au, "execute_command");
v4 = strchr(src, 32) - src;
v5 = v4;
if ( (int)v4 > 0 )
{
v9 = (char *)malloc((int)v4 + 1);
strncpy(v9, src, v5);
v10 = get_command_dict();
v7 = (__int64 (__fastcall *)(char *, __int64, __int64))dict_obj_at(v10, v9);
if ( v7 )
{
free(v9);
return v7(src, a2, a3);
}
}
else
{
v6 = get_command_dict();
v7 = (__int64 (__fastcall *)(char *, __int64, __int64))dict_obj_at(v6, src);
if ( v7 )
return v7(src, a2, a3);
}
return puts("Invalid command");
}

canonical_decompiled_code:
int __fastcall func1(char *src, __int64 a2, __int64 a3)
{
signed __int64 v4; // rax
int v5; // ebp
__int64 v6; // rax
__int64 (__fastcall *v7)(char *, __int64, __int64); // rbp
char *v9; // r14
__int64 v10; // rax

if ( !src || !*src )
_assert_fail("command != NULL && strlen(command) != 0", "src/main.c", 0x5Au, "execute_command");
v4 = strchr(src, 32) - src;
v5 = v4;
if ( (int)v4 > 0 )
{
v9 = (char *)malloc((int)v4 + 1);
strncpy(v9, src, v5);
v10 = func0();
v7 = (__int64 (__fastcall *)(char *, __int64, __int64))dict_obj_at(v10, v9);
if ( v7 )
{
free(v9);
return v7(src, a2, a3);
}
}
else
{
v6 = func0();
v7 = (__int64 (__fastcall *)(char *, __int64, __int64))dict_obj_at(v6, src);
if ( v7 )
return v7(src, a2, a3);
}
return puts("Invalid command");
}

original_code:
void execute_command(char* command, ListT* tasks, TaskT** current) {
    ((void) sizeof ((command != ((void *)0) && strlen(command) != 0) ? 1 : 0), __extension__ ({ if (command != ((void *)0) && strlen(command) != 0) ; else __assert_fail ("command != NULL && strlen(command) != 0", "src/main.c", 90, __extension__ __PRETTY_FUNCTION__); }));
    char* command_token = command;
    void (*command_executor)(char*, ListT*, TaskT**) = ((void *)0);
    int space_idx = -1;
    space_idx = strstr(command, " ") - command;
    if (space_idx > 0) {
        command_token = malloc(sizeof(char) * (space_idx + 1));
        strncpy(command_token, command, space_idx);
    }
    command_executor = dict_obj_at(get_command_dict(), command_token);
    if (command_executor == ((void *)0)) {
        puts("Invalid command");
        return;
    }
    if (space_idx > 0) {
        free(command_token);
    }
    command_executor(command, tasks, current);
}

canonical_original_code:
void execute_command(char *command, struct ListT *tasks, struct TaskT **current) {
    ((void) sizeof ((command != ((void *)0) && strlen(command) != 0) ? 1 : 0), __extension__ ({ if (command != ((void *)0) && strlen(command) != 0) ; else __assert_fail ("command != NULL && strlen(command) != 0", "src/main.c", 90, __extension__ __PRETTY_FUNCTION__); }));
    char *command_token = command;
    void (*command_executor)(char *, struct ListT *, struct TaskT **) = ((void *)0);
    int space_idx = -1;
    space_idx = strstr(command, " ") - command;
    if (space_idx > 0) {
        command_token = malloc(sizeof(char) * (space_idx + 1));
        strncpy(command_token, command, space_idx);
    }
    command_executor = dict_obj_at(get_command_dict(), command_token);
    if (command_executor == ((void *)0)) {
        puts("Invalid command");
        return;
    }
    if (space_idx > 0) {
        free(command_token);
    }
    command_executor(command, tasks, current);
}

variable_types:
command
char *

variable_types: void (*)(char *, struct ListT { void **values; void **last_value; int size; int capacity; } *, struct TaskT { char *text; struct ListT *notes; struct ListT *children; int is_complete; struct TaskT *parent; } **)


decompiled_code:
_BOOL8 __fastcall do_quit(const char *a1)
{
char *v1; // rax
_BOOL4 v2; // ecx

v1 = strstr(a1, "quit");
v2 = 1;
if ( strcmp(a1, "q") )
v2 = v1 != 0LL && a1 == v1;
return v2;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(const char *a1)
{
char *v1; // rax
_BOOL4 v2; // ecx

v1 = strstr(a1, "quit");
v2 = 1;
if ( strcmp(a1, "q") )
v2 = v1 != 0LL && a1 == v1;
return v2;
}

original_code:
int do_quit(char* command) {
    char* substr = strstr(command, kQuitString);
    return strcmp(command, kQuitStringAbbr) == 0
        || (substr != ((void *)0) && ((substr - command) == 0));
}

canonical_original_code:
int do_quit(char *command) {
    char *substr = strstr(command, kQuitString);
    return strcmp(command, kQuitStringAbbr) == 0
        || (substr != ((void *)0) && ((substr - command) == 0));
}

variable_types:
substr
char *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
char *v4; // rbx
const char *v6; // rbx
__int64 v7; // [rsp+0h] [rbp-28h] BYREF
void *ptr[4]; // [rsp+8h] [rbp-20h] BYREF

puts(
"\n"
"\n"
"\n"
"Welcome to task!\n"
"Here are your commands:\n"
"n(ew) - Begin a new task\n"
"a(dd) - add a note to the current task\n"
"f(inish) - finish the current task\n"
"s(how) - show current task\n"
"p(rint) - print tasks\n"
"c(hange) - change tasks\n"
"l(oad) - load a task file\n"
"w(rite) - save a task file\n"
"q(uit) - quit\n");
v3 = List(10LL, 0LL);
ptr[0] = 0LL;
v7 = 0LL;
get_user_input_msg(ptr, "\nWhat would you like to do? ");
while ( 1 )
{
v4 = (char *)ptr[0];
if ( ptr[0] )
{
if ( *(_BYTE *)ptr[0] )
break;
}
LABEL_2:
get_user_input_msg(ptr, "\nWhat would you like to do? ");
}
if ( !do_quit((const char *)ptr[0]) )
{
execute_command(v4, v3, (__int64)&v7);
goto LABEL_2;
}
if ( *(int *)(v3 + 16) > 0 )
{
get_user_input_msg(ptr, "\nSave your tasks? (y)/n: ");
v6 = (const char *)ptr[0];
if ( !*(_BYTE *)ptr[0] || strcmp((const char *)ptr[0], "n") && strcmp(v6, "N") )
execute_save(v6, v3, &v7);
}
free(ptr[0]);
return 0;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v3; // rbp
char *v4; // rbx
const char *v6; // rbx
__int64 v7; // [rsp+0h] [rbp-28h] BYREF
void *ptr[4]; // [rsp+8h] [rbp-20h] BYREF

puts(
"\n"
"\n"
"\n"
"Welcome to task!\n"
"Here are your commands:\n"
"n(ew) - Begin a new task\n"
"a(dd) - add a note to the current task\n"
"f(inish) - finish the current task\n"
"s(how) - show current task\n"
"p(rint) - print tasks\n"
"c(hange) - change tasks\n"
"l(oad) - load a task file\n"
"w(rite) - save a task file\n"
"q(uit) - quit\n");
v3 = List(10LL, 0LL);
ptr[0] = 0LL;
v7 = 0LL;
get_user_input_msg(ptr, "\nWhat would you like to do? ");
while ( 1 )
{
v4 = (char *)ptr[0];
if ( ptr[0] )
{
if ( *(_BYTE *)ptr[0] )
break;
}
LABEL_2:
get_user_input_msg(ptr, "\nWhat would you like to do? ");
}
if ( !func2((const char *)ptr[0]) )
{
func1(v4, v3, (__int64)&v7);
goto LABEL_2;
}
if ( *(int *)(v3 + 16) > 0 )
{
get_user_input_msg(ptr, "\nSave your tasks? (y)/n: ");
v6 = (const char *)ptr[0];
if ( !*(_BYTE *)ptr[0] || strcmp((const char *)ptr[0], "n") && strcmp(v6, "N") )
execute_save(v6, v3, &v7);
}
free(ptr[0]);
return 0;
}

original_code:
int main() {
    puts(kWelcomeMessage);
    char * command;
    ListT* tasks;
    TaskT* current;
    tasks = List(10, ((void *)0));
    command = ((void *)0);
    current = ((void *)0);
    get_user_input_msg(&command, "\nWhat would you like to do? ");
    while (command == ((void *)0) || strlen(command) == 0 || !do_quit(command)) {
        if (command != ((void *)0) && strlen(command) > 0) {
            execute_command(command, tasks, &current);
        }
        get_user_input_msg(&command, "\nWhat would you like to do? ");
    }
    if (tasks->size > 0) {
        get_user_input_msg(&command, "\nSave your tasks? (y)/n: ");
        if (strlen(command) == 0 ||
            (strcmp(command, "n") != 0 && strcmp(command, "N") != 0)) {
            execute_save(command, tasks, &current);
        }
    }
    free(command);
}

canonical_original_code:
int main() {
    puts(kWelcomeMessage);
    char *command;
    struct ListT *tasks;
    struct TaskT *current;
    tasks = List(10, ((void *)0));
    command = ((void *)0);
    current = ((void *)0);
    get_user_input_msg(&command, "\nWhat would you like to do? ");
    while (command == ((void *)0) || strlen(command) == 0 || !do_quit(command)) {
        if (command != ((void *)0) && strlen(command) > 0) {
            execute_command(command, tasks, &current);
        }
        get_user_input_msg(&command, "\nWhat would you like to do? ");
    }
    if (tasks->size > 0) {
        get_user_input_msg(&command, "\nSave your tasks? (y)/n: ");
        if (strlen(command) == 0 ||
            (strcmp(command, "n") != 0 && strcmp(command, "N") != 0)) {
            execute_save(command, tasks, &current);
        }
    }
    free(command);
}


decompiled_code:
char *__fastcall get_text_from_command(char *s)
{
unsigned int v1; // er13
size_t v2; // rbx
char *v3; // rax

v1 = (unsigned int)strchr(s, 32) - (_DWORD)s;
v2 = (int)(strlen(s) - v1);
v3 = (char *)malloc(v2);
return strncpy(v3, &s[v1 + 1], v2);
}

canonical_decompiled_code:
char *__fastcall func0(char *s)
{
unsigned int v1; // er13
size_t v2; // rbx
char *v3; // rax

v1 = (unsigned int)strchr(s, 32) - (_DWORD)s;
v2 = (int)(strlen(s) - v1);
v3 = (char *)malloc(v2);
return strncpy(v3, &s[v1 + 1], v2);
}

original_code:
static char* get_text_from_command(char* command) {
    int first_space_idx, command_strlen;
    char* text;;
    first_space_idx = strstr(command, " ") - command;
    command_strlen = strlen(command);
    text = malloc(sizeof(char) * (command_strlen - first_space_idx));
    strncpy(text, (command + first_space_idx + 1), (command_strlen - first_space_idx));
    return text;
}

canonical_original_code:
static char *get_text_from_command(char *command) {
    int first_space_idx; int command_strlen;
    char *text;;
    first_space_idx = strstr(command, " ") - command;
    command_strlen = strlen(command);
    text = malloc(sizeof(char) * (command_strlen - first_space_idx));
    strncpy(text, (command + first_space_idx + 1), (command_strlen - first_space_idx));
    return text;
}

variable_types:
text
char *

return_type: char *


decompiled_code:
_BOOL8 __fastcall is_command_only(__int64 a1)
{
return (unsigned int)stroccur(a1, &unk_85C) == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func1(__int64 a1)
{
return (unsigned int)stroccur(a1, &unk_85C) == 0;
}

original_code:
static int is_command_only(char* command) {
    return stroccur(command, " ") == 0;
}

canonical_original_code:
static int is_command_only(char *command) {
    return stroccur(command, " ") == 0;
}


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

v1 = strcmp(".", a1) == 0;
result = !v1;
if ( !v1 )
result = strcmp("..", a1) != 0;
return result;
}

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

v1 = strcmp(".", a1) == 0;
result = !v1;
if ( !v1 )
result = strcmp("..", a1) != 0;
return result;
}

original_code:
int is_loadable(char* filename) {
    return strcmp(".", filename) != 0 && strcmp("..", filename) != 0;
}

canonical_original_code:
int is_loadable(char *filename) {
    return strcmp(".", filename) != 0 && strcmp("..", filename) != 0;
}

variable_types:
filename
char *


decompiled_code:
char *make_file_name()
{
struct tm *v0; // rbp
char *v1; // rbx
size_t v2; // rax
char *v3; // rbp
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
v1 = (char *)malloc(0x14uLL);
strftime(v1, 0x14uLL, "%Y_%m_%d", v0);
v2 = strlen(v1);
v3 = (char *)malloc(v2 + 21);
sprintf(v3, "tasks/task-%s.js", v1);
free(v1);
return v3;
}

canonical_decompiled_code:
char *func4()
{
struct tm *v0; // rbp
char *v1; // rbx
size_t v2; // rax
char *v3; // rbp
time_t timer; // [rsp+8h] [rbp-20h] BYREF

timer = time(0LL);
v0 = localtime(&timer);
v1 = (char *)malloc(0x14uLL);
strftime(v1, 0x14uLL, "%Y_%m_%d", v0);
v2 = strlen(v1);
v3 = (char *)malloc(v2 + 21);
sprintf(v3, "tasks/task-%s.js", v1);
free(v1);
return v3;
}

original_code:
static char* make_file_name() {
    time_t current_time;
    struct tm* local_time;
    char* time_str;
    char* filename;
    current_time = time(((void *)0));
    local_time = localtime(&current_time);
    time_str = malloc(kFileTimeFormatSize);
    strftime(time_str, kFileTimeFormatSize, kFileTimeFormat, local_time);
    filename = malloc(kFileTimeFormatSize + strlen(time_str) + 1);
    sprintf(filename, kFileNameFormat, time_str);
    free(time_str);
    return filename;
}

canonical_original_code:
static char *make_file_name() {
    long current_time;
    struct tm *local_time;
    char *time_str;
    char *filename;
    current_time = time(((void *)0));
    local_time = localtime(&current_time);
    time_str = malloc(kFileTimeFormatSize);
    strftime(time_str, kFileTimeFormatSize, kFileTimeFormat, local_time);
    filename = malloc(kFileTimeFormatSize + strlen(time_str) + 1);
    sprintf(filename, kFileNameFormat, time_str);
    free(time_str);
    return filename;
}

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


decompiled_code:
__int64 __fastcall execute_new(char *s, __int64 a2, __int64 *a3)
{
__int64 v4; // rax
unsigned int v6; // er14
size_t v7; // r13
char *v8; // [rsp+8h] [rbp-30h] BYREF

if ( !*s )
_assert_fail("strlen(command) > 0", "src/execute.c", 0xAu, "execute_new");
if ( !a2 )
_assert_fail("tasks != NULL", "src/execute.c", 0xBu, "execute_new");
if ( is_command_only((__int64)s) )
{
get_user_input_msg(&v8, "What do you need to get done? ");
}
else
{
v6 = (unsigned int)strchr(s, 32) - (_DWORD)s;
v7 = (int)(strlen(s) - v6);
v8 = (char *)malloc(v7);
strncpy(v8, &s[v6 + 1], v7);
}
v4 = Task(v8);
*a3 = v4;
return list_append(a2, v4);
}

canonical_decompiled_code:
__int64 __fastcall func5(char *s, __int64 a2, __int64 *a3)
{
__int64 v4; // rax
unsigned int v6; // er14
size_t v7; // r13
char *v8; // [rsp+8h] [rbp-30h] BYREF

if ( !*s )
_assert_fail("strlen(command) > 0", "src/execute.c", 0xAu, "execute_new");
if ( !a2 )
_assert_fail("tasks != NULL", "src/execute.c", 0xBu, "execute_new");
if ( func1((__int64)s) )
{
get_user_input_msg(&v8, "What do you need to get done? ");
}
else
{
v6 = (unsigned int)strchr(s, 32) - (_DWORD)s;
v7 = (int)(strlen(s) - v6);
v8 = (char *)malloc(v7);
strncpy(v8, &s[v6 + 1], v7);
}
v4 = Task(v8);
*a3 = v4;
return list_append(a2, v4);
}

original_code:
void execute_new(char* command, ListT* tasks, TaskT** current_task) {
    ((void) sizeof ((strlen(command) > 0) ? 1 : 0), __extension__ ({ if (strlen(command) > 0) ; else __assert_fail ("strlen(command) > 0", "src/execute.c", 10, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((tasks != ((void *)0)) ? 1 : 0), __extension__ ({ if (tasks != ((void *)0)) ; else __assert_fail ("tasks != NULL", "src/execute.c", 11, __extension__ __PRETTY_FUNCTION__); }));
    char* task_str;
    TaskT* task;
    if (is_command_only(command)) {
        get_user_input_msg(&task_str, "What do you need to get done? ");
    } else {
        int first_space_idx, command_strlen;
        first_space_idx = strstr(command, " ") - command;
        command_strlen = strlen(command);
        task_str = malloc(sizeof(char) * (command_strlen - first_space_idx));
        strncpy(task_str, (command + first_space_idx + 1), (command_strlen - first_space_idx));
    }
    task = Task(task_str);
    *current_task = task;
    list_append(tasks, task);
}

canonical_original_code:
void execute_new(char *command, struct ListT *tasks, struct TaskT **current_task) {
    ((void) sizeof ((strlen(command) > 0) ? 1 : 0), __extension__ ({ if (strlen(command) > 0) ; else __assert_fail ("strlen(command) > 0", "src/execute.c", 10, __extension__ __PRETTY_FUNCTION__); }));
    ((void) sizeof ((tasks != ((void *)0)) ? 1 : 0), __extension__ ({ if (tasks != ((void *)0)) ; else __assert_fail ("tasks != NULL", "src/execute.c", 11, __extension__ __PRETTY_FUNCTION__); }));
    char *task_str;
    struct TaskT *task;
    if (is_command_only(command)) {
        get_user_input_msg(&task_str, "What do you need to get done? ");
    } else {
        int first_space_idx; int command_strlen;
        first_space_idx = strstr(command, " ") - command;
        command_strlen = strlen(command);
        task_str = malloc(sizeof(char) * (command_strlen - first_space_idx));
        strncpy(task_str, (command + first_space_idx + 1), (command_strlen - first_space_idx));
    }
    task = Task(task_str);
    *current_task = task;
    list_append(tasks, task);
}

variable_types: struct TaskT { char *text; struct ListT *notes; struct ListT *children; int is_complete; struct TaskT *parent; } **

variable_types: struct TaskT { char *text; struct ListT { void **values; void **last_value; int size; int capacity; } *notes; struct ListT *children; int is_complete; struct TaskT *parent; } *


decompiled_code:
int __fastcall execute_finish(__int64 a1, __int64 a2, __int64 *a3)
{
__int64 v3; // rbx
int v5; // ebx
__int64 v6; // rax

v3 = *a3;
if ( *a3 )
{
printf("Finsihing '%s'", *(const char **)v3);
*(_DWORD *)(v3 + 24) = 1;
v5 = *(_DWORD *)(a2 + 16) - 1;
if ( v5 >= 0 )
{
while ( 1 )
{
v6 = list_obj_at_idx(a2, (unsigned int)v5--);
if ( v5 == -1 )
break;
if ( *(_DWORD *)(v6 + 24) != 1 )
{
if ( v5 < -1 )
goto LABEL_8;
goto LABEL_6;
}
}
if ( *(_DWORD *)(v6 + 24) != 1 )
{
LABEL_6:
*a3 = v6;
return v6;
}
}
LABEL_8:
LODWORD(v6) = puts("\nAll tasks completed!");
*a3 = 0LL;
}
else
{
LODWORD(v6) = puts("No current task.");
}
return v6;
}

canonical_decompiled_code:
int __fastcall func6(__int64 a1, __int64 a2, __int64 *a3)
{
__int64 v3; // rbx
int v5; // ebx
__int64 v6; // rax

v3 = *a3;
if ( *a3 )
{
printf("Finsihing '%s'", *(const char **)v3);
*(_DWORD *)(v3 + 24) = 1;
v5 = *(_DWORD *)(a2 + 16) - 1;
if ( v5 >= 0 )
{
while ( 1 )
{
v6 = list_obj_at_idx(a2, (unsigned int)v5--);
if ( v5 == -1 )
break;
if ( *(_DWORD *)(v6 + 24) != 1 )
{
if ( v5 < -1 )
goto LABEL_8;
goto LABEL_6;
}
}
if ( *(_DWORD *)(v6 + 24) != 1 )
{
LABEL_6:
*a3 = v6;
return v6;
}
}
LABEL_8:
LODWORD(v6) = puts("\nAll tasks completed!");
*a3 = 0LL;
}
else
{
LODWORD(v6) = puts("No current task.");
}
return v6;
}

original_code:
void execute_finish(char* command, ListT* tasks, TaskT** current_task) {
    if (*current_task != ((void *)0)) {
        TaskT* _current;
        int task_idx;
        _current = *current_task;
        printf("Finsihing '%s'", _current->text);
        _current->is_complete = 1;
        task_idx = tasks->size - 1;
        for (task_idx = tasks->size - 1;
            task_idx >= 0 && _current->is_complete == 1;
            task_idx--) {
            _current = list_obj_at_idx(tasks, task_idx);
        }
        if (task_idx < -1 || _current->is_complete == 1) {
            puts("\nAll tasks completed!");
            *current_task = ((void *)0);
        } else {
            *current_task = _current;
        }
    } else {
        printf("No current task.\n");
    }
}

canonical_original_code:
void execute_finish(char *command, struct ListT *tasks, struct TaskT **current_task) {
    if (*current_task != ((void *)0)) {
        struct TaskT *_current;
        int task_idx;
        _current = *current_task;
        printf("Finsihing '%s'", _current->text);
        _current->is_complete = 1;
        task_idx = tasks->size - 1;
        for (task_idx = tasks->size - 1;
            task_idx >= 0 && _current->is_complete == 1;
            task_idx--) {
            _current = list_obj_at_idx(tasks, task_idx);
        }
        if (task_idx < -1 || _current->is_complete == 1) {
            puts("\nAll tasks completed!");
            *current_task = ((void *)0);
        } else {
            *current_task = _current;
        }
    } else {
        printf("No current task.\n");
    }
}

variable_types: struct ListT { void **values; void **last_value; int size; int capacity; } *


decompiled_code:
int __fastcall execute_show(__int64 a1, __int64 a2, __int64 *a3)
{
__int64 v3; // rax
const char *v4; // rdx

v3 = *a3;
if ( !*a3 )
return puts("No current task.");
v4 = "Finished";
if ( !*(_DWORD *)(v3 + 24) )
v4 = "Not Finished";
return printf("\nYour current task is: '%s'. \nIts status is '%s'.\n", *(const char **)v3, v4);
}

canonical_decompiled_code:
int __fastcall func7(__int64 a1, __int64 a2, __int64 *a3)
{
__int64 v3; // rax
const char *v4; // rdx

v3 = *a3;
if ( !*a3 )
return puts("No current task.");
v4 = "Finished";
if ( !*(_DWORD *)(v3 + 24) )
v4 = "Not Finished";
return printf("\nYour current task is: '%s'. \nIts status is '%s'.\n", *(const char **)v3, v4);
}

original_code:
void execute_show(char* command, ListT* tasks, TaskT** current_task) {
    TaskT* _current;
    _current = *current_task;
    if (_current != ((void *)0)) {
        char* status;
        status = _current->is_complete ? "Finished" : "Not Finished";
        printf("\nYour current task is: '%s'. \nIts status is '%s'.\n", _current->text, status);
    } else {
        printf("No current task.\n");
    }
}

canonical_original_code:
void execute_show(char *command, struct ListT *tasks, struct TaskT **current_task) {
    struct TaskT *_current;
    _current = *current_task;
    if (_current != ((void *)0)) {
        char *status;
        status = _current->is_complete ? "Finished" : "Not Finished";
        printf("\nYour current task is: '%s'. \nIts status is '%s'.\n", _current->text, status);
    } else {
        printf("No current task.\n");
    }
}

variable_types:
status
char *


decompiled_code:
int __fastcall execute_add_note(char *s, __int64 a2, _QWORD *a3)
{
char *v5; // r12
size_t v6; // rax
char *v7; // [rsp+8h] [rbp-20h] BYREF

if ( !s )
_assert_fail("command != NULL", "src/execute.c", 0x59u, "execute_add_note");
if ( !*a3 )
return puts("No current task");
if ( !*(_DWORD *)(a2 + 16) )
return puts("No tasks");
if ( is_command_only((__int64)s) )
{
get_multiline_input(&v7, "What is your note? (hit return twice to end)\n");
}
else
{
v5 = strchr(s, 32);
v6 = strlen(s);
v7 = (char *)malloc(v6 - (s - v5));
strcpy(v7, v5 + 1);
}
return task_add_note(*a3, v7);
}

canonical_decompiled_code:
int __fastcall func8(char *s, __int64 a2, _QWORD *a3)
{
char *v5; // r12
size_t v6; // rax
char *v7; // [rsp+8h] [rbp-20h] BYREF

if ( !s )
_assert_fail("command != NULL", "src/execute.c", 0x59u, "execute_add_note");
if ( !*a3 )
return puts("No current task");
if ( !*(_DWORD *)(a2 + 16) )
return puts("No tasks");
if ( func1((__int64)s) )
{
get_multiline_input(&v7, "What is your note? (hit return twice to end)\n");
}
else
{
v5 = strchr(s, 32);
v6 = strlen(s);
v7 = (char *)malloc(v6 - (s - v5));
strcpy(v7, v5 + 1);
}
return task_add_note(*a3, v7);
}

original_code:
void execute_add_note(char* command, ListT* tasks, TaskT** current_task) {
    ((void) sizeof ((command != ((void *)0)) ? 1 : 0), __extension__ ({ if (command != ((void *)0)) ; else __assert_fail ("command != NULL", "src/execute.c", 89, __extension__ __PRETTY_FUNCTION__); }));
    if (*current_task != ((void *)0)) {
        if (tasks->size == 0) {
            puts("No tasks");
            return;
        }
        char* note;
        if (is_command_only(command)) {
            get_multiline_input(&note, "What is your note? (hit return twice to end)\n");
        } else {
            char *after_space, *first_space;
            int space_idx;
            first_space = strchr(command, ' ');
            note = malloc(sizeof(char) * (strlen(command) - (command - first_space)));
            strcpy(note, first_space + 1);
        }
        task_add_note(*current_task, note);
    } else {
        puts("No current task");
    }
}

canonical_original_code:
void execute_add_note(char *command, struct ListT *tasks, struct TaskT **current_task) {
    ((void) sizeof ((command != ((void *)0)) ? 1 : 0), __extension__ ({ if (command != ((void *)0)) ; else __assert_fail ("command != NULL", "src/execute.c", 89, __extension__ __PRETTY_FUNCTION__); }));
    if (*current_task != ((void *)0)) {
        if (tasks->size == 0) {
            puts("No tasks");
            return;
        }
        char *note;
        if (is_command_only(command)) {
            get_multiline_input(&note, "What is your note? (hit return twice to end)\n");
        } else {
            char *after_space; char *first_space;
            int space_idx;
            first_space = strchr(command, ' ');
            note = malloc(sizeof(char) * (strlen(command) - (command - first_space)));
            strcpy(note, first_space + 1);
        }
        task_add_note(*current_task, note);
    } else {
        puts("No current task");
    }
}

variable_types:
note
char *


decompiled_code:
int __fastcall execute_print(__int64 a1, __int64 a2)
{
int result; // eax
unsigned int v3; // ebx
unsigned int v4; // er12
__int64 v5; // rax

if ( !a2 )
_assert_fail("tasks != NULL", "src/execute.c", 0x76u, "execute_print");
if ( !*(_DWORD *)(a2 + 16) )
return puts("No tasks.");
result = puts(&byte_94B);
if ( *(int *)(a2 + 16) > 0 )
{
v3 = 0;
do
{
v4 = v3++;
printf("Task #%d: ", v3);
v5 = list_obj_at_idx(a2, v4);
task_print(v5);
result = printf("\n");
}
while ( (signed int)v3 < *(_DWORD *)(a2 + 16) );
}
return result;
}

canonical_decompiled_code:
int __fastcall func9(__int64 a1, __int64 a2)
{
int result; // eax
unsigned int v3; // ebx
unsigned int v4; // er12
__int64 v5; // rax

if ( !a2 )
_assert_fail("tasks != NULL", "src/execute.c", 0x76u, "execute_print");
if ( !*(_DWORD *)(a2 + 16) )
return puts("No tasks.");
result = puts(&byte_94B);
if ( *(int *)(a2 + 16) > 0 )
{
v3 = 0;
do
{
v4 = v3++;
printf("Task #%d: ", v3);
v5 = list_obj_at_idx(a2, v4);
task_print(v5);
result = printf("\n");
}
while ( (signed int)v3 < *(_DWORD *)(a2 + 16) );
}
return result;
}

original_code:
void execute_print(char* command, ListT* tasks, TaskT** current_task) {
    ((void) sizeof ((tasks != ((void *)0)) ? 1 : 0), __extension__ ({ if (tasks != ((void *)0)) ; else __assert_fail ("tasks != NULL", "src/execute.c", 118, __extension__ __PRETTY_FUNCTION__); }));
    if (tasks->size == 0) {
        puts("No tasks.");
    } else {
        puts("");
        int task_idx;
        for (task_idx = 0; task_idx < tasks->size; task_idx++) {
            printf("Task #%d: ", task_idx + 1);
            TaskT* task;
            task = list_obj_at_idx(tasks, task_idx);
            task_print(task);
            printf("\n", ((void *)0));
        }
    }
}

canonical_original_code:
void execute_print(char *command, struct ListT *tasks, struct TaskT **current_task) {
    ((void) sizeof ((tasks != ((void *)0)) ? 1 : 0), __extension__ ({ if (tasks != ((void *)0)) ; else __assert_fail ("tasks != NULL", "src/execute.c", 118, __extension__ __PRETTY_FUNCTION__); }));
    if (tasks->size == 0) {
        puts("No tasks.");
    } else {
        puts("");
        int task_idx;
        for (task_idx = 0; task_idx < tasks->size; task_idx++) {
            printf("Task #%d: ", task_idx + 1);
            struct TaskT *task;
            task = list_obj_at_idx(tasks, task_idx);
            task_print(task);
            printf("\n", ((void *)0));
        }
    }
}


decompiled_code:
void __fastcall execute_save(__int64 a1, __int64 a2)
{
char *v2; // rbp
size_t v3; // rax
char *v4; // r12
char *v5; // r12
size_t v6; // rax
char *v7; // r13
char *s; // [rsp+0h] [rbp-30h] BYREF

if ( a2 && *(int *)(a2 + 16) > 0 )
{
s = 0LL;
v2 = make_file_name();
v3 = strlen(v2);
v4 = (char *)malloc(v3 + 49);
sprintf(v4, "Enter a filename or hit return to save as '%s'.\n", v2);
get_user_input_msg(&s, v4);
v5 = s;
if ( s )
{
if ( *s )
{
v6 = strlen(s);
v7 = (char *)malloc(v6 + 7);
sprintf(v7, "tasks/%s", v5);
free(v2);
free(s);
v2 = v7;
}
}
task_write(a2, v2);
free(v2);
}
}

canonical_decompiled_code:
void __fastcall func11(__int64 a1, __int64 a2)
{
char *v2; // rbp
size_t v3; // rax
char *v4; // r12
char *v5; // r12
size_t v6; // rax
char *v7; // r13
char *s; // [rsp+0h] [rbp-30h] BYREF

if ( a2 && *(int *)(a2 + 16) > 0 )
{
s = 0LL;
v2 = func4();
v3 = strlen(v2);
v4 = (char *)malloc(v3 + 49);
sprintf(v4, "Enter a filename or hit return to save as '%s'.\n", v2);
get_user_input_msg(&s, v4);
v5 = s;
if ( s )
{
if ( *s )
{
v6 = strlen(s);
v7 = (char *)malloc(v6 + 7);
sprintf(v7, "tasks/%s", v5);
free(v2);
free(s);
v2 = v7;
}
}
task_write(a2, v2);
free(v2);
}
}

original_code:
void execute_save(char* command, ListT* tasks, TaskT** current_task) {
    char* filename;
    int write_result;
    if (tasks != ((void *)0) && tasks->size > 0) {
        char* user_filename = ((void *)0);
        char* input_msg = ((void *)0);
        filename = make_file_name();
        input_msg = malloc(strlen(filename) + strlen(kFilenamePromptFormat) + 1);
        sprintf(input_msg, kFilenamePromptFormat, filename);
        get_user_input_msg(&user_filename, input_msg);
        if (user_filename != ((void *)0) && strlen(user_filename) > 0) {
            char* user_filename_with_dir;
            user_filename_with_dir = malloc(6 + 1 + strlen(user_filename));
            sprintf(user_filename_with_dir, "tasks/%s", user_filename);
            free(filename);
            free(user_filename);
            filename = user_filename_with_dir;
        }
        write_result = task_write(tasks, filename);
        if (task_write < 0) {
            printf("Failed to write tasks to %s\n", filename);
        }
        free(filename);
    }
}

canonical_original_code:
void execute_save(char *command, struct ListT *tasks, struct TaskT **current_task) {
    char *filename;
    int write_result;
    if (tasks != ((void *)0) && tasks->size > 0) {
        char *user_filename = ((void *)0);
        char *input_msg = ((void *)0);
        filename = make_file_name();
        input_msg = malloc(strlen(filename) + strlen(kFilenamePromptFormat) + 1);
        sprintf(input_msg, kFilenamePromptFormat, filename);
        get_user_input_msg(&user_filename, input_msg);
        if (user_filename != ((void *)0) && strlen(user_filename) > 0) {
            char *user_filename_with_dir;
            user_filename_with_dir = malloc(6 + 1 + strlen(user_filename));
            sprintf(user_filename_with_dir, "tasks/%s", user_filename);
            free(filename);
            free(user_filename);
            filename = user_filename_with_dir;
        }
        write_result = task_write(tasks, filename);
        if (task_write < 0) {
            printf("Failed to write tasks to %s\n", filename);
        }
        free(filename);
    }
}


decompiled_code:
__int64 __fastcall execute_load(__int64 a1, __int64 a2, __int64 *a3)
{
__int64 v3; // r12
__int64 v5; // rbp
int v6; // eax
unsigned int v7; // ebx
const char *v8; // r14
size_t v9; // rax
char *v10; // rbx
__int64 v11; // r14
__int64 v13[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = a2;
if ( a2 && *(int *)(a2 + 16) > 0 )
{
if ( (printf("Save before load? (y)/n? "), get_user_input(v13), v13[0]) && *(_BYTE *)v13[0] == 121
|| *(_BYTE *)v13[0] == 89 )
{
puts("saving");
execute_save(a1, a2);
}
}
v5 = get_loadables(1);
if ( *(int *)(v5 + 16) <= 0 )
{
puts("No files to load.");
}
else
{
do
{
do
{
v6 = get_numeric_input("Choose which file to load? ");
v7 = v6;
}
while ( v6 < 0 );
}
while ( *(_DWORD *)(v5 + 16) <= v6 );
tk_log("Debug", "src/execute.c", "execute_load", 180LL, "user_selection %d", (unsigned int)v6);
puts("\n");
v8 = (const char *)list_obj_at_idx(v5, v7);
v9 = strlen(v8);
v10 = (char *)malloc(v9 + 20);
sprintf(v10, "tasks/%s", v8);
list_empty(a2, 1LL);
v11 = task_read(v10);
list_copy(a2, v11);
if ( a2 )
{
if ( *(int *)(a2 + 16) > 0 )
v3 = list_obj_at_idx(a2, 0LL);
else
v3 = 0LL;
}
*a3 = v3;
list_destroy(v11);
free(v10);
}
return list_destroy(v5);
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, __int64 a2, __int64 *a3)
{
__int64 v3; // r12
__int64 v5; // rbp
int v6; // eax
unsigned int v7; // ebx
const char *v8; // r14
size_t v9; // rax
char *v10; // rbx
__int64 v11; // r14
__int64 v13[6]; // [rsp+8h] [rbp-30h] BYREF

v3 = a2;
if ( a2 && *(int *)(a2 + 16) > 0 )
{
if ( (printf("Save before load? (y)/n? "), get_user_input(v13), v13[0]) && *(_BYTE *)v13[0] == 121
|| *(_BYTE *)v13[0] == 89 )
{
puts("saving");
func11(a1, a2);
}
}
v5 = func3(1);
if ( *(int *)(v5 + 16) <= 0 )
{
puts("No files to load.");
}
else
{
do
{
do
{
v6 = get_numeric_input("Choose which file to load? ");
v7 = v6;
}
while ( v6 < 0 );
}
while ( *(_DWORD *)(v5 + 16) <= v6 );
tk_log("Debug", "src/execute.c", "execute_load", 180LL, "user_selection %d", (unsigned int)v6);
puts("\n");
v8 = (const char *)list_obj_at_idx(v5, v7);
v9 = strlen(v8);
v10 = (char *)malloc(v9 + 20);
sprintf(v10, "tasks/%s", v8);
list_empty(a2, 1LL);
v11 = task_read(v10);
list_copy(a2, v11);
if ( a2 )
{
if ( *(int *)(a2 + 16) > 0 )
v3 = list_obj_at_idx(a2, 0LL);
else
v3 = 0LL;
}
*a3 = v3;
list_destroy(v11);
free(v10);
}
return list_destroy(v5);
}

original_code:
void execute_load(char* command, ListT* tasks, TaskT** current_task) {
    ListT* files;
    if (tasks != ((void *)0) && tasks->size > 0) {
        char* save_before_load;
        printf("Save before load? (y)/n? ");
        get_user_input(&save_before_load);
        if (save_before_load != ((void *)0) && strlen(save_before_load) > 0
            && save_before_load[0] == 'y' || save_before_load[0] == 'Y') {
            printf("saving\n");
            execute_save(command, tasks, current_task);
        }
    }
    files = get_loadables(1);
    if (files->size > 0) {
        ListT* _tasks;
        TaskT* loaded_task;
        int user_selection;
        char *filename, *abs_file;;
        while ((user_selection = get_numeric_input("Choose which file to load? ")) < 0 || user_selection >= files->size) ;
        do { tk_log("Debug", "src/execute.c", __FUNCTION__, 180, "user_selection %d", user_selection); } while(0);;
        printf("\n\n");
        filename = list_obj_at_idx(files, user_selection);
        abs_file = malloc(strlen(filename) + 20);
        sprintf(abs_file, "tasks/%s", filename);
        list_empty(tasks, 1);
        _tasks = task_read(abs_file);
        list_copy(tasks, _tasks);
        *current_task = tasks != ((void *)0) && tasks->size > 0 ? list_obj_at_idx(tasks, 0) : ((void *)0);
        list_destroy(_tasks);
        free(abs_file);
    } else {
        puts("No files to load.");
    }
    list_destroy(files);
}

canonical_original_code:
void execute_load(char *command, struct ListT *tasks, struct TaskT **current_task) {
    struct ListT *files;
    if (tasks != ((void *)0) && tasks->size > 0) {
        char *save_before_load;
        printf("Save before load? (y)/n? ");
        get_user_input(&save_before_load);
        if (save_before_load != ((void *)0) && strlen(save_before_load) > 0
            && save_before_load[0] == 'y' || save_before_load[0] == 'Y') {
            printf("saving\n");
            execute_save(command, tasks, current_task);
        }
    }
    files = get_loadables(1);
    if (files->size > 0) {
        struct ListT *_tasks;
        struct TaskT *loaded_task;
        int user_selection;
        char *filename; char *abs_file;;
        while ((user_selection = get_numeric_input("Choose which file to load? ")) < 0 || user_selection >= files->size) ;
        do { tk_log("Debug", "src/execute.c", __FUNCTION__, 180, "user_selection %d", user_selection); } while(0);;
        printf("\n\n");
        filename = list_obj_at_idx(files, user_selection);
        abs_file = malloc(strlen(filename) + 20);
        sprintf(abs_file, "tasks/%s", filename);
        list_empty(tasks, 1);
        _tasks = task_read(abs_file);
        list_copy(tasks, _tasks);
        *current_task = tasks != ((void *)0) && tasks->size > 0 ? list_obj_at_idx(tasks, 0) : ((void *)0);
        list_destroy(_tasks);
        free(abs_file);
    } else {
        puts("No files to load.");
    }
    list_destroy(files);
}