decompiled_code:
__int64 __fastcall marktab_rend_file(const char *a1)
{
__int64 result; // rax

yyin = fopen(a1, "r");
if ( yyin )
{
mtr_init();
mt_conf_init();
yyparse();
mt_output(MTR[1]);
if ( yyin )
fclose(yyin);
result = 0LL;
}
else
{
fprintf(stderr, "Can't open: \"%s\"\n", a1);
result = 1LL;
}
return result;
}

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

yyin = fopen(a1, "r");
if ( yyin )
{
mtr_init();
mt_conf_init();
yyparse();
mt_output(MTR[1]);
if ( yyin )
fclose(yyin);
result = 0LL;
}
else
{
fprintf(stderr, "Can't open: \"%s\"\n", a1);
result = 1LL;
}
return result;
}

original_code:
int marktab_rend_file(char* file)
{
  yyin = fopen(file, "r");
  if (yyin == ((void *)0))
  {
    fprintf(stderr, "Can't open: \"%s\"\n", file);
    return 1;
  }
  mtr_init();
  mt_conf_init();
  yyparse();
  mt_output(MTR.sections);
  if (yyin != ((void *)0))
    fclose(yyin);
  return 0;
}

canonical_original_code:
int marktab_rend_file(char *file)
{
  yyin = fopen(file, "r");
  if (yyin == ((void *)0))
  {
    fprintf(stderr, "Can't open: \"%s\"\n", file);
    return 1;
  }
  mtr_init();
  mt_conf_init();
  yyparse();
  mt_output(MTR.sections);
  if (yyin != ((void *)0))
    fclose(yyin);
  return 0;
}

variable_types:
file
char *


repo: cknadler/marktab-c

decompiled_code:
void mt_conf_init()
{
MT_CONF = 6;
*((_QWORD *)&MT_CONF + 1) = "eBGDAE";
*(&MT_CONF + 4) = 80;
}

canonical_decompiled_code:
void func0()
{
MT_CONF = 6;
*((_QWORD *)&MT_CONF + 1) = "eBGDAE";
*(&MT_CONF + 4) = 80;
}

original_code:
void
mt_conf_init()
{
  MT_CONF.strings = 6;
  MT_CONF.string_names = "eBGDAE";
  MT_CONF.max_line_length = 80;
}

return_type: void


decompiled_code:
__int64 __fastcall mt_conf_set_option(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("id != NULL", "src/mt_conf.c", 0x1Du, "mt_conf_set_option");
if ( !a2 )
_assert_fail("value != NULL", "src/mt_conf.c", 0x1Eu, "mt_conf_set_option");
mt_string_compare_utf8(a1, "tuning");
mt_string_compare_utf8(a1, "line_length");
mt_string_free(a1);
return mt_string_free(a2);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, __int64 a2)
{
if ( !a1 )
_assert_fail("id != NULL", "src/mt_conf.c", 0x1Du, "mt_conf_set_option");
if ( !a2 )
_assert_fail("value != NULL", "src/mt_conf.c", 0x1Eu, "mt_conf_set_option");
mt_string_compare_utf8(a1, "tuning");
mt_string_compare_utf8(a1, "line_length");
mt_string_free(a1);
return mt_string_free(a2);
}

original_code:
void
mt_conf_set_option(MtString* id, MtString* value)
{
  ((void) sizeof ((id != ((void *)0)) ? 1 : 0), __extension__ ({ if (id != ((void *)0)) ; else __assert_fail ("id != NULL", "src/mt_conf.c", 29, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((value != ((void *)0)) ? 1 : 0), __extension__ ({ if (value != ((void *)0)) ; else __assert_fail ("value != NULL", "src/mt_conf.c", 30, __extension__ __PRETTY_FUNCTION__); }));
  if (mt_string_compare_utf8(id, "tuning"))
    mt_conf_set_tuning(value);
  if (mt_string_compare_utf8(id, "line_length"))
    mt_conf_set_line_length(value);
  mt_string_free(id);
  mt_string_free(value);
}

canonical_original_code:
void mt_conf_set_option(struct MtString *id, struct MtString *value)
{
  ((void) sizeof ((id != ((void *)0)) ? 1 : 0), __extension__ ({ if (id != ((void *)0)) ; else __assert_fail ("id != NULL", "src/mt_conf.c", 29, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((value != ((void *)0)) ? 1 : 0), __extension__ ({ if (value != ((void *)0)) ; else __assert_fail ("value != NULL", "src/mt_conf.c", 30, __extension__ __PRETTY_FUNCTION__); }));
  if (mt_string_compare_utf8(id, "tuning"))
    mt_conf_set_tuning(value);
  if (mt_string_compare_utf8(id, "line_length"))
    mt_conf_set_line_length(value);
  mt_string_free(id);
  mt_string_free(value);
}

variable_types: struct MtString { char *utf8_data; unsigned long size; unsigned long length; unsigned long hash; } *

variable_types:
value
struct MtString *


decompiled_code:
void __fastcall mt_pair_free(void *ptr)
{
if ( !ptr )
_assert_fail("pair != NULL", "src/mt_pair.c", 0x16u, "mt_pair_free");
mt_string_free(*(_QWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( !ptr )
_assert_fail("pair != NULL", "src/mt_pair.c", 0x16u, "mt_pair_free");
mt_string_free(*(_QWORD *)ptr);
free(ptr);
}

original_code:
void mt_pair_free(MtPair* pair)
{
  ((void) sizeof ((pair != ((void *)0)) ? 1 : 0), __extension__ ({ if (pair != ((void *)0)) ; else __assert_fail ("pair != NULL", "src/mt_pair.c", 22, __extension__ __PRETTY_FUNCTION__); }));
  mt_string_free(pair->key);
  free(pair);
}

canonical_original_code:
void mt_pair_free(struct MtPair *pair)
{
  ((void) sizeof ((pair != ((void *)0)) ? 1 : 0), __extension__ ({ if (pair != ((void *)0)) ; else __assert_fail ("pair != NULL", "src/mt_pair.c", 22, __extension__ __PRETTY_FUNCTION__); }));
  mt_string_free(pair->key);
  free(pair);
}

variable_types: struct MtPair { struct MtString { char *utf8_data; unsigned long size; unsigned long length; unsigned long hash; } *key; void *value; } *

user_defined_types: struct MtPair { struct MtString *key; void *value; }


original_code:
static size_t Murmur3(const char* key, size_t len)
{
  const size_t seed = 0xDEADBEEF;
  const size_t m1 = 0x0acffe3d, m2 = 0x0e4ef5f3, m3 = 0xa729a897;
  const size_t r1 = 11, r2 = 18, r3 = 18;
  size_t h = len + seed, k = 0;
  const size_t* dwords = (const size_t*) key;
  while(len >= sizeof(size_t))
  {
    k = *dwords++;
    { k *= m1; k = (k<<r1)|(k>>(sizeof(size_t)*8-r1)); k *= m2; h *= 3; h ^= k; };
    len -= sizeof(size_t);
  }
  const char* tail = (const char*) dwords;
  switch (len)
  {
    case 3: k ^= tail[2] << 16;
    case 2: k ^= tail[1] << 8;
    case 1:
      k ^= tail[0];
      { k *= m1; k = (k<<r1)|(k>>(sizeof(size_t)*8-r1)); k *= m2; h *= 3; h ^= k; };
  }
  h ^= h >> r2;
  h *= m3;
  h ^= h >> r3;
  return h;
}

canonical_original_code:
static unsigned long Murmur3(char *key, unsigned long len)
{
  unsigned long seed = 0xDEADBEEF;
  unsigned long m1 = 0x0acffe3d; unsigned long m2 = 0x0e4ef5f3; unsigned long m3 = 0xa729a897;
  unsigned long r1 = 11; unsigned long r2 = 18; unsigned long r3 = 18;
  unsigned long h = len + seed; unsigned long k = 0;
  unsigned long *dwords = (const size_t*) key;
  while(len >= sizeof(unsigned long))
  {
    k = *dwords++;
    { k *= m1; k = (k<<r1)|(k>>(sizeof(unsigned long)*8-r1)); k *= m2; h *= 3; h ^= k; };
    len -= sizeof(unsigned long);
  }
  char *tail = (const char*) dwords;
  switch (len)
  {
    case 3: k ^= tail[2] << 16;
    case 2: k ^= tail[1] << 8;
    case 1:
      k ^= tail[0];
      { k *= m1; k = (k<<r1)|(k>>(sizeof(unsigned long)*8-r1)); k *= m2; h *= 3; h ^= k; };
  }
  h ^= h >> r2;
  h *= m3;
  h ^= h >> r3;
  return h;
}

variable_types:
key
char *

variable_types:
len
unsigned long

variable_types:
seed
unsigned long

variable_types:
h
unsigned long

variable_types:
k
unsigned long

variable_types:
dwords
unsigned long *

variable_types:
tail
char *

return_type: unsigned long


decompiled_code:
void __fastcall mt_hash_double_size(__int64 a1)
{
__int64 v1; // r12
_QWORD *v2; // r13
void *v3; // rax
__int64 i; // rbx

if ( !a1 )
_assert_fail("hash != NULL", "src/mt_hash.c", 0x6Au, "mt_hash_double_size");
v1 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 16) = 0LL;
v2 = *(_QWORD **)a1;
*(_QWORD *)(a1 + 8) = 2 * v1;
v3 = malloc(32 * v1);
*(_QWORD *)a1 = v3;
if ( 2 * v1 )
memset(v3, 0, 16 * v1);
if ( v1 )
{
for ( i = 0LL; i != v1; ++i )
{
if ( v2[i] )
mt_hash_insert_pair(a1);
}
}
free(v2);
}

original_code:
static void
mt_hash_double_size(MtHash* hash)
{
  ((void) sizeof ((hash != ((void *)0)) ? 1 : 0), __extension__ ({ if (hash != ((void *)0)) ; else __assert_fail ("hash != NULL", "src/mt_hash.c", 106, __extension__ __PRETTY_FUNCTION__); }));
  size_t old_size = hash->size;
  hash->size <<= 1;
  hash->length = 0;
  MtPair** old_buckets = hash->buckets;
  { hash->buckets = malloc(sizeof(MtPair) * hash->size); size_t i; for (i = 0; i < hash->size; ++i) hash->buckets[i] = ((void *)0); };
  MtPair* element;
  size_t i;
  for (i = 0; i < old_size; ++i)
  {
    element = old_buckets[i];
    if (element)
      mt_hash_insert_pair(hash, element);
  }
  free(old_buckets);
}

canonical_original_code:
static void mt_hash_double_size(struct MtHash *hash)
{
  ((void) sizeof ((hash != ((void *)0)) ? 1 : 0), __extension__ ({ if (hash != ((void *)0)) ; else __assert_fail ("hash != NULL", "src/mt_hash.c", 106, __extension__ __PRETTY_FUNCTION__); }));
  unsigned long old_size = hash->size;
  hash->size <<= 1;
  hash->length = 0;
  struct MtPair **old_buckets = hash->buckets;
  { hash->buckets = malloc(sizeof(MtPair) * hash->size); unsigned long i; for (i = 0; i < hash->size; ++i) hash->buckets[i] = ((void *)0); };
  struct MtPair *element;
  unsigned long i;
  for (i = 0; i < old_size; ++i)
  {
    element = old_buckets[i];
    if (element)
      mt_hash_insert_pair(hash, element);
  }
  free(old_buckets);
}

variable_types: struct MtHash { struct MtPair { struct MtString { char *utf8_data; unsigned long size; unsigned long length; unsigned long hash; } *key; void *value; } **buckets; unsigned long size; unsigned long length; } *

variable_types:
i
unsigned long

user_defined_types: struct MtHash { struct MtPair **buckets; unsigned long size; unsigned long length; }


original_code:
static void
mt_hash_insert_pair(MtHash* hash, MtPair* pair)
{
  ((void) sizeof ((hash != ((void *)0)) ? 1 : 0), __extension__ ({ if (hash != ((void *)0)) ; else __assert_fail ("hash != NULL", "src/mt_hash.c", 70, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((pair != ((void *)0)) ? 1 : 0), __extension__ ({ if (pair != ((void *)0)) ; else __assert_fail ("pair != NULL", "src/mt_hash.c", 71, __extension__ __PRETTY_FUNCTION__); }));
  size_t index = pair->key->hash % hash->size;
  MtPair* element = hash->buckets[index];
  if (element == ((void *)0))
  {
    hash->buckets[index] = pair;
    ++hash->length;
    if (hash->length >= 0.75 * hash->size)
      mt_hash_double_size(hash);
  }
  while (element != ((void *)0))
  {
    if (mt_string_compare(element->key, pair->key) == 0)
    {
      hash->buckets[index] = pair;
      return;
    }
    ++index;
    index %= hash->size;
    element = hash->buckets[index];
  }
}

canonical_original_code:
static void mt_hash_insert_pair(struct MtHash *hash, struct MtPair *pair)
{
  ((void) sizeof ((hash != ((void *)0)) ? 1 : 0), __extension__ ({ if (hash != ((void *)0)) ; else __assert_fail ("hash != NULL", "src/mt_hash.c", 70, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((pair != ((void *)0)) ? 1 : 0), __extension__ ({ if (pair != ((void *)0)) ; else __assert_fail ("pair != NULL", "src/mt_hash.c", 71, __extension__ __PRETTY_FUNCTION__); }));
  unsigned long index = pair->key->hash % hash->size;
  struct MtPair *element = hash->buckets[index];
  if (element == ((void *)0))
  {
    hash->buckets[index] = pair;
    ++hash->length;
    if (hash->length >= 0.75 * hash->size)
      mt_hash_double_size(hash);
  }
  while (element != ((void *)0))
  {
    if (mt_string_compare(element->key, pair->key) == 0)
    {
      hash->buckets[index] = pair;
      return;
    }
    ++index;
    index %= hash->size;
    element = hash->buckets[index];
  }
}

variable_types:
pair
struct MtPair *

variable_types:
index
unsigned long

user_defined_types: struct MtString { char *utf8_data; unsigned long size; unsigned long length; unsigned long hash; }


decompiled_code:
_QWORD *mt_hash_new()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
void *v2; // rdx

v0 = malloc(0x18uLL);
if ( !v0 )
_assert_fail("hash != NULL", "src/mt_hash.c", 0x8Fu, "mt_hash_new");
v0[1] = 16LL;
v1 = v0;
v0[2] = 0LL;
v2 = malloc(0x100uLL);
*v1 = v2;
memset(v2, 0, 0x80uLL);
return v1;
}

canonical_decompiled_code:
_QWORD *func3()
{
_QWORD *v0; // rax
_QWORD *v1; // r12
void *v2; // rdx

v0 = malloc(0x18uLL);
if ( !v0 )
_assert_fail("hash != NULL", "src/mt_hash.c", 0x8Fu, "mt_hash_new");
v0[1] = 16LL;
v1 = v0;
v0[2] = 0LL;
v2 = malloc(0x100uLL);
*v1 = v2;
memset(v2, 0, 0x80uLL);
return v1;
}

original_code:
MtHash*
mt_hash_new()
{
  MtHash* hash = (MtHash*) malloc(sizeof(MtHash));
  ((void) sizeof ((hash != ((void *)0)) ? 1 : 0), __extension__ ({ if (hash != ((void *)0)) ; else __assert_fail ("hash != NULL", "src/mt_hash.c", 143, __extension__ __PRETTY_FUNCTION__); }));
  hash->size = 16;
  hash->length = 0;
  { hash->buckets = malloc(sizeof(MtPair) * hash->size); size_t i; for (i = 0; i < hash->size; ++i) hash->buckets[i] = ((void *)0); };
  return hash;
}

canonical_original_code:
struct MtHash *mt_hash_new()
{
  struct MtHash *hash = (MtHash*) malloc(sizeof(MtHash));
  ((void) sizeof ((hash != ((void *)0)) ? 1 : 0), __extension__ ({ if (hash != ((void *)0)) ; else __assert_fail ("hash != NULL", "src/mt_hash.c", 143, __extension__ __PRETTY_FUNCTION__); }));
  hash->size = 16;
  hash->length = 0;
  { hash->buckets = malloc(sizeof(MtPair) * hash->size); unsigned long i; for (i = 0; i < hash->size; ++i) hash->buckets[i] = ((void *)0); };
  return hash;
}

return_type: struct MtHash { struct MtPair { struct MtString { char *utf8_data; unsigned long size; unsigned long length; unsigned long hash; } *key; void *value; } **buckets; unsigned long size; unsigned long length; } *


decompiled_code:
void __fastcall mt_hash_insert(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 *v4; // rax
unsigned __int64 v5; // r14
_QWORD *v6; // rax

if ( !a1 )
_assert_fail("hash != NULL", "src/mt_hash.c", 0x9Du, "mt_hash_insert");
if ( !a2 )
_assert_fail("key != NULL", "src/mt_hash.c", 0x9Eu, "mt_hash_insert");
if ( !*(_QWORD *)(a2 + 24) )
{
v5 = mt_string_get_length(a2);
v6 = (_QWORD *)mt_string_get_utf8(a2);
*(_QWORD *)(a2 + 24) = Murmur3(v6, v5);
}
v4 = (__int64 *)mt_pair_new(a2, a3);
mt_hash_insert_pair(a1, v4);
}

canonical_decompiled_code:
void __fastcall func4(_QWORD *a1, __int64 a2, __int64 a3)
{
__int64 *v4; // rax
unsigned __int64 v5; // r14
_QWORD *v6; // rax

if ( !a1 )
_assert_fail("hash != NULL", "src/mt_hash.c", 0x9Du, "mt_hash_insert");
if ( !a2 )
_assert_fail("key != NULL", "src/mt_hash.c", 0x9Eu, "mt_hash_insert");
if ( !*(_QWORD *)(a2 + 24) )
{
v5 = mt_string_get_length(a2);
v6 = (_QWORD *)mt_string_get_utf8(a2);
*(_QWORD *)(a2 + 24) = func0(v6, v5);
}
v4 = (__int64 *)mt_pair_new(a2, a3);
func2(a1, v4);
}

original_code:
void
mt_hash_insert(MtHash* hash, MtString* key, void* value)
{
  ((void) sizeof ((hash != ((void *)0)) ? 1 : 0), __extension__ ({ if (hash != ((void *)0)) ; else __assert_fail ("hash != NULL", "src/mt_hash.c", 157, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((key != ((void *)0)) ? 1 : 0), __extension__ ({ if (key != ((void *)0)) ; else __assert_fail ("key != NULL", "src/mt_hash.c", 158, __extension__ __PRETTY_FUNCTION__); }));
  if (key->hash == 0)
    key->hash = Murmur3(mt_string_get_utf8(key), mt_string_get_length(key));
  mt_hash_insert_pair(hash, mt_pair_new(key, value));
}

canonical_original_code:
void mt_hash_insert(struct MtHash *hash, struct MtString *key, void *value)
{
  ((void) sizeof ((hash != ((void *)0)) ? 1 : 0), __extension__ ({ if (hash != ((void *)0)) ; else __assert_fail ("hash != NULL", "src/mt_hash.c", 157, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((key != ((void *)0)) ? 1 : 0), __extension__ ({ if (key != ((void *)0)) ; else __assert_fail ("key != NULL", "src/mt_hash.c", 158, __extension__ __PRETTY_FUNCTION__); }));
  if (key->hash == 0)
    key->hash = Murmur3(mt_string_get_utf8(key), mt_string_get_length(key));
  mt_hash_insert_pair(hash, mt_pair_new(key, value));
}

variable_types:
key
struct MtString *

variable_types:
value
void *


decompiled_code:
void __fastcall mt_hash_free(void *ptr)
{
if ( !ptr )
_assert_fail("hash != NULL", "src/mt_hash.c", 0xE9u, "mt_hash_free");
mt_hash_clear((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
if ( !ptr )
_assert_fail("hash != NULL", "src/mt_hash.c", 0xE9u, "mt_hash_free");
func5((__int64)ptr);
free(*(void **)ptr);
free(ptr);
}

original_code:
void
mt_hash_free(MtHash* hash)
{
  ((void) sizeof ((hash != ((void *)0)) ? 1 : 0), __extension__ ({ if (hash != ((void *)0)) ; else __assert_fail ("hash != NULL", "src/mt_hash.c", 233, __extension__ __PRETTY_FUNCTION__); }));
  mt_hash_clear(hash);
  free(hash->buckets);
  free(hash);
}

canonical_original_code:
void mt_hash_free(struct MtHash *hash)
{
  ((void) sizeof ((hash != ((void *)0)) ? 1 : 0), __extension__ ({ if (hash != ((void *)0)) ; else __assert_fail ("hash != NULL", "src/mt_hash.c", 233, __extension__ __PRETTY_FUNCTION__); }));
  mt_hash_clear(hash);
  free(hash->buckets);
  free(hash);
}


decompiled_code:
void __fastcall mt_queue_node_free(void *a1)
{
if ( !a1 )
_assert_fail("node != NULL", "src/mt_queue.c", 0x17u, "mt_queue_node_free");
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
if ( !a1 )
_assert_fail("node != NULL", "src/mt_queue.c", 0x17u, "mt_queue_node_free");
free(a1);
}

original_code:
void mt_queue_node_free(MtQueueNode* node)
{
  ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "src/mt_queue.c", 23, __extension__ __PRETTY_FUNCTION__); }));
  node->value = ((void *)0);
  node->next = ((void *)0);
  free(node);
}

canonical_original_code:
void mt_queue_node_free(struct MtQueueNode *node)
{
  ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "src/mt_queue.c", 23, __extension__ __PRETTY_FUNCTION__); }));
  node->value = ((void *)0);
  node->next = ((void *)0);
  free(node);
}

variable_types: struct MtQueueNode { void *value; struct MtQueueNode *next; } *


decompiled_code:
_QWORD *mt_queue_new()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( !result )
_assert_fail("queue != NULL", "src/mt_queue.c", 0x27u, "mt_queue_new");
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(0x18uLL);
if ( !result )
_assert_fail("queue != NULL", "src/mt_queue.c", 0x27u, "mt_queue_new");
*(_DWORD *)result = 0;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

original_code:
MtQueue* mt_queue_new()
{
  MtQueue* queue = (MtQueue *) malloc(sizeof(MtQueue));
  ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/mt_queue.c", 39, __extension__ __PRETTY_FUNCTION__); }));
  queue->length = 0;
  queue->front = ((void *)0);
  queue->back = ((void *)0);
  return queue;
}

canonical_original_code:
struct MtQueue *mt_queue_new()
{
  struct MtQueue *queue = (MtQueue *) malloc(sizeof(MtQueue));
  ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/mt_queue.c", 39, __extension__ __PRETTY_FUNCTION__); }));
  queue->length = 0;
  queue->front = ((void *)0);
  queue->back = ((void *)0);
  return queue;
}

variable_types: struct MtQueue { int length; struct MtQueueNode { void *value; struct MtQueueNode *next; } *front; struct MtQueueNode *back; } *

user_defined_types: struct MtQueue { int length; struct MtQueueNode *front; struct MtQueueNode *back; }


decompiled_code:
__int64 __fastcall mt_queue_dequeue(__int64 a1)
{
__int64 v2; // r12
__int64 *v3; // rdi

if ( !a1 )
_assert_fail("queue != NULL", "src/mt_queue.c", 0x47u, "mt_queue_dequeue");
v2 = 0LL;
if ( *(int *)a1 > 0 )
{
v3 = *(__int64 **)(a1 + 8);
v2 = *v3;
*(_QWORD *)(a1 + 8) = v3[1];
mt_queue_node_free(v3);
--*(_DWORD *)a1;
}
return v2;
}

original_code:
void* mt_queue_dequeue(MtQueue* queue)
{
  ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/mt_queue.c", 71, __extension__ __PRETTY_FUNCTION__); }));
  if (queue->length > 0)
  {
    MtQueueNode* front_node = queue->front;
    void* value = front_node->value;
    queue->front = front_node->next;
    mt_queue_node_free(front_node);
    --queue->length;
    return value;
  }
  return ((void *)0);
}

canonical_original_code:
void *mt_queue_dequeue(struct MtQueue *queue)
{
  ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/mt_queue.c", 71, __extension__ __PRETTY_FUNCTION__); }));
  if (queue->length > 0)
  {
    struct MtQueueNode *front_node = queue->front;
    void *value = front_node->value;
    queue->front = front_node->next;
    mt_queue_node_free(front_node);
    --queue->length;
    return value;
  }
  return ((void *)0);
}

return_type: void *

user_defined_types: struct MtQueueNode { void *value; struct MtQueueNode *next; }


decompiled_code:
void __fastcall mt_queue_clear(__int64 a1)
{
if ( !a1 )
_assert_fail("queue != NULL", "src/mt_queue.c", 0x5Du, "mt_queue_clear");
*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}

canonical_decompiled_code:
void __fastcall func4(__int64 a1)
{
if ( !a1 )
_assert_fail("queue != NULL", "src/mt_queue.c", 0x5Du, "mt_queue_clear");
*(_DWORD *)a1 = 0;
*(_QWORD *)(a1 + 8) = 0LL;
*(_QWORD *)(a1 + 16) = 0LL;
}

original_code:
void mt_queue_clear(MtQueue* queue)
{
  ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/mt_queue.c", 93, __extension__ __PRETTY_FUNCTION__); }));
  queue->length = 0;
  queue->front = ((void *)0);
  queue->back = ((void *)0);
}

canonical_original_code:
void mt_queue_clear(struct MtQueue *queue)
{
  ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/mt_queue.c", 93, __extension__ __PRETTY_FUNCTION__); }));
  queue->length = 0;
  queue->front = ((void *)0);
  queue->back = ((void *)0);
}


decompiled_code:
void __fastcall mt_queue_free(void *ptr)
{
if ( !ptr )
_assert_fail("queue != NULL", "src/mt_queue.c", 0x68u, "mt_queue_free");
mt_queue_clear((__int64)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
if ( !ptr )
_assert_fail("queue != NULL", "src/mt_queue.c", 0x68u, "mt_queue_free");
func4((__int64)ptr);
free(ptr);
}

original_code:
void mt_queue_free(MtQueue* queue)
{
  ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/mt_queue.c", 104, __extension__ __PRETTY_FUNCTION__); }));
  mt_queue_clear(queue);
  free(queue);
}

canonical_original_code:
void mt_queue_free(struct MtQueue *queue)
{
  ((void) sizeof ((queue != ((void *)0)) ? 1 : 0), __extension__ ({ if (queue != ((void *)0)) ; else __assert_fail ("queue != NULL", "src/mt_queue.c", 104, __extension__ __PRETTY_FUNCTION__); }));
  mt_queue_clear(queue);
  free(queue);
}


decompiled_code:
void __fastcall mt_stack_node_free(void *a1)
{
if ( !a1 )
_assert_fail("node != NULL", "src/mt_stack.c", 0x14u, "mt_stack_node_free");
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
if ( !a1 )
_assert_fail("node != NULL", "src/mt_stack.c", 0x14u, "mt_stack_node_free");
free(a1);
}

original_code:
static void mt_stack_node_free(MtStackNode* node)
{
  ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "src/mt_stack.c", 20, __extension__ __PRETTY_FUNCTION__); }));
  free(node);
}

canonical_original_code:
static void mt_stack_node_free(struct MtStackNode *node)
{
  ((void) sizeof ((node != ((void *)0)) ? 1 : 0), __extension__ ({ if (node != ((void *)0)) ; else __assert_fail ("node != NULL", "src/mt_stack.c", 20, __extension__ __PRETTY_FUNCTION__); }));
  free(node);
}

variable_types: struct MtStackNode { void *value; struct MtStackNode *next; } *


decompiled_code:
_QWORD *mt_stack_new()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( !result )
_assert_fail("stack != NULL", "src/mt_stack.c", 0x1Du, "mt_stack_new");
*result = 0LL;
result[1] = 0LL;
return result;
}

canonical_decompiled_code:
_QWORD *func1()
{
_QWORD *result; // rax

result = malloc(0x10uLL);
if ( !result )
_assert_fail("stack != NULL", "src/mt_stack.c", 0x1Du, "mt_stack_new");
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
MtStack* mt_stack_new()
{
  MtStack* stack = (MtStack *) malloc(sizeof(MtStack));
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/mt_stack.c", 29, __extension__ __PRETTY_FUNCTION__); }));
  stack->head = ((void *)0);
  stack->size = 0;
  return stack;
}

canonical_original_code:
struct MtStack *mt_stack_new()
{
  struct MtStack *stack = (MtStack *) malloc(sizeof(MtStack));
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/mt_stack.c", 29, __extension__ __PRETTY_FUNCTION__); }));
  stack->head = ((void *)0);
  stack->size = 0;
  return stack;
}

variable_types: struct MtStack { struct MtStackNode { void *value; struct MtStackNode *next; } *head; unsigned long size; } *

user_defined_types: struct MtStack { struct MtStackNode *head; unsigned long size; }


decompiled_code:
__int64 __fastcall mt_stack_pop(__int64 a1)
{
__int64 *v1; // r8
__int64 v2; // rax
__int64 v3; // r12

if ( !a1 )
_assert_fail("stack != NULL", "src/mt_stack.c", 0x32u, "mt_stack_pop");
v1 = *(__int64 **)a1;
if ( !*(_QWORD *)a1 || (v2 = v1[1], --*(_QWORD *)(a1 + 8), v3 = *v1, *(_QWORD *)a1 = v2, mt_stack_node_free(v1), !v3) )
_assert_fail("data != NULL", "src/mt_stack.c", 0x40u, "mt_stack_pop");
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
__int64 *v1; // r8
__int64 v2; // rax
__int64 v3; // r12

if ( !a1 )
_assert_fail("stack != NULL", "src/mt_stack.c", 0x32u, "mt_stack_pop");
v1 = *(__int64 **)a1;
if ( !*(_QWORD *)a1 || (v2 = v1[1], --*(_QWORD *)(a1 + 8), v3 = *v1, *(_QWORD *)a1 = v2, func0(v1), !v3) )
_assert_fail("data != NULL", "src/mt_stack.c", 0x40u, "mt_stack_pop");
return v3;
}

original_code:
void* mt_stack_pop(MtStack* stack)
{
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/mt_stack.c", 50, __extension__ __PRETTY_FUNCTION__); }));
  MtStackNode* node = stack->head;
  void* data = ((void *)0);
  if (stack->head != ((void *)0))
  {
    stack->size--;
    stack->head = stack->head->next;
    data = node->value;
    mt_stack_node_free(node);
  }
  ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != NULL", "src/mt_stack.c", 64, __extension__ __PRETTY_FUNCTION__); }));
  return data;
}

canonical_original_code:
void *mt_stack_pop(struct MtStack *stack)
{
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/mt_stack.c", 50, __extension__ __PRETTY_FUNCTION__); }));
  struct MtStackNode *node = stack->head;
  void *data = ((void *)0);
  if (stack->head != ((void *)0))
  {
    stack->size--;
    stack->head = stack->head->next;
    data = node->value;
    mt_stack_node_free(node);
  }
  ((void) sizeof ((data != ((void *)0)) ? 1 : 0), __extension__ ({ if (data != ((void *)0)) ; else __assert_fail ("data != NULL", "src/mt_stack.c", 64, __extension__ __PRETTY_FUNCTION__); }));
  return data;
}

variable_types:
data
void *

user_defined_types: struct MtStackNode { void *value; struct MtStackNode *next; }


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

if ( !a1 )
_assert_fail("stack != NULL", "src/mt_stack.c", 0x47u, "mt_stack_top");
result = **a1;
if ( !result )
_assert_fail("stack->head->value != NULL", "src/mt_stack.c", 0x48u, "mt_stack_top");
return result;
}

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

if ( !a1 )
_assert_fail("stack != NULL", "src/mt_stack.c", 0x47u, "mt_stack_top");
result = **a1;
if ( !result )
_assert_fail("stack->head->value != NULL", "src/mt_stack.c", 0x48u, "mt_stack_top");
return result;
}

original_code:
void* mt_stack_top(MtStack* stack)
{
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/mt_stack.c", 71, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((stack->head->value != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack->head->value != ((void *)0)) ; else __assert_fail ("stack->head->value != NULL", "src/mt_stack.c", 72, __extension__ __PRETTY_FUNCTION__); }));
  return stack->head->value;
}

canonical_original_code:
void *mt_stack_top(struct MtStack *stack)
{
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/mt_stack.c", 71, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((stack->head->value != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack->head->value != ((void *)0)) ; else __assert_fail ("stack->head->value != NULL", "src/mt_stack.c", 72, __extension__ __PRETTY_FUNCTION__); }));
  return stack->head->value;
}


decompiled_code:
void __fastcall mt_stack_clear(_QWORD *a1)
{
_QWORD *v1; // rbx
void *v3; // rdi

if ( !a1 )
_assert_fail("stack != NULL", "src/mt_stack.c", 0x4Fu, "mt_stack_clear");
v1 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v3 = v1;
v1 = (_QWORD *)v1[1];
mt_stack_node_free(v3);
}
while ( v1 );
}
*a1 = 0LL;
a1[1] = 0LL;
}

canonical_decompiled_code:
void __fastcall func4(_QWORD *a1)
{
_QWORD *v1; // rbx
void *v3; // rdi

if ( !a1 )
_assert_fail("stack != NULL", "src/mt_stack.c", 0x4Fu, "mt_stack_clear");
v1 = (_QWORD *)*a1;
if ( *a1 )
{
do
{
v3 = v1;
v1 = (_QWORD *)v1[1];
func0(v3);
}
while ( v1 );
}
*a1 = 0LL;
a1[1] = 0LL;
}

original_code:
void mt_stack_clear(MtStack* stack)
{
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/mt_stack.c", 79, __extension__ __PRETTY_FUNCTION__); }));
  MtStackNode* node = stack->head;
  MtStackNode* next;
  while (node != ((void *)0))
  {
    next = node->next;
    mt_stack_node_free(node);
    node = next;
  }
  stack->head = ((void *)0);
  stack->size = 0;
}

canonical_original_code:
void mt_stack_clear(struct MtStack *stack)
{
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/mt_stack.c", 79, __extension__ __PRETTY_FUNCTION__); }));
  struct MtStackNode *node = stack->head;
  struct MtStackNode *next;
  while (node != ((void *)0))
  {
    next = node->next;
    mt_stack_node_free(node);
    node = next;
  }
  stack->head = ((void *)0);
  stack->size = 0;
}


decompiled_code:
void __fastcall mt_stack_free(void *ptr)
{
if ( !ptr )
_assert_fail("stack != NULL", "src/mt_stack.c", 0x60u, "mt_stack_free");
mt_stack_clear(ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func5(void *ptr)
{
if ( !ptr )
_assert_fail("stack != NULL", "src/mt_stack.c", 0x60u, "mt_stack_free");
func4(ptr);
free(ptr);
}

original_code:
void mt_stack_free(MtStack* stack)
{
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/mt_stack.c", 96, __extension__ __PRETTY_FUNCTION__); }));
  mt_stack_clear(stack);
  free(stack);
}

canonical_original_code:
void mt_stack_free(struct MtStack *stack)
{
  ((void) sizeof ((stack != ((void *)0)) ? 1 : 0), __extension__ ({ if (stack != ((void *)0)) ; else __assert_fail ("stack != NULL", "src/mt_stack.c", 96, __extension__ __PRETTY_FUNCTION__); }));
  mt_stack_clear(stack);
  free(stack);
}


decompiled_code:
void __fastcall mt_transition_free(void *a1)
{
if ( !a1 )
_assert_fail("transition != NULL", "src/mt_transition.c", 0x1Fu, "mt_transition_free");
free(a1);
}

canonical_decompiled_code:
void __fastcall func0(void *a1)
{
if ( !a1 )
_assert_fail("transition != NULL", "src/mt_transition.c", 0x1Fu, "mt_transition_free");
free(a1);
}

original_code:
void
mt_transition_free(MtTransition* transition)
{
  ((void) sizeof ((transition != ((void *)0)) ? 1 : 0), __extension__ ({ if (transition != ((void *)0)) ; else __assert_fail ("transition != NULL", "src/mt_transition.c", 31, __extension__ __PRETTY_FUNCTION__); }));
  (free(transition));
}

canonical_original_code:
void mt_transition_free(struct MtTransition *transition)
{
  ((void) sizeof ((transition != ((void *)0)) ? 1 : 0), __extension__ ({ if (transition != ((void *)0)) ; else __assert_fail ("transition != NULL", "src/mt_transition.c", 31, __extension__ __PRETTY_FUNCTION__); }));
  (free(transition));
}

variable_types: struct MtTransition { enum MtTransitionType { MT_TRANSITION_NONE=0, MT_TRANSITION_BEND=1, MT_TRANSITION_SLIDE_UP=2, MT_TRANSITION_SLIDE_DOWN=3, MT_TRANSITION_HAMMER_ON=4, MT_TRANSITION_PULL_OFF=5 } type; struct MtObject { enum MtObjectType { MT_OBJ_NONE=0, MT_OBJ_NOTE=1, MT_OBJ_CHORD=2, MT_OBJ_TRANSITION=3, MT_OBJ_SEQUENCE=4, MT_OBJ_REST=5, MT_OBJ_SYMBOL=6 } type; union asvalue { struct MtNote { enum MtNoteType { MT_NOTE_NONE=0, MT_NOTE_NOTE=1, MT_NOTE_MUTE=2 } type; int string; int fret; enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 } modifier; int size; } *note; struct MtChord { struct MtQueue { int length; struct MtQueueNode { void *value; struct MtQueueNode *next; } *front; struct MtQueueNode *back; } *notes; enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 } modifier; int size; } *chord; struct MtTransition *transition; struct MtSequence { enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 } modifier; struct MtQueue *objects; } *sequence; struct MtSymbol { struct MtString { char *utf8_data; unsigned long size; unsigned long length; unsigned long hash; } *name; enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 } modifier; } *symbol; } as; } *destination; } *

user_defined_types: struct MtTransition { enum MtTransitionType type; struct MtObject *destination; }

user_defined_types: struct MtObject { enum MtObjectType type; union asvalue as; }

user_defined_types: union asvalue { struct MtNote *note; struct MtChord *chord; struct MtTransition *transition; struct MtSequence *sequence; struct MtSymbol *symbol; }

user_defined_types: struct MtNote { enum MtNoteType type; int string; int fret; enum MtModifier modifier; int size; }

user_defined_types: struct MtChord { struct MtQueue *notes; enum MtModifier modifier; int size; }

user_defined_types: struct MtSequence { enum MtModifier modifier; struct MtQueue *objects; }

user_defined_types: struct MtSymbol { struct MtString *name; enum MtModifier modifier; }


decompiled_code:
_DWORD *mt_object_new_rest()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
if ( !result )
_assert_fail("object != NULL", "src/mt_object.c", 0x32u, "mt_object_new_rest");
*result = 5;
return result;
}

canonical_decompiled_code:
_DWORD *func0()
{
_DWORD *result; // rax

result = malloc(0x10uLL);
if ( !result )
_assert_fail("object != NULL", "src/mt_object.c", 0x32u, "mt_object_new_rest");
*result = 5;
return result;
}

original_code:
MtObject* mt_object_new_rest()
{
  MtObject* object = ((MtObject *) malloc(sizeof(MtObject)));
  ((void) sizeof ((object != ((void *)0)) ? 1 : 0), __extension__ ({ if (object != ((void *)0)) ; else __assert_fail ("object != NULL", "src/mt_object.c", 50, __extension__ __PRETTY_FUNCTION__); }));
  object->type = MT_OBJ_REST;
  return object;
}

canonical_original_code:
struct MtObject *mt_object_new_rest()
{
  struct MtObject *object = ((MtObject *) malloc(sizeof(MtObject)));
  ((void) sizeof ((object != ((void *)0)) ? 1 : 0), __extension__ ({ if (object != ((void *)0)) ; else __assert_fail ("object != NULL", "src/mt_object.c", 50, __extension__ __PRETTY_FUNCTION__); }));
  object->type = MT_OBJ_REST;
  return object;
}

variable_types: struct MtObject { enum MtObjectType { MT_OBJ_NONE=0, MT_OBJ_NOTE=1, MT_OBJ_CHORD=2, MT_OBJ_TRANSITION=3, MT_OBJ_SEQUENCE=4, MT_OBJ_REST=5, MT_OBJ_SYMBOL=6 } type; union asvalue { struct MtNote { enum MtNoteType { MT_NOTE_NONE=0, MT_NOTE_NOTE=1, MT_NOTE_MUTE=2 } type; int string; int fret; enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 } modifier; int size; } *note; struct MtChord { struct MtQueue { int length; struct MtQueueNode { void *value; struct MtQueueNode *next; } *front; struct MtQueueNode *back; } *notes; enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 } modifier; int size; } *chord; struct MtTransition { enum MtTransitionType { MT_TRANSITION_NONE=0, MT_TRANSITION_BEND=1, MT_TRANSITION_SLIDE_UP=2, MT_TRANSITION_SLIDE_DOWN=3, MT_TRANSITION_HAMMER_ON=4, MT_TRANSITION_PULL_OFF=5 } type; struct MtObject *destination; } *transition; struct MtSequence { enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 } modifier; struct MtQueue *objects; } *sequence; struct MtSymbol { struct MtString { char *utf8_data; unsigned long size; unsigned long length; unsigned long hash; } *name; enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 } modifier; } *symbol; } as; } *


decompiled_code:
void __fastcall mt_object_free(void *ptr)
{
unsigned int v1; // eax

if ( !ptr )
_assert_fail("object != NULL", "src/mt_object.c", 0x3Bu, "mt_object_free");
v1 = *(_DWORD *)ptr;
if ( *(_DWORD *)ptr == 3 )
{
mt_transition_free(*((_QWORD *)ptr + 1));
free(ptr);
}
else if ( v1 > 3 )
{
if ( v1 != 6 )
goto LABEL_11;
mt_symbol_free(*((_QWORD *)ptr + 1));
free(ptr);
}
else
{
if ( v1 != 1 )
{
if ( v1 == 2 )
{
mt_chord_free(*((_QWORD *)ptr + 1));
free(ptr);
return;
}
LABEL_11:
_assert_fail("false", "src/mt_object.c", 0x51u, "mt_object_free");
}
mt_note_free(*((_QWORD *)ptr + 1));
free(ptr);
}
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
unsigned int v1; // eax

if ( !ptr )
_assert_fail("object != NULL", "src/mt_object.c", 0x3Bu, "mt_object_free");
v1 = *(_DWORD *)ptr;
if ( *(_DWORD *)ptr == 3 )
{
mt_transition_free(*((_QWORD *)ptr + 1));
free(ptr);
}
else if ( v1 > 3 )
{
if ( v1 != 6 )
goto LABEL_11;
mt_symbol_free(*((_QWORD *)ptr + 1));
free(ptr);
}
else
{
if ( v1 != 1 )
{
if ( v1 == 2 )
{
mt_chord_free(*((_QWORD *)ptr + 1));
free(ptr);
return;
}
LABEL_11:
_assert_fail("false", "src/mt_object.c", 0x51u, "mt_object_free");
}
mt_note_free(*((_QWORD *)ptr + 1));
free(ptr);
}
}

original_code:
void mt_object_free(MtObject* object)
{
  ((void) sizeof ((object != ((void *)0)) ? 1 : 0), __extension__ ({ if (object != ((void *)0)) ; else __assert_fail ("object != NULL", "src/mt_object.c", 59, __extension__ __PRETTY_FUNCTION__); }));
  switch (object->type)
  {
    case MT_OBJ_NOTE:
      mt_note_free(object->as.note);
      break;
    case MT_OBJ_CHORD:
      mt_chord_free(object->as.chord);
      break;
    case MT_OBJ_TRANSITION:
      mt_transition_free(object->as.transition);
      break;
    case MT_OBJ_SYMBOL:
      mt_symbol_free(object->as.symbol);
      break;
    default:
      ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("false", "src/mt_object.c", 81, __extension__ __PRETTY_FUNCTION__); }));
      break;
  }
  (free(object));
}

canonical_original_code:
void mt_object_free(struct MtObject *object)
{
  ((void) sizeof ((object != ((void *)0)) ? 1 : 0), __extension__ ({ if (object != ((void *)0)) ; else __assert_fail ("object != NULL", "src/mt_object.c", 59, __extension__ __PRETTY_FUNCTION__); }));
  switch (object->type)
  {
    case MT_OBJ_NOTE:
      mt_note_free(object->as.note);
      break;
    case MT_OBJ_CHORD:
      mt_chord_free(object->as.chord);
      break;
    case MT_OBJ_TRANSITION:
      mt_transition_free(object->as.transition);
      break;
    case MT_OBJ_SYMBOL:
      mt_symbol_free(object->as.symbol);
      break;
    default:
      ((void) sizeof ((0) ? 1 : 0), __extension__ ({ if (0) ; else __assert_fail ("false", "src/mt_object.c", 81, __extension__ __PRETTY_FUNCTION__); }));
      break;
  }
  (free(object));
}

user_defined_types: enum MtObjectType { MT_OBJ_NONE=0, MT_OBJ_NOTE=1, MT_OBJ_CHORD=2, MT_OBJ_TRANSITION=3, MT_OBJ_SEQUENCE=4, MT_OBJ_REST=5, MT_OBJ_SYMBOL=6 }

user_defined_types: enum MtNoteType { MT_NOTE_NONE=0, MT_NOTE_NOTE=1, MT_NOTE_MUTE=2 }

user_defined_types: enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 }

user_defined_types: enum MtTransitionType { MT_TRANSITION_NONE=0, MT_TRANSITION_BEND=1, MT_TRANSITION_SLIDE_UP=2, MT_TRANSITION_SLIDE_DOWN=3, MT_TRANSITION_HAMMER_ON=4, MT_TRANSITION_PULL_OFF=5 }


decompiled_code:
void __fastcall mt_symbol_free(void *ptr)
{
if ( !ptr )
_assert_fail("symbol != NULL", "src/mt_symbol.c", 0x14u, "mt_symbol_free");
mt_string_free(*(_QWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func0(void *ptr)
{
if ( !ptr )
_assert_fail("symbol != NULL", "src/mt_symbol.c", 0x14u, "mt_symbol_free");
mt_string_free(*(_QWORD *)ptr);
free(ptr);
}

original_code:
void mt_symbol_free(MtSymbol* symbol)
{
  ((void) sizeof ((symbol != ((void *)0)) ? 1 : 0), __extension__ ({ if (symbol != ((void *)0)) ; else __assert_fail ("symbol != NULL", "src/mt_symbol.c", 20, __extension__ __PRETTY_FUNCTION__); }));
  mt_string_free(symbol->name);
  (free(symbol));
}

canonical_original_code:
void mt_symbol_free(struct MtSymbol *symbol)
{
  ((void) sizeof ((symbol != ((void *)0)) ? 1 : 0), __extension__ ({ if (symbol != ((void *)0)) ; else __assert_fail ("symbol != NULL", "src/mt_symbol.c", 20, __extension__ __PRETTY_FUNCTION__); }));
  mt_string_free(symbol->name);
  (free(symbol));
}

variable_types: struct MtSymbol { struct MtString { char *utf8_data; unsigned long size; unsigned long length; unsigned long hash; } *name; enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 } modifier; } *


decompiled_code:
void __fastcall mt_sequence_free(void *a1)
{
if ( !a1 )
_assert_fail("sequence != NULL", "src/mt_sequence.c", 0x1Du, "mt_sequence_free");
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(void *a1)
{
if ( !a1 )
_assert_fail("sequence != NULL", "src/mt_sequence.c", 0x1Du, "mt_sequence_free");
free(a1);
}

original_code:
void mt_sequence_free(MtSequence* sequence)
{
  ((void) sizeof ((sequence != ((void *)0)) ? 1 : 0), __extension__ ({ if (sequence != ((void *)0)) ; else __assert_fail ("sequence != NULL", "src/mt_sequence.c", 29, __extension__ __PRETTY_FUNCTION__); }));
  (free(sequence));
}

canonical_original_code:
void mt_sequence_free(struct MtSequence *sequence)
{
  ((void) sizeof ((sequence != ((void *)0)) ? 1 : 0), __extension__ ({ if (sequence != ((void *)0)) ; else __assert_fail ("sequence != NULL", "src/mt_sequence.c", 29, __extension__ __PRETTY_FUNCTION__); }));
  (free(sequence));
}

variable_types: struct MtSequence { enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 } modifier; struct MtQueue { int length; struct MtQueueNode { void *value; struct MtQueueNode *next; } *front; struct MtQueueNode *back; } *objects; } *


decompiled_code:
void __fastcall mt_note_set_modifier(__int64 a1, int a2)
{
if ( !a1 )
_assert_fail("note != NULL", "src/mt_note.c", 0x4Au, "mt_note_set_modifier");
*(_DWORD *)(a1 + 12) = a2;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
if ( !a1 )
_assert_fail("note != NULL", "src/mt_note.c", 0x4Au, "mt_note_set_modifier");
*(_DWORD *)(a1 + 12) = a2;
}

original_code:
void mt_note_set_modifier(MtNote* note, MtModifier modifier)
{
  ((void) sizeof ((note != ((void *)0)) ? 1 : 0), __extension__ ({ if (note != ((void *)0)) ; else __assert_fail ("note != NULL", "src/mt_note.c", 74, __extension__ __PRETTY_FUNCTION__); }));
  note->modifier = modifier;
}

canonical_original_code:
void mt_note_set_modifier(struct MtNote *note, enum MtModifier modifier)
{
  ((void) sizeof ((note != ((void *)0)) ? 1 : 0), __extension__ ({ if (note != ((void *)0)) ; else __assert_fail ("note != NULL", "src/mt_note.c", 74, __extension__ __PRETTY_FUNCTION__); }));
  note->modifier = modifier;
}

variable_types: struct MtNote { enum MtNoteType { MT_NOTE_NONE=0, MT_NOTE_NOTE=1, MT_NOTE_MUTE=2 } type; int string; int fret; enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 } modifier; int size; } *


decompiled_code:
__int64 __fastcall mt_note_set_fret(_DWORD *a1, int a2)
{
__int64 result; // rax
__m128d v3; // xmm0
__m128d v4; // xmm4

if ( !a1 )
_assert_fail("note != NULL", "src/mt_note.c", 0x50u, "mt_note_set_fret");
if ( *a1 )
_assert_fail("note->type == MT_NOTE_NONE", "src/mt_note.c", 0x51u, "mt_note_set_fret");
*a1 = 1;
result = 1LL;
a1[2] = a2;
if ( a2 )
{
v3.m128d_f64[0] = log10(COERCE_DOUBLE(COERCE_UNSIGNED_INT64((double)a2) & LC4));
if ( COERCE_DOUBLE(*(_QWORD *)&v3.m128d_f64[0] & LC4) < 4.503599627370496e15 )
{
v4.m128d_f64[0] = (double)(int)v3.m128d_f64[0];
result = (unsigned int)(int)(COERCE_DOUBLE(COERCE_UNSIGNED_INT64(
v4.m128d_f64[0]
- COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v4, v3) & LC6)) | ~LC4 & *(_QWORD *)&v3.m128d_f64[0])
+ 1.0);
}
else
{
result = (unsigned int)(int)(v3.m128d_f64[0] + 1.0);
}
a1[4] = result;
}
else
{
a1[4] = 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1, int a2)
{
__int64 result; // rax
__m128d v3; // xmm0
__m128d v4; // xmm4

if ( !a1 )
_assert_fail("note != NULL", "src/mt_note.c", 0x50u, "mt_note_set_fret");
if ( *a1 )
_assert_fail("note->type == MT_NOTE_NONE", "src/mt_note.c", 0x51u, "mt_note_set_fret");
*a1 = 1;
result = 1LL;
a1[2] = a2;
if ( a2 )
{
v3.m128d_f64[0] = log10(COERCE_DOUBLE(COERCE_UNSIGNED_INT64((double)a2) & LC4));
if ( COERCE_DOUBLE(*(_QWORD *)&v3.m128d_f64[0] & LC4) < 4.503599627370496e15 )
{
v4.m128d_f64[0] = (double)(int)v3.m128d_f64[0];
result = (unsigned int)(int)(COERCE_DOUBLE(COERCE_UNSIGNED_INT64(
v4.m128d_f64[0]
- COERCE_DOUBLE(*(_OWORD *)&_mm_cmpgt_sd(v4, v3) & LC6)) | ~LC4 & *(_QWORD *)&v3.m128d_f64[0])
+ 1.0);
}
else
{
result = (unsigned int)(int)(v3.m128d_f64[0] + 1.0);
}
a1[4] = result;
}
else
{
a1[4] = 1;
}
return result;
}

original_code:
void mt_note_set_fret(MtNote* note, int fret)
{
  ((void) sizeof ((note != ((void *)0)) ? 1 : 0), __extension__ ({ if (note != ((void *)0)) ; else __assert_fail ("note != NULL", "src/mt_note.c", 80, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((note->type == MT_NOTE_NONE) ? 1 : 0), __extension__ ({ if (note->type == MT_NOTE_NONE) ; else __assert_fail ("note->type == MT_NOTE_NONE", "src/mt_note.c", 81, __extension__ __PRETTY_FUNCTION__); }));
  note->type = MT_NOTE_NOTE;
  note->fret = fret;
  note->size = (fret == 0) ? 1 : (int) (floor(log10(fabs(fret))) + 1);
}

canonical_original_code:
void mt_note_set_fret(struct MtNote *note, int fret)
{
  ((void) sizeof ((note != ((void *)0)) ? 1 : 0), __extension__ ({ if (note != ((void *)0)) ; else __assert_fail ("note != NULL", "src/mt_note.c", 80, __extension__ __PRETTY_FUNCTION__); }));
  ((void) sizeof ((note->type == MT_NOTE_NONE) ? 1 : 0), __extension__ ({ if (note->type == MT_NOTE_NONE) ; else __assert_fail ("note->type == MT_NOTE_NONE", "src/mt_note.c", 81, __extension__ __PRETTY_FUNCTION__); }));
  note->type = MT_NOTE_NOTE;
  note->fret = fret;
  note->size = (fret == 0) ? 1 : (int) (floor(log10(fabs(fret))) + 1);
}

variable_types: fret int


decompiled_code:
void __fastcall mt_note_free(void *a1)
{
if ( !a1 )
_assert_fail("note != NULL", "src/mt_note.c", 0x63u, "mt_note_free");
free(a1);
}

canonical_decompiled_code:
void __fastcall func3(void *a1)
{
if ( !a1 )
_assert_fail("note != NULL", "src/mt_note.c", 0x63u, "mt_note_free");
free(a1);
}

original_code:
void mt_note_free(MtNote* note)
{
  ((void) sizeof ((note != ((void *)0)) ? 1 : 0), __extension__ ({ if (note != ((void *)0)) ; else __assert_fail ("note != NULL", "src/mt_note.c", 99, __extension__ __PRETTY_FUNCTION__); }));
  (free(note));
}

canonical_original_code:
void mt_note_free(struct MtNote *note)
{
  ((void) sizeof ((note != ((void *)0)) ? 1 : 0), __extension__ ({ if (note != ((void *)0)) ; else __assert_fail ("note != NULL", "src/mt_note.c", 99, __extension__ __PRETTY_FUNCTION__); }));
  (free(note));
}


decompiled_code:
void __fastcall mt_chord_set_modifier(__int64 a1, int a2)
{
if ( !a1 )
_assert_fail("chord != NULL", "src/mt_chord.c", 0x21u, "mt_chord_set_modifier");
*(_DWORD *)(a1 + 8) = a2;
}

canonical_decompiled_code:
void __fastcall func0(__int64 a1, int a2)
{
if ( !a1 )
_assert_fail("chord != NULL", "src/mt_chord.c", 0x21u, "mt_chord_set_modifier");
*(_DWORD *)(a1 + 8) = a2;
}

original_code:
void mt_chord_set_modifier(MtChord* chord, MtModifier modifier)
{
  ((void) sizeof ((chord != ((void *)0)) ? 1 : 0), __extension__ ({ if (chord != ((void *)0)) ; else __assert_fail ("chord != NULL", "src/mt_chord.c", 33, __extension__ __PRETTY_FUNCTION__); }));
  chord->modifier = modifier;
}

canonical_original_code:
void mt_chord_set_modifier(struct MtChord *chord, enum MtModifier modifier)
{
  ((void) sizeof ((chord != ((void *)0)) ? 1 : 0), __extension__ ({ if (chord != ((void *)0)) ; else __assert_fail ("chord != NULL", "src/mt_chord.c", 33, __extension__ __PRETTY_FUNCTION__); }));
  chord->modifier = modifier;
}

variable_types: struct MtChord { struct MtQueue { int length; struct MtQueueNode { void *value; struct MtQueueNode *next; } *front; struct MtQueueNode *back; } *notes; enum MtModifier { MT_MODIFIER_NONE=0, MT_MODIFIER_PALM_MUTE=1, MT_MODIFIER_HARMONIC=2, MT_MODIFIER_VIBRATO=3 } modifier; int size; } *


decompiled_code:
void __fastcall mt_chord_free(void *ptr)
{
if ( !ptr )
_assert_fail("chord != NULL", "src/mt_chord.c", 0x27u, "mt_chord_free");
mt_queue_free(*(_QWORD *)ptr);
free(ptr);
}

canonical_decompiled_code:
void __fastcall func1(void *ptr)
{
if ( !ptr )
_assert_fail("chord != NULL", "src/mt_chord.c", 0x27u, "mt_chord_free");
mt_queue_free(*(_QWORD *)ptr);
free(ptr);
}

original_code:
void mt_chord_free(MtChord* chord)
{
  ((void) sizeof ((chord != ((void *)0)) ? 1 : 0), __extension__ ({ if (chord != ((void *)0)) ; else __assert_fail ("chord != NULL", "src/mt_chord.c", 39, __extension__ __PRETTY_FUNCTION__); }));
  mt_queue_free(chord->notes);
  (free(chord));
}

canonical_original_code:
void mt_chord_free(struct MtChord *chord)
{
  ((void) sizeof ((chord != ((void *)0)) ? 1 : 0), __extension__ ({ if (chord != ((void *)0)) ; else __assert_fail ("chord != NULL", "src/mt_chord.c", 39, __extension__ __PRETTY_FUNCTION__); }));
  mt_queue_free(chord->notes);
  (free(chord));
}


main

canonical_name: main

repo: cknadler/questions

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rbp
int result; // eax
char *v5; // r13
char *v6; // r12

v3 = fopen("test.txt", "r");
result = 1;
if ( v3 )
{
v5 = (char *)malloc(0x100uLL);
v6 = (char *)malloc(0x100uLL);
__isoc99_fscanf();
__isoc99_fscanf();
fclose(v3);
if ( (unsigned __int8)anagram(v5, v6) )
printf("%s is an anagram of %s\n", v5, v6);
else
printf("%s is not an anagram of %s\n", v5, v6);
free(v5);
free(v6);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rbp
int result; // eax
char *v5; // r13
char *v6; // r12

v3 = fopen("test.txt", "r");
result = 1;
if ( v3 )
{
v5 = (char *)malloc(0x100uLL);
v6 = (char *)malloc(0x100uLL);
__isoc99_fscanf();
__isoc99_fscanf();
fclose(v3);
if ( (unsigned __int8)func7(v5, v6) )
printf("%s is an anagram of %s\n", v5, v6);
else
printf("%s is not an anagram of %s\n", v5, v6);
free(v5);
free(v6);
result = 0;
}
return result;
}

original_code:
int main()
{
  int an_int = 1;
  char* ptr = (char*) &an_int;
  if (((int) *ptr) == 1)
    printf("The system is little endian\n");
  else
    printf("The system is big endian\n");
  return 0;
}

canonical_original_code:
int main()
{
  int an_int = 1;
  char *ptr = (char*) &an_int;
  if (((int) *ptr) == 1)
    printf("The system is little endian\n");
  else
    printf("The system is big endian\n");
  return 0;
}

variable_types:
ptr
char *

return_type: int


anagram

decompiled_code:
__int64 __fastcall anagram(const char *a1, const char *a2)
{
const char *v2; // rbx
int v3; // er12
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
__int64 v8; // rdx
int v10[262]; // [rsp+0h] [rbp-418h] BYREF

v2 = a1;
v3 = strlen(a1);
if ( v3 != strlen(a2) )
return 0LL;
memset(v10, 0, 0x400uLL);
if ( v3 > 0 )
{
v5 = (unsigned int)(v3 - 1);
do
{
v6 = *a1++;
++v10[v6];
}
while ( a1 != &v2[v5 + 1] );
v7 = (__int64)&a2[v5 + 1];
while ( 1 )
{
v8 = *a2;
if ( --v10[v8] < 0 )
break;
if ( (const char *)v7 == ++a2 )
return 1LL;
}
return 0LL;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func7(const char *a1, const char *a2)
{
const char *v2; // rbx
int v3; // er12
__int64 v5; // rcx
__int64 v6; // rax
__int64 v7; // rcx
__int64 v8; // rdx
int v10[262]; // [rsp+0h] [rbp-418h] BYREF

v2 = a1;
v3 = strlen(a1);
if ( v3 != strlen(a2) )
return 0LL;
memset(v10, 0, 0x400uLL);
if ( v3 > 0 )
{
v5 = (unsigned int)(v3 - 1);
do
{
v6 = *a1++;
++v10[v6];
}
while ( a1 != &v2[v5 + 1] );
v7 = (__int64)&a2[v5 + 1];
while ( 1 )
{
v8 = *a2;
if ( --v10[v8] < 0 )
break;
if ( (const char *)v7 == ++a2 )
return 1LL;
}
return 0LL;
}
return 1LL;
}

original_code:
_Bool anagram(char* string1, char* string2)
{
  int length = strlen(string1);
  if (length != strlen(string2))
    return 0;
  int ascii_table[256];
  memset(ascii_table, 0, sizeof(ascii_table));
  int i;
  for (i = 0; i < length; ++i)
    ++ascii_table[string1[i]];
  for (i = 0; i < length; ++i)
  {
    --ascii_table[string2[i]];
    if (ascii_table[string2[i]] < 0)
      return 0;
  }
  return 1;
}

canonical_original_code:
_Bool anagram(char *string1, char *string2)
{
  int length = strlen(string1);
  if (length != strlen(string2))
    return 0;
  int ascii_table[256];
  memset(ascii_table, 0, sizeof(ascii_table));
  int i;
  for (i = 0; i < length; ++i)
    ++ascii_table[string1[i]];
  for (i = 0; i < length; ++i)
  {
    --ascii_table[string2[i]];
    if (ascii_table[string2[i]] < 0)
      return 0;
  }
  return 1;
}

variable_types: length int

variable_types: i int


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rbp
int result; // eax
char *v5; // r12

v3 = fopen("test.txt", "r");
result = 1;
if ( v3 )
{
v5 = (char *)malloc(0x100uLL);
__isoc99_fscanf();
fclose(v3);
reverse(v5);
puts(v5);
free(v5);
result = 0;
}
return result;
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
FILE *v3; // rbp
int result; // eax
char *v5; // r12

v3 = fopen("test.txt", "r");
result = 1;
if ( v3 )
{
v5 = (char *)malloc(0x100uLL);
__isoc99_fscanf();
fclose(v3);
func7(v5);
puts(v5);
free(v5);
result = 0;
}
return result;
}


reverse

decompiled_code:
char *__fastcall reverse(char *dest)
{
__int64 v1; // rax
char *v2; // rdx
char v3; // cl
char v5[264]; // [rsp+0h] [rbp-108h] BYREF

LODWORD(v1) = strlen(dest) - 1;
if ( (int)v1 >= 0 )
{
v1 = (int)v1;
v2 = v5;
do
{
v3 = dest[v1--];
*v2++ = v3;
}
while ( (int)v1 >= 0 );
}
return strcpy(dest, v5);
}

canonical_decompiled_code:
char *__fastcall func7(char *dest)
{
__int64 v1; // rax
char *v2; // rdx
char v3; // cl
char v5[264]; // [rsp+0h] [rbp-108h] BYREF

LODWORD(v1) = strlen(dest) - 1;
if ( (int)v1 >= 0 )
{
v1 = (int)v1;
v2 = v5;
do
{
v3 = dest[v1--];
*v2++ = v3;
}
while ( (int)v1 >= 0 );
}
return strcpy(dest, v5);
}

original_code:
void reverse(char* string)
{
  char back[256];
  int i, length = strlen(string) - 1;
  for(i = length; i >= 0; i--)
    back[length - i] = string[i];
  strcpy(string, back);
}

canonical_original_code:
void reverse(char *string)
{
  char back[256];
  int i; int length = strlen(string) - 1;
  for(i = length; i >= 0; i--)
    back[length - i] = string[i];
  strcpy(string, back);
}

variable_types:
string
char *

variable_types:
back
char [256]


main

repo: cksystemsgroup/libscm

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // er12
time_t v5; // r13
__int64 v6; // rbx
__int64 v7; // r14
time_t v8; // rax
__int64 v9; // rdx
FILE *v10; // rdi
int v11; // eax
__int64 v13; // rbp
double v14; // [rsp+8h] [rbp-30h]

v3 = getPagefault(argc, argv, envp);
setbuf(_bss_start, 0LL);
if ( argc > 1 )
{
fin = fopen(argv[1], "r");
if ( argc != 2 )
{
fout = fopen(argv[2], "w");
goto LABEL_4;
}
}
else
{
fin = (FILE *)stdin;
}
fout = _bss_start;
LABEL_4:
if ( !fin || !fout )
{
v13 = 0LL;
fwrite("Could not open file(s): ", 1uLL, 0x18uLL, stderr);
while ( argc > (int)++v13 )
fprintf(stderr, "%s ", argv[v13]);
fputc(10, stderr);
exit(-1);
}
ulCallCount = promptAndRead_constprop_0(ulCallCount);
uMinBlockSize = promptAndRead_constprop_0((unsigned int)uMinBlockSize);
uMaxBlockSize = promptAndRead_constprop_0((unsigned int)uMaxBlockSize);
v4 = clock();
v5 = time(0LL);
v6 = rdtsc(0LL);
doBench();
v7 = rdtsc(0LL) - v6;
v8 = time(0LL);
v14 = difftime(v8, v5);
LODWORD(v6) = clock();
fputc(10, fout);
fprintf(
fout,
"\nTotal elapsed time: %.2f (%.4f CPU) (%ld clock ticks read from register)\n",
v14,
(double)((int)v6 - v4) / 1000000.0,
v7);
if ( fin != (FILE *)stdin )
fclose(fin);
v10 = fout;
if ( fout != _bss_start )
fclose(fout);
v11 = getPagefault(v10, "\nTotal elapsed time: %.2f (%.4f CPU) (%ld clock ticks read from register)\n", v9);
return printf("Occurred page faults: %d\n", (unsigned int)(v11 - v3));
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
int v3; // ebp
int v4; // er12
time_t v5; // r13
__int64 v6; // rbx
__int64 v7; // r14
time_t v8; // rax
__int64 v9; // rdx
FILE *v10; // rdi
int v11; // eax
__int64 v13; // rbp
double v14; // [rsp+8h] [rbp-30h]

v3 = func9(argc, argv, envp);
setbuf(_bss_start, 0LL);
if ( argc > 1 )
{
fin = fopen(argv[1], "r");
if ( argc != 2 )
{
fout = fopen(argv[2], "w");
goto LABEL_4;
}
}
else
{
fin = (FILE *)stdin;
}
fout = _bss_start;
LABEL_4:
if ( !fin || !fout )
{
v13 = 0LL;
fwrite("Could not open file(s): ", 1uLL, 0x18uLL, stderr);
while ( argc > (int)++v13 )
fprintf(stderr, "%s ", argv[v13]);
fputc(10, stderr);
exit(-1);
}
ulCallCount = func8(ulCallCount);
uMinBlockSize = func8((unsigned int)uMinBlockSize);
uMaxBlockSize = func8((unsigned int)uMaxBlockSize);
v4 = clock();
v5 = time(0LL);
v6 = func7(0LL);
func10();
v7 = func7(0LL) - v6;
v8 = time(0LL);
v14 = difftime(v8, v5);
LODWORD(v6) = clock();
fputc(10, fout);
fprintf(
fout,
"\nTotal elapsed time: %.2f (%.4f CPU) (%ld clock ticks read from register)\n",
v14,
(double)((int)v6 - v4) / 1000000.0,
v7);
if ( fin != (FILE *)stdin )
fclose(fin);
v10 = fout;
if ( fout != _bss_start )
fclose(fout);
v11 = func9(v10, "\nTotal elapsed time: %.2f (%.4f CPU) (%ld clock ticks read from register)\n", v9);
return printf("Occurred page faults: %d\n", (unsigned int)(v11 - v3));
}

original_code:
void main(int argc, char *argv[])
{
 clock_t startCPU;
 time_t startTime;
 double elapsedTime, cpuTime;
 uint64_t clock_reg;
 int pf0 = getPagefault();
 setbuf(stdout, ((void *)0));
 if (argc > 1)
  fin = fopen(argv[1], "r");
 else
  fin = stdin;
 if (argc > 2)
  fout = fopen(argv[2], "w");
 else
  fout = stdout;
 if(fin == ((void *)0) || fout == ((void *)0)) {
  fprintf(stderr, "Could not open file(s): ");
  int i=1;
  for(i=1; i<argc;i++) {
   fprintf(stderr, "%s ", argv[i]);
  }
  fprintf(stderr, "\n");
  exit(-1);
 }
 ulCallCount = promptAndRead("call count", ulCallCount, 'u');
 uMinBlockSize = (unsigned)promptAndRead("min block size",uMinBlockSize,'u');
 uMaxBlockSize = (unsigned)promptAndRead("max block size",uMaxBlockSize,'u');
        0;
 startCPU = clock();
 startTime = time(((void *)0));
 clock_reg = rdtsc();
 doBench(((void *)0));
 uint64_t cpuTime_reg = (rdtsc() - clock_reg);
 elapsedTime = difftime(time(((void *)0)), startTime);
 cpuTime = (double)(clock()-startCPU) / (double)((__clock_t) 1000000);
 fprintf(fout, "\n");
 fprintf(fout, "\nTotal elapsed time"
   ": %.2f (%.4f CPU) (%ld clock ticks read from register)\n",
   elapsedTime, cpuTime, cpuTime_reg);
 if (fin != stdin)
  fclose(fin);
 if (fout != stdout)
  fclose(fout);
 printf("Occurred page faults: %d\n", getPagefault() - pf0);
}

canonical_original_code:
void main(int argc, char *argv[])
{
 long startCPU;
 long startTime;
 double elapsedTime; double cpuTime;
 unsigned long clock_reg;
 int pf0 = getPagefault();
 setbuf(stdout, ((void *)0));
 if (argc > 1)
  fin = fopen(argv[1], "r");
 else
  fin = stdin;
 if (argc > 2)
  fout = fopen(argv[2], "w");
 else
  fout = stdout;
 if(fin == ((void *)0) || fout == ((void *)0)) {
  fprintf(stderr, "Could not open file(s): ");
  int i = 1;
  for(i=1; i<argc;i++) {
   fprintf(stderr, "%s ", argv[i]);
  }
  fprintf(stderr, "\n");
  exit(-1);
 }
 ulCallCount = promptAndRead("call count", ulCallCount, 'u');
 uMinBlockSize = (unsigned int)promptAndRead("min block size",uMinBlockSize,'u');
 uMaxBlockSize = (unsigned int)promptAndRead("max block size",uMaxBlockSize,'u');
        0;
 startCPU = clock();
 startTime = time(((void *)0));
 clock_reg = rdtsc();
 doBench(((void *)0));
 unsigned long cpuTime_reg = (rdtsc() - clock_reg);
 elapsedTime = difftime(time(((void *)0)), startTime);
 cpuTime = (double)(clock()-startCPU) / (double)((long) 1000000);
 fprintf(fout, "\n");
 fprintf(fout, "\nTotal elapsed time"
   ": %.2f (%.4f CPU) (%ld clock ticks read from register)\n",
   elapsedTime, cpuTime, cpuTime_reg);
 if (fin != stdin)
  fclose(fin);
 if (fout != stdout)
  fclose(fout);
 printf("Occurred page faults: %d\n", getPagefault() - pf0);
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: startCPU long

variable_types: startTime long

variable_types: elapsedTime double

variable_types: cpuTime double


promptAndRead

decompiled_code:
__int64 __fastcall promptAndRead(__int64 a1, __int64 a2)
{
return a2;
}

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

original_code:
unsigned long promptAndRead(char *msg, unsigned long defaultVal, char fmtCh)
{
 return defaultVal;
}

variable_types:
msg
char *

variable_types:
defaultVal
unsigned long

variable_types: fmtCh char


decompiled_code:
_QWORD *new_descriptor_page()
{
__int64 v0; // rax
__int64 v1; // rdx
_QWORD *result; // rax

v0 = *(_QWORD *)_tls_get_addr(&descriptor_root_tlsind);
v1 = *(_QWORD *)(v0 + 4728);
if ( v1 )
{
*(_QWORD *)(v0 + 4728) = v1 - 1;
result = *(_QWORD **)(v0 + 8 * v1 + 4640);
LABEL_3:
result[1] = 0LL;
*result = 0LL;
return result;
}
result = (_QWORD *)_real_malloc(4096LL);
if ( result )
goto LABEL_3;
return result;
}

canonical_decompiled_code:
_QWORD *func0()
{
__int64 v0; // rax
__int64 v1; // rdx
_QWORD *result; // rax

v0 = *(_QWORD *)_tls_get_addr(&descriptor_root_tlsind);
v1 = *(_QWORD *)(v0 + 4728);
if ( v1 )
{
*(_QWORD *)(v0 + 4728) = v1 - 1;
result = *(_QWORD **)(v0 + 8 * v1 + 4640);
LABEL_3:
result[1] = 0LL;
*result = 0LL;
return result;
}
result = (_QWORD *)_real_malloc(4096LL);
if ( result )
goto LABEL_3;
return result;
}

original_code:
static descriptor_page_t *new_descriptor_page() {
    descriptor_page_t *new_page = ((void *)0);
    if (descriptor_root->number_of_pooled_descriptor_pages > 0) {
        descriptor_root->number_of_pooled_descriptor_pages--;
        new_page = descriptor_root->descriptor_page_pool
                   [descriptor_root->number_of_pooled_descriptor_pages];
    } else {
        new_page = __real_malloc(4096);
        if (!new_page) {
            return ((void *)0);
        }
    }
    new_page->number_of_descriptors = 0;
    new_page->next = ((void *)0);
    return new_page;
}

canonical_original_code:
static struct descriptor_page *new_descriptor_page() {
    struct descriptor_page *new_page = ((void *)0);
    if (descriptor_root->number_of_pooled_descriptor_pages > 0) {
        descriptor_root->number_of_pooled_descriptor_pages--;
        new_page = descriptor_root->descriptor_page_pool
                   [descriptor_root->number_of_pooled_descriptor_pages];
    } else {
        new_page = __real_malloc(4096);
        if (!new_page) {
            return ((void *)0);
        }
    }
    new_page->number_of_descriptors = 0;
    new_page->next = ((void *)0);
    return new_page;
}

variable_types: struct descriptor_page { struct descriptor_page *next; unsigned long number_of_descriptors; struct object_header { int dc_or_region_id; int finalizer_index; } *descriptors[-1]; } *

user_defined_types: struct descriptor_page { struct descriptor_page *next; unsigned long number_of_descriptors; struct object_header *descriptors[-1]; }


decompiled_code:
__int64 __fastcall recycle_descriptor_page(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdx
unsigned __int64 v3; // rax
__int64 result; // rax

v1 = _tls_get_addr(&descriptor_root_tlsind);
v2 = *(_QWORD *)v1;
v3 = *(_QWORD *)(*(_QWORD *)v1 + 4728LL);
if ( v3 > 9 )
return _real_free(a1);
*(_QWORD *)(v2 + 8 * v3 + 4648) = a1;
result = v3 + 1;
*(_QWORD *)(v2 + 4728) = result;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // rax
__int64 v2; // rdx
unsigned __int64 v3; // rax
__int64 result; // rax

v1 = _tls_get_addr(&descriptor_root_tlsind);
v2 = *(_QWORD *)v1;
v3 = *(_QWORD *)(*(_QWORD *)v1 + 4728LL);
if ( v3 > 9 )
return _real_free(a1);
*(_QWORD *)(v2 + 8 * v3 + 4648) = a1;
result = v3 + 1;
*(_QWORD *)(v2 + 4728) = result;
return result;
}

original_code:
static inline void recycle_descriptor_page(descriptor_page_t *page) {
    if (descriptor_root->number_of_pooled_descriptor_pages <
            10) {
        descriptor_root->descriptor_page_pool[descriptor_root->number_of_pooled_descriptor_pages] = page;
        descriptor_root->number_of_pooled_descriptor_pages++;
    } else {
        __real_free(page);
    }
}

canonical_original_code:
static inline void recycle_descriptor_page(struct descriptor_page *page) {
    if (descriptor_root->number_of_pooled_descriptor_pages <
            10) {
        descriptor_root->descriptor_page_pool[descriptor_root->number_of_pooled_descriptor_pages] = page;
        descriptor_root->number_of_pooled_descriptor_pages++;
    } else {
        __real_free(page);
    }
}

user_defined_types: struct object_header { int dc_or_region_id; int finalizer_index; }


original_code:
static void recycle_region(region_t* region) {
    region_page_t* legacy_pages;
    unsigned long number_of_recycle_region_pages;
    if (region->age == descriptor_root->current_time) {
        region_page_t* firstPage = region->firstPage;
        legacy_pages = firstPage->nextPage;
        memset(firstPage, '\0', 4096);
        region->last_address_in_last_page =
                firstPage->memory + (4096 - sizeof(region_page_t*));
        if (legacy_pages == ((void *)0)) {
            region->dc = 0;
            return;
        }
        number_of_recycle_region_pages =
            region->number_of_region_pages - 1;
    }
    else {
        legacy_pages = region->firstPage;
        if (legacy_pages == ((void *)0)) {
            region->dc = 0;
            return;
        }
        number_of_recycle_region_pages =
            region->number_of_region_pages;
    }
    unsigned long number_of_pooled_region_pages =
        descriptor_root->number_of_pooled_region_pages;
    if ((number_of_pooled_region_pages
            + number_of_recycle_region_pages) <=
            10) {
        region_page_t* first_in_pool = descriptor_root->region_page_pool;
        region_page_t* last_page = region->lastPage;
        last_page->nextPage = first_in_pool;
        descriptor_root->region_page_pool = legacy_pages;
        descriptor_root->number_of_pooled_region_pages =
            number_of_pooled_region_pages + number_of_recycle_region_pages;
    } else {
        region_page_t* page2free = legacy_pages;
        while (page2free != ((void *)0) && (number_of_pooled_region_pages
                + number_of_recycle_region_pages) >
                10) {
            region_page_t* next = page2free->nextPage;
            __real_free(page2free);
            page2free = next;
            number_of_recycle_region_pages--;
        }
        if (page2free != ((void *)0) && (number_of_pooled_region_pages
                + number_of_recycle_region_pages) <=
                10) {
            region_page_t* first_in_pool = descriptor_root->region_page_pool;
            region_page_t* last_page = region->lastPage;
            if(last_page != ((void *)0)) {
                last_page->nextPage = first_in_pool;
                descriptor_root->region_page_pool = page2free;
                descriptor_root->number_of_pooled_region_pages =
                        number_of_recycle_region_pages - 1;
            }
        }
        descriptor_root->number_of_pooled_region_pages =
                number_of_pooled_region_pages + number_of_recycle_region_pages;
    }
    region->number_of_region_pages = 1;
    region->lastPage = region->firstPage;
    region->last_address_in_last_page =
            region->lastPage->memory + (4096 - sizeof(region_page_t*));
    region->next_free_address = region->lastPage->memory;
    if (region->age != descriptor_root->current_time) {
        region->number_of_region_pages = 0;
        region->lastPage = region->firstPage = ((void *)0);
    }
}

canonical_original_code:
static void recycle_region(struct region *region) {
    struct region_page *legacy_pages;
    unsigned long number_of_recycle_region_pages;
    if (region->age == descriptor_root->current_time) {
        struct region_page *firstPage = region->firstPage;
        legacy_pages = firstPage->nextPage;
        memset(firstPage, '\0', 4096);
        region->last_address_in_last_page =
                firstPage->memory + (4096 - sizeof(struct region_page *));
        if (legacy_pages == ((void *)0)) {
            region->dc = 0;
            return;
        }
        number_of_recycle_region_pages =
            region->number_of_region_pages - 1;
    }
    else {
        legacy_pages = region->firstPage;
        if (legacy_pages == ((void *)0)) {
            region->dc = 0;
            return;
        }
        number_of_recycle_region_pages =
            region->number_of_region_pages;
    }
    unsigned long number_of_pooled_region_pages = descriptor_root->number_of_pooled_region_pages;
    if ((number_of_pooled_region_pages
            + number_of_recycle_region_pages) <=
            10) {
        struct region_page *first_in_pool = descriptor_root->region_page_pool;
        struct region_page *last_page = region->lastPage;
        last_page->nextPage = first_in_pool;
        descriptor_root->region_page_pool = legacy_pages;
        descriptor_root->number_of_pooled_region_pages =
            number_of_pooled_region_pages + number_of_recycle_region_pages;
    } else {
        struct region_page *page2free = legacy_pages;
        while (page2free != ((void *)0) && (number_of_pooled_region_pages
                + number_of_recycle_region_pages) >
                10) {
            struct region_page *next = page2free->nextPage;
            __real_free(page2free);
            page2free = next;
            number_of_recycle_region_pages--;
        }
        if (page2free != ((void *)0) && (number_of_pooled_region_pages
                + number_of_recycle_region_pages) <=
                10) {
            struct region_page *first_in_pool = descriptor_root->region_page_pool;
            struct region_page *last_page = region->lastPage;
            if(last_page != ((void *)0)) {
                last_page->nextPage = first_in_pool;
                descriptor_root->region_page_pool = page2free;
                descriptor_root->number_of_pooled_region_pages =
                        number_of_recycle_region_pages - 1;
            }
        }
        descriptor_root->number_of_pooled_region_pages =
                number_of_pooled_region_pages + number_of_recycle_region_pages;
    }
    region->number_of_region_pages = 1;
    region->lastPage = region->firstPage;
    region->last_address_in_last_page =
            region->lastPage->memory + (4096 - sizeof(struct region_page *));
    region->next_free_address = region->lastPage->memory;
    if (region->age != descriptor_root->current_time) {
        region->number_of_region_pages = 0;
        region->lastPage = region->firstPage = ((void *)0);
    }
}

variable_types: struct region { unsigned int dc; unsigned int number_of_region_pages; struct region_page { struct region_page *nextPage; char memory[-1]; } *firstPage; struct region_page *lastPage; unsigned int age; void *next_free_address; void *last_address_in_last_page; } *

user_defined_types: struct region { unsigned int dc; unsigned int number_of_region_pages; struct region_page *firstPage; struct region_page *lastPage; unsigned int age; void *next_free_address; void *last_address_in_last_page; }


original_code:
void expire_buffer(descriptor_buffer_t *buffer,
                   expired_descriptor_page_list_t *exp_list) {
    int to_be_expired_index = buffer->current_index - 1;
    if (to_be_expired_index < 0)
        to_be_expired_index += buffer->not_expired_length;
    descriptor_page_list_t *just_expired_page_list = &buffer->not_expired[to_be_expired_index];
    if (just_expired_page_list->first != ((void *)0)) {
        if (just_expired_page_list->first->number_of_descriptors != 0) {
            if (exp_list->first == ((void *)0)) {
                exp_list->first = just_expired_page_list->first;
                exp_list->last = just_expired_page_list->last;
                exp_list->collected = 0;
            } else {
                exp_list->last->next = just_expired_page_list->first;
                exp_list->last = just_expired_page_list->last;
            }
            just_expired_page_list->first = ((void *)0);
            just_expired_page_list->last = just_expired_page_list->first;
        } else {
        }
    } else {
    }
}

canonical_original_code:
void expire_buffer(struct descriptor_buffer *buffer, struct expired_descriptor_page_list *exp_list) {
    int to_be_expired_index = buffer->current_index - 1;
    if (to_be_expired_index < 0)
        to_be_expired_index += buffer->not_expired_length;
    struct descriptor_page_list *just_expired_page_list = &buffer->not_expired[to_be_expired_index];
    if (just_expired_page_list->first != ((void *)0)) {
        if (just_expired_page_list->first->number_of_descriptors != 0) {
            if (exp_list->first == ((void *)0)) {
                exp_list->first = just_expired_page_list->first;
                exp_list->last = just_expired_page_list->last;
                exp_list->collected = 0;
            } else {
                exp_list->last->next = just_expired_page_list->first;
                exp_list->last = just_expired_page_list->last;
            }
            just_expired_page_list->first = ((void *)0);
            just_expired_page_list->last = just_expired_page_list->first;
        } else {
        }
    } else {
    }
}

variable_types: struct descriptor_buffer { struct descriptor_page_list { struct descriptor_page { struct descriptor_page *next; unsigned long number_of_descriptors; struct object_header { int dc_or_region_id; int finalizer_index; } *descriptors[-1]; } *first; struct descriptor_page *last; } not_expired[-1]; unsigned int not_expired_length; unsigned int current_index; unsigned int age; } *

variable_types: struct expired_descriptor_page_list { struct descriptor_page *first; struct descriptor_page *last; unsigned long collected; } *

variable_types: struct descriptor_page_list { struct descriptor_page { struct descriptor_page *next; unsigned long number_of_descriptors; struct object_header { int dc_or_region_id; int finalizer_index; } *descriptors[-1]; } *first; struct descriptor_page *last; } *

user_defined_types: struct descriptor_buffer { struct descriptor_page_list not_expired[-1]; unsigned int not_expired_length; unsigned int current_index; unsigned int age; }

user_defined_types: struct descriptor_page_list { struct descriptor_page *first; struct descriptor_page *last; }


decompiled_code:
__int64 __fastcall expire_object_descriptor_if_exists(__int64 a1)
{
unsigned int v1; // er12
volatile signed __int32 *v2; // rax
volatile signed __int32 *v3; // rbp

v1 = 0;
v2 = (volatile signed __int32 *)get_expired_memory(a1);
if ( v2 )
{
v3 = v2;
v1 = atomic_int_exchange_and_add_constprop_0(v2);
if ( v1 != 1 || (unsigned int)run_finalizer() )
v1 = 1;
else
_real_free(v3);
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
unsigned int v1; // er12
volatile signed __int32 *v2; // rax
volatile signed __int32 *v3; // rbp

v1 = 0;
v2 = (volatile signed __int32 *)get_expired_memory(a1);
if ( v2 )
{
v3 = v2;
v1 = func3(v2);
if ( v1 != 1 || (unsigned int)run_finalizer() )
v1 = 1;
else
_real_free(v3);
}
return v1;
}

original_code:
int expire_object_descriptor_if_exists(expired_descriptor_page_list_t *list) {
    object_header_t *expired_object = (object_header_t*) get_expired_memory(list);
    if (expired_object != ((void *)0)) {
        if ((atomic_int_exchange_and_add(((int*) &expired_object->dc_or_region_id), -1) == 1)) {
            int finalizer_result = run_finalizer(expired_object);
            if (finalizer_result != 0) {
                return 1;
            }
            __real_free(expired_object);
            return 1;
        } else {
            return 1;
        }
    } else {
        return 0;
    }
}

canonical_original_code:
int expire_object_descriptor_if_exists(struct expired_descriptor_page_list *list) {
    struct object_header *expired_object = (object_header_t*) get_expired_memory(list);
    if (expired_object != ((void *)0)) {
        if ((atomic_int_exchange_and_add(((int *) &expired_object->dc_or_region_id), -1) == 1)) {
            int finalizer_result = run_finalizer(expired_object);
            if (finalizer_result != 0) {
                return 1;
            }
            __real_free(expired_object);
            return 1;
        } else {
            return 1;
        }
    } else {
        return 0;
    }
}

variable_types: struct expired_descriptor_page_list { struct descriptor_page { struct descriptor_page *next; unsigned long number_of_descriptors; struct object_header { int dc_or_region_id; int finalizer_index; } *descriptors[-1]; } *first; struct descriptor_page *last; unsigned long collected; } *

user_defined_types: struct expired_descriptor_page_list { struct descriptor_page *first; struct descriptor_page *last; unsigned long collected; }


decompiled_code:
__int64 __fastcall expire_region_descriptor_if_exists(__int64 a1)
{
volatile signed __int32 *v1; // rdi
__int64 result; // rax

v1 = (volatile signed __int32 *)get_expired_memory(a1);
result = 0LL;
if ( v1 )
{
if ( (unsigned int)atomic_int_exchange_and_add_constprop_0(v1) == 1 )
{
recycle_region((__int64)v1);
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
volatile signed __int32 *v1; // rdi
__int64 result; // rax

v1 = (volatile signed __int32 *)get_expired_memory(a1);
result = 0LL;
if ( v1 )
{
if ( (unsigned int)func3(v1) == 1 )
{
func2((__int64)v1);
result = 1LL;
}
else
{
result = 1LL;
}
}
return result;
}

original_code:
int expire_region_descriptor_if_exists(expired_descriptor_page_list_t *list) {
    region_t* expired_region = (region_t*) get_expired_memory(list);
    if (expired_region != ((void *)0)) {
        if ((atomic_int_exchange_and_add(((volatile int*) &expired_region->dc), -1) == 1)) {
            recycle_region(expired_region);
        }
        return 1;
    } else {
        return 0;
    }
}

canonical_original_code:
int expire_region_descriptor_if_exists(struct expired_descriptor_page_list *list) {
    struct region *expired_region = (region_t*) get_expired_memory(list);
    if (expired_region != ((void *)0)) {
        if ((atomic_int_exchange_and_add(((int *) &expired_region->dc), -1) == 1)) {
            recycle_region(expired_region);
        }
        return 1;
    } else {
        return 0;
    }
}

user_defined_types: struct region_page { struct region_page *nextPage; char memory[-1]; }


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

result = atomic_int_exchange_and_add_constprop_0();
if ( (int)result > 31 )
return 0xFFFFFFFFLL;
finalizer_table[(int)result] = a1;
return result;
}

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

result = func0();
if ( (int)result > 31 )
return 0xFFFFFFFFLL;
finalizer_table[(int)result] = a1;
return result;
}

original_code:
int scm_register_finalizer(int(*scm_finalizer)(void*)) {
    int index = atomic_int_exchange_and_add(&finalizer_index, 1);
    if (index >= 32) return -1;
    finalizer_table[index] = scm_finalizer;
    return index;
}

canonical_original_code:
int scm_register_finalizer(int (*scm_finalizer)(void *)) {
    int index = atomic_int_exchange_and_add(&finalizer_index, 1);
    if (index >= 32) return -1;
    finalizer_table[index] = scm_finalizer;
    return index;
}

variable_types: index int


decompiled_code:
void __fastcall scm_set_finalizer(__int64 a1, int a2)
{
*(_DWORD *)(a1 - 4) = a2;
}

canonical_decompiled_code:
void __fastcall func2(__int64 a1, int a2)
{
*(_DWORD *)(a1 - 4) = a2;
}

original_code:
void scm_set_finalizer(void *ptr, int scm_finalizer_id) {
    object_header_t *o = (object_header_t*)(ptr - sizeof(object_header_t));
    o->finalizer_index = scm_finalizer_id;
}

canonical_original_code:
void scm_set_finalizer(void *ptr, int scm_finalizer_id) {
    struct object_header *o = (object_header_t*)(ptr - sizeof(object_header_t));
    o->finalizer_index = scm_finalizer_id;
}

variable_types:
ptr
void *

variable_types: struct object_header { int dc_or_region_id; int finalizer_index; } *


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

v1 = *(int *)(a1 + 4);
if ( (_DWORD)v1 == -1 )
result = 0LL;
else
result = ((__int64 (__fastcall *)(__int64))finalizer_table[v1])(a1 + 8);
return result;
}

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

v1 = *(int *)(a1 + 4);
if ( (_DWORD)v1 == -1 )
result = 0LL;
else
result = ((__int64 (__fastcall *)(__int64))finalizer_table[v1])(a1 + 8);
return result;
}

original_code:
int run_finalizer(object_header_t *o) {
    if (o->finalizer_index == -1) return 0;
    void *ptr = ((void*)(o) + sizeof(object_header_t));
    int (*finalizer)(void*);
    finalizer = finalizer_table[o->finalizer_index];
    return (*finalizer)(ptr);
}

canonical_original_code:
int run_finalizer(struct object_header *o) {
    if (o->finalizer_index == -1) return 0;
    void *ptr = ((void*)(o) + sizeof(object_header_t));
    int (*finalizer)(void *);
    finalizer = finalizer_table[o->finalizer_index];
    return (*finalizer)(ptr);
}

variable_types:
finalizer
int (*)(void *)


repo: clarkgrubb/data-tools

decompiled_code:
__int64 __fastcall push_stack(__int64 *a1, char a2)
{
__int64 result; // rax
unsigned __int64 v5; // rcx
unsigned __int64 v6; // rdx
void *v7; // rdi
size_t v8; // rsi
void *v9; // rax

result = *a1;
v5 = a1[1];
v6 = *a1 + 1;
*a1 = v6;
v7 = (void *)a1[2];
if ( v6 > v5 )
{
v8 = 2 * v5 + 1;
a1[1] = v8;
v9 = realloc(v7, v8);
a1[2] = (__int64)v9;
v7 = v9;
result = *a1 - 1;
}
*((_BYTE *)v7 + result) = a2;
return result;
}

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

result = *a1;
v5 = a1[1];
v6 = *a1 + 1;
*a1 = v6;
v7 = (void *)a1[2];
if ( v6 > v5 )
{
v8 = 2 * v5 + 1;
a1[1] = v8;
v9 = realloc(v7, v8);
a1[2] = (__int64)v9;
v7 = v9;
result = *a1 - 1;
}
*((_BYTE *)v7 + result) = a2;
return result;
}

original_code:
void
push_stack(json_type_stack *stack, json_type val) {
  stack->size += 1;
  if (stack->size > stack->capacity) {
    stack->capacity = 2 * (stack->capacity) + 1;
    stack->data = (json_type *)realloc(stack->data, stack->capacity);
  }
  stack->data[stack->size - 1] = val;
}

canonical_original_code:
void push_stack(struct json_type_stack *stack, _Bool val) {
  stack->size += 1;
  if (stack->size > stack->capacity) {
    stack->capacity = 2 * (stack->capacity) + 1;
    stack->data = (_Bool *)realloc(stack->data, stack->capacity);
  }
  stack->data[stack->size - 1] = val;
}

variable_types: struct json_type_stack { unsigned long size; unsigned long capacity; _Bool *data; } *


decompiled_code:
__int64 __fastcall peek_stack(_QWORD *a1)
{
if ( !*a1 )
{
fwrite("ERROR: stack underflow", 1uLL, 0x16uLL, stderr);
exit(1);
}
return *(unsigned __int8 *)(a1[2] + *a1 - 1LL);
}

canonical_decompiled_code:
__int64 __fastcall func10(_QWORD *a1)
{
if ( !*a1 )
{
fwrite("ERROR: stack underflow", 1uLL, 0x16uLL, stderr);
exit(1);
}
return *(unsigned __int8 *)(a1[2] + *a1 - 1LL);
}

original_code:
json_type
peek_stack(json_type_stack *stack) {
  if (stack->size == 0) {
    fprintf(stderr, "ERROR: stack underflow");
    exit(1);
  }
  return stack->data[stack->size - 1];
}

canonical_original_code:
_Bool peek_stack(struct json_type_stack *stack) {
  if (stack->size == 0) {
    fprintf(stderr, "ERROR: stack underflow");
    exit(1);
  }
  return stack->data[stack->size - 1];
}

user_defined_types: struct json_type_stack { unsigned long size; unsigned long capacity; _Bool *data; }


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

result = peek_stack(a1);
--*a1;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1)
{
__int64 result; // rax

result = func10(a1);
--*a1;
return result;
}

original_code:
json_type
pop_stack(json_type_stack *stack) {
  json_type retval = peek_stack(stack);
  stack->size -= 1;
  return retval;
}

canonical_original_code:
_Bool pop_stack(struct json_type_stack *stack) {
  _Bool retval = peek_stack(stack);
  stack->size -= 1;
  return retval;
}


decompiled_code:
__int64 json_pluck()
{
__int64 v0; // r14
int v1; // er13
__int64 v2; // r12
char v3; // bp
char v4; // bl
unsigned int i; // eax
__int64 v7[9]; // [rsp+0h] [rbp-48h] BYREF

v0 = 1LL;
v1 = 0;
v2 = 0LL;
v3 = 0;
v4 = 0;
init_stack(v7);
LABEL_2:
for ( i = getwchar(); i != -1; i = getwchar() )
{
++v2;
if ( i > 0x2C )
{
switch ( i )
{
case '[':
if ( v4 )
{
v3 = 0;
putwchar(91);
}
else
{
push_stack(v7, JSON_TYPE_ARRAY);
if ( v1 )
putwchar(91);
++v1;
v3 = 0;
}
goto LABEL_2;
case '\\':
if ( !v4 )
fatal("backslash outside of string", v0, v2);
v3 ^= 1u;
putwchar(92);
goto LABEL_2;
case ']':
if ( v4 || (--v1, pop_stack(v7), v1 > 0) )
{
v3 = 0;
putwchar(93);
}
else
{
if ( v1 == -1 )
fatal("unmatched right square bracket", v0, v2);
v3 = 0;
v1 = 0;
}
goto LABEL_2;
case '{':
if ( !v4 )
push_stack(v7, JSON_TYPE_OBJECT);
v3 = 0;
putwchar(123);
goto LABEL_2;
case '}':
if ( !v4 )
pop_stack(v7);
v3 = 0;
putwchar(125);
goto LABEL_2;
default:
goto LABEL_5;
}
}
if ( i > 8 )
{
switch ( i )
{
case 9u:
if ( v4 )
fatal("tab in string", v0, v2);
v3 = 0;
goto LABEL_2;
case 0xAu:
if ( v4 )
fatal("newline in string", v0, v2);
++v0;
v3 = 0;
v2 = 0LL;
goto LABEL_2;
case 0x20u:
v3 = 0;
if ( v4 )
putwchar(32);
goto LABEL_2;
case 0x22u:
putwchar(34);
v4 = v3 | v4 ^ 1;
v3 = 0;
goto LABEL_2;
case 0x2Cu:
if ( v4 )
goto LABEL_12;
if ( !v1 )
fatal("unexpected comma", v0, v2);
if ( v1 == 1 && (unsigned __int8)peek_stack(v7) == JSON_TYPE_ARRAY )
{
v3 = 0;
putwchar(10);
}
else
{
LABEL_12:
v3 = 0;
putwchar(44);
}
goto LABEL_2;
default:
break;
}
}
LABEL_5:
v3 = 0;
putwchar(i);
}
if ( v1 )
fatal("more left brackets than right brackets", v0 - 1, v2);
putwchar(10);
return 0LL;
}

canonical_decompiled_code:
__int64 func12()
{
__int64 v0; // r14
int v1; // er13
__int64 v2; // r12
char v3; // bp
char v4; // bl
unsigned int i; // eax
__int64 v7[9]; // [rsp+0h] [rbp-48h] BYREF

v0 = 1LL;
v1 = 0;
v2 = 0LL;
v3 = 0;
v4 = 0;
func8(v7);
LABEL_2:
for ( i = getwchar(); i != -1; i = getwchar() )
{
++v2;
if ( i > 0x2C )
{
switch ( i )
{
case '[':
if ( v4 )
{
v3 = 0;
putwchar(91);
}
else
{
func9(v7, JSON_TYPE_ARRAY);
if ( v1 )
putwchar(91);
++v1;
v3 = 0;
}
goto LABEL_2;
case '\\':
if ( !v4 )
func7("backslash outside of string", v0, v2);
v3 ^= 1u;
putwchar(92);
goto LABEL_2;
case ']':
if ( v4 || (--v1, func11(v7), v1 > 0) )
{
v3 = 0;
putwchar(93);
}
else
{
if ( v1 == -1 )
func7("unmatched right square bracket", v0, v2);
v3 = 0;
v1 = 0;
}
goto LABEL_2;
case '{':
if ( !v4 )
func9(v7, JSON_TYPE_OBJECT);
v3 = 0;
putwchar(123);
goto LABEL_2;
case '}':
if ( !v4 )
func11(v7);
v3 = 0;
putwchar(125);
goto LABEL_2;
default:
goto LABEL_5;
}
}
if ( i > 8 )
{
switch ( i )
{
case 9u:
if ( v4 )
func7("tab in string", v0, v2);
v3 = 0;
goto LABEL_2;
case 0xAu:
if ( v4 )
func7("newline in string", v0, v2);
++v0;
v3 = 0;
v2 = 0LL;
goto LABEL_2;
case 0x20u:
v3 = 0;
if ( v4 )
putwchar(32);
goto LABEL_2;
case 0x22u:
putwchar(34);
v4 = v3 | v4 ^ 1;
v3 = 0;
goto LABEL_2;
case 0x2Cu:
if ( v4 )
goto LABEL_12;
if ( !v1 )
func7("unexpected comma", v0, v2);
if ( v1 == 1 && (unsigned __int8)func10(v7) == JSON_TYPE_ARRAY )
{
v3 = 0;
putwchar(10);
}
else
{
LABEL_12:
v3 = 0;
putwchar(44);
}
goto LABEL_2;
default:
break;
}
}
LABEL_5:
v3 = 0;
putwchar(i);
}
if ( v1 )
func7("more left brackets than right brackets", v0 - 1, v2);
putwchar(10);
return 0LL;
}

original_code:
int
json_pluck() {
  wint_t ch;
  size_t lineno = 1, offsetno = 0;
  int array_depth = 0;
  _Bool inside_string = 0;
  _Bool after_backslash = 0;
  json_type_stack stack;
  init_stack(&stack);
  while ((ch = getwchar()) != (0xffffffffu)) {
    offsetno += 1;
    switch (ch) {
    case L'[':
      if (inside_string) {
        putwchar(ch);
      }
      else {
        push_stack(&stack, JSON_TYPE_ARRAY);
        if (array_depth > 0) {
          putwchar(ch);
        }
        array_depth += 1;
      }
      after_backslash = 0;
      break;
    case L']':
      if (inside_string) {
        putwchar(ch);
      }
      else {
        pop_stack(&stack);
        array_depth -= 1;
        if (array_depth > 0) {
          putwchar(ch);
        }
        if (array_depth < 0) {
          fatal("unmatched right square bracket", lineno, offsetno);
        }
      }
      after_backslash = 0;
      break;
    case L'{':
      if (!inside_string) {
        push_stack(&stack, JSON_TYPE_OBJECT);
      }
      putwchar(ch);
      after_backslash = 0;
      break;
    case L'}':
      if (!inside_string) {
        pop_stack(&stack);
      }
      putwchar(ch);
      after_backslash = 0;
      break;
    case ',':
      if (inside_string) {
        putwchar(ch);
      }
      else {
        if (array_depth == 0) {
          fatal("unexpected comma", lineno, offsetno);
        }
        else if (array_depth == 1) {
          if (peek_stack(&stack) == JSON_TYPE_ARRAY) {
            putwchar(L'\n');
          }
          else {
            putwchar(ch);
          }
        }
        else {
          putwchar(ch);
        }
      }
      after_backslash = 0;
      break;
    case L'"':
      if (inside_string) {
        if (after_backslash) {
          inside_string = 1;
          after_backslash = 0;
        }
        else {
          inside_string = 0;
        }
      }
      else {
        inside_string = 1;
      }
      putwchar(ch);
      after_backslash = 0;
      break;
    case L'\\':
      if (inside_string) {
        after_backslash = !after_backslash;
      }
      else {
        fatal("backslash outside of string", lineno, offsetno);
      }
      putwchar(ch);
      break;
    case L' ':
      if (inside_string) {
        putwchar(ch);
      }
      after_backslash = 0;
      break;
    case L'\t':
      if (inside_string) {
        fatal("tab in string", lineno, offsetno);
      }
      after_backslash = 0;
      break;
    case L'\n':;
      if (inside_string) {
        fatal("newline in string", lineno, offsetno);
      }
      lineno += 1;
      offsetno = 0;
      after_backslash = 0;
      break;
    default:
      putwchar(ch);
      after_backslash = 0;
      break;
    }
  }
  if (array_depth != 0) {
    fatal("more left brackets than right brackets", lineno - 1, offsetno);
  }
  putwchar(L'\n');
  return 0;
}

canonical_original_code:
int json_pluck() {
  unsigned int ch;
  unsigned long lineno = 1; unsigned long offsetno = 0;
  int array_depth = 0;
  _Bool inside_string = 0;
  _Bool after_backslash = 0;
  struct json_type_stack stack;
  init_stack(&stack);
  while ((ch = getwchar()) != (0xffffffffu)) {
    offsetno += 1;
    switch (ch) {
    case L'[':
      if (inside_string) {
        putwchar(ch);
      }
      else {
        push_stack(&stack, JSON_TYPE_ARRAY);
        if (array_depth > 0) {
          putwchar(ch);
        }
        array_depth += 1;
      }
      after_backslash = 0;
      break;
    case L']':
      if (inside_string) {
        putwchar(ch);
      }
      else {
        pop_stack(&stack);
        array_depth -= 1;
        if (array_depth > 0) {
          putwchar(ch);
        }
        if (array_depth < 0) {
          fatal("unmatched right square bracket", lineno, offsetno);
        }
      }
      after_backslash = 0;
      break;
    case L'{':
      if (!inside_string) {
        push_stack(&stack, JSON_TYPE_OBJECT);
      }
      putwchar(ch);
      after_backslash = 0;
      break;
    case L'}':
      if (!inside_string) {
        pop_stack(&stack);
      }
      putwchar(ch);
      after_backslash = 0;
      break;
    case ',':
      if (inside_string) {
        putwchar(ch);
      }
      else {
        if (array_depth == 0) {
          fatal("unexpected comma", lineno, offsetno);
        }
        else if (array_depth == 1) {
          if (peek_stack(&stack) == JSON_TYPE_ARRAY) {
            putwchar(L'\n');
          }
          else {
            putwchar(ch);
          }
        }
        else {
          putwchar(ch);
        }
      }
      after_backslash = 0;
      break;
    case L'"':
      if (inside_string) {
        if (after_backslash) {
          inside_string = 1;
          after_backslash = 0;
        }
        else {
          inside_string = 0;
        }
      }
      else {
        inside_string = 1;
      }
      putwchar(ch);
      after_backslash = 0;
      break;
    case L'\\':
      if (inside_string) {
        after_backslash = !after_backslash;
      }
      else {
        fatal("backslash outside of string", lineno, offsetno);
      }
      putwchar(ch);
      break;
    case L' ':
      if (inside_string) {
        putwchar(ch);
      }
      after_backslash = 0;
      break;
    case L'\t':
      if (inside_string) {
        fatal("tab in string", lineno, offsetno);
      }
      after_backslash = 0;
      break;
    case L'\n':;
      if (inside_string) {
        fatal("newline in string", lineno, offsetno);
      }
      lineno += 1;
      offsetno = 0;
      after_backslash = 0;
      break;
    default:
      putwchar(ch);
      after_backslash = 0;
      break;
    }
  }
  if (array_depth != 0) {
    fatal("more left brackets than right brackets", lineno - 1, offsetno);
  }
  putwchar(L'\n');
  return 0;
}

variable_types:
ch
unsigned int

variable_types:
lineno
unsigned long

variable_types:
offsetno
unsigned long

variable_types: struct json_type_stack { unsigned long size; unsigned long capacity; _Bool *data; }


main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
setlocale(6, "");
return json_pluck();
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
setlocale(6, "");
return func12();
}

original_code:
int
main(int argc, char **argv) {
  setlocale(6, "");
  return json_pluck();
}

variable_types: argc int

variable_types:
argv
char **


fatal

decompiled_code:
void __fastcall __noreturn fatal(const char *a1, __int64 a2, __int64 a3)
{
fprintf(stderr, "ERROR: line: %lu: offset: %lu: %s\n", a2, a3, a1);
exit(1);
}

canonical_decompiled_code:
void __fastcall __noreturn func7(const char *a1, __int64 a2, __int64 a3)
{
fprintf(stderr, "ERROR: line: %lu: offset: %lu: %s\n", a2, a3, a1);
exit(1);
}

original_code:
void
fatal(char *msg, size_t lineno, size_t offsetno) {
  fprintf(stderr, "ERROR: line: %lu: offset: %lu: %s\n",
          lineno, offsetno, msg);
  exit(1);
}

canonical_original_code:
void fatal(char *msg, unsigned long lineno, unsigned long offsetno) {
  fprintf(stderr, "ERROR: line: %lu: offset: %lu: %s\n",
          lineno, offsetno, msg);
  exit(1);
}

variable_types:
msg
char *