decompiled_code:
__int64 __fastcall complex_algo_next_token(__int64 a1)
{
unsigned __int8 *v2; // r12
__int64 v3; // rdi
__int64 v4; // rsi

v2 = *(unsigned __int8 **)(a1 + 672);
v3 = *v2;
if ( !(_BYTE)v3 )
return 0LL;
if ( (_BYTE)v3 == 10 )
return 1LL;
if ( *(int *)(a1 + 272) >= 0 )
return chinese_token((const __m128i *)a1);
v4 = utf8_char_len(v3);
if ( v4 != 1 )
{
if ( !dict_search_word_info(v2, v4) )
return one_unicode_token_isra_0(*(unsigned __int8 **)(a1 + 672));
return chinese_token((const __m128i *)a1);
}
return latin_token(*(char **)(a1 + 672));
}

canonical_decompiled_code:
__int64 __fastcall func6(__int64 a1)
{
unsigned __int8 *v2; // r12
__int64 v3; // rdi
__int64 v4; // rsi

v2 = *(unsigned __int8 **)(a1 + 672);
v3 = *v2;
if ( !(_BYTE)v3 )
return 0LL;
if ( (_BYTE)v3 == 10 )
return 1LL;
if ( *(int *)(a1 + 272) >= 0 )
return func4((const __m128i *)a1);
v4 = utf8_char_len(v3);
if ( v4 != 1 )
{
if ( !dict_search_word_info(v2, v4) )
return func5(*(unsigned __int8 **)(a1 + 672));
return func4((const __m128i *)a1);
}
return func2(*(char **)(a1 + 672));
}

original_code:
static size_t
complex_algo_next_token(algor_t* al)
{
    const char* text = al->target_string;
    if(!text[0])
        return 0;
    if(text[0] == '\n')
        return 1;
    if(al->current_token_pos >= 0)
        return chinese_token(al);
    size_t len = utf8_char_len(text[0]);
    if(len == 1)
        return latin_token(al->target_string);
    if(dict_search_word_info(text, len))
        return chinese_token(al);
    else
        return one_unicode_token(al);
}

canonical_original_code:
static unsigned long complex_algo_next_token(struct _algor_t *al)
{
    char *text = al->target_string;
    if(!text[0])
        return 0;
    if(text[0] == '\n')
        return 1;
    if(al->current_token_pos >= 0)
        return chinese_token(al);
    unsigned long len = utf8_char_len(text[0]);
    if(len == 1)
        return latin_token(al->target_string);
    if(dict_search_word_info(text, len))
        return chinese_token(al);
    else
        return one_unicode_token(al);
}

variable_types:
len
unsigned long


repo: mikeandmore/segc

decompiled_code:
void __fastcall algor_destroy(void *ptr)
{
_QWORD *v1; // r12
char *v2; // rbp
__int64 *v3; // rbx
__int64 v4; // rdi

v1 = ptr;
v2 = (char *)ptr + 256;
v3 = (__int64 *)ptr;
do
{
v4 = *v3++;
chunk_free(v4);
}
while ( v3 != (__int64 *)v2 );
chunk_free(v1[85]);
free(v1);
}

canonical_decompiled_code:
void __fastcall func7(void *ptr)
{
_QWORD *v1; // r12
char *v2; // rbp
__int64 *v3; // rbx
__int64 v4; // rdi

v1 = ptr;
v2 = (char *)ptr + 256;
v3 = (__int64 *)ptr;
do
{
v4 = *v3++;
chunk_free(v4);
}
while ( v3 != (__int64 *)v2 );
chunk_free(v1[85]);
free(v1);
}

original_code:
void
algor_destroy(algor_t* al)
{
    int i;
    for(i = 0; i < 32; i++)
        chunk_free(al->current_chunks[i]);
    chunk_free(al->temp_chunk);
    free(al);
}

canonical_original_code:
void algor_destroy(struct _algor_t *al)
{
    int i;
    for(i = 0; i < 32; i++)
        chunk_free(al->current_chunks[i]);
    chunk_free(al->temp_chunk);
    free(al);
}

variable_types: struct _algor_t { struct _chunk_t { char w[3][64]; struct _word_info_t { unsigned char nbytes; unsigned char length; int freq; } *winfo[3]; unsigned long n; } *current_chunks[32]; unsigned long current_chunks_size; struct _chunk_t *current_chunk; int current_token_pos; struct _cache_t { struct _word_info_t *content[4]; unsigned long size; char *pos_key; } match_cache[8]; unsigned long current_cache_pos; char *target_string; struct _chunk_t *temp_chunk; } *

variable_types: i int

return_type: void

user_defined_types: struct _algor_t { struct _chunk_t *current_chunks[32]; unsigned long current_chunks_size; struct _chunk_t *current_chunk; int current_token_pos; struct _cache_t match_cache[8]; unsigned long current_cache_pos; char *target_string; struct _chunk_t *temp_chunk; }

user_defined_types: struct _chunk_t { char w[3][64]; struct _word_info_t *winfo[3]; unsigned long n; }


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

result = complex_algo_next_token(a1);
*(_QWORD *)(a1 + 672) += result;
return result;
}

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

result = func6(a1);
*(_QWORD *)(a1 + 672) += result;
return result;
}

original_code:
size_t
algor_get_next_token(algor_t* al)
{
    size_t tok = complex_algo_next_token(al);
    al->target_string += tok;
    return tok;
}

canonical_original_code:
unsigned long algor_get_next_token(struct _algor_t *al)
{
    unsigned long tok = complex_algo_next_token(al);
    al->target_string += tok;
    return tok;
}

variable_types:
tok
unsigned long

return_type: unsigned long

user_defined_types: struct _cache_t { struct _word_info_t *content[4]; unsigned long size; char *pos_key; }

user_defined_types: struct _word_info_t { unsigned char nbytes; unsigned char length; int freq; }


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

result = 2LL;
if ( (unsigned __int8)(a1 + 64) > 0x1Fu )
{
result = 3LL;
if ( (unsigned __int8)(a1 + 32) > 0xFu )
result = a1 != 0;
}
return result;
}

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

result = 2LL;
if ( (unsigned __int8)(a1 + 64) > 0x1Fu )
{
result = 3LL;
if ( (unsigned __int8)(a1 + 32) > 0xFu )
result = a1 != 0;
}
return result;
}

original_code:
size_t
utf8_char_len(unsigned char ch)
{
    if(ch >= 0xC0 && ch <= 0xDF)
        return 2;
    if(ch >= 0xE0 && ch <= 0xEF)
        return 3;
    if(ch == 0)
        return 0;
    return 1;
}

canonical_original_code:
unsigned long utf8_char_len(unsigned char ch)
{
    if(ch >= 0xC0 && ch <= 0xDF)
        return 2;
    if(ch >= 0xE0 && ch <= 0xEF)
        return 3;
    if(ch == 0)
        return 0;
    return 1;
}

variable_types:
ch
unsigned char


decompiled_code:
__int64 __fastcall utf8_len(char *a1)
{
char v1; // di
__int64 i; // r8
__int64 v3; // rax
__int64 v4; // rcx

v1 = *a1;
for ( i = 0LL; v1; v1 = *(_BYTE *)(v3 + v4) )
v3 = utf8_char_len(v1);
return i;
}

canonical_decompiled_code:
__int64 __fastcall func1(char *a1)
{
char v1; // di
__int64 i; // r8
__int64 v3; // rax
__int64 v4; // rcx

v1 = *a1;
for ( i = 0LL; v1; v1 = *(_BYTE *)(v3 + v4) )
v3 = func0(v1);
return i;
}

original_code:
size_t
utf8_len(const char* text)
{
    size_t len = 0;
    while(1)
    {
        char ch = (*text);
        if(ch == 0)
            break;
        text += utf8_char_len(ch);
        len++;
    }
    return len;
}

canonical_original_code:
unsigned long utf8_len(char *text)
{
    unsigned long len = 0;
    while(1)
    {
        char ch = (*text);
        if(ch == 0)
            break;
        text += utf8_char_len(ch);
        len++;
    }
    return len;
}

variable_types:
text
char *

variable_types: ch char


decompiled_code:
__int64 __fastcall make_word_info(char *a1, int a2)
{
char v2; // r12
__int64 v3; // rax
char v4; // al
__int64 v5; // r9

v2 = strlen(a1);
v3 = pool_alloc(8LL);
*(_BYTE *)v3 = v2;
*(_DWORD *)(v3 + 4) = a2;
v4 = utf8_len(a1);
*(_BYTE *)(v5 + 1) = v4;
return v5;
}

canonical_decompiled_code:
__int64 __fastcall func2(char *a1, int a2)
{
char v2; // r12
__int64 v3; // rax
char v4; // al
__int64 v5; // r9

v2 = strlen(a1);
v3 = pool_alloc(8LL);
*(_BYTE *)v3 = v2;
*(_DWORD *)(v3 + 4) = a2;
v4 = func1(a1);
*(_BYTE *)(v5 + 1) = v4;
return v5;
}

original_code:
word_info_t*
make_word_info(const char* text,
               int freq)
{
    size_t len = strlen(text);
    word_info_t* w = pool_alloc(sizeof(word_info_t));
    w->nbytes = len;
    w->freq = freq;
    w->length = utf8_len(text);
    return w;
}

canonical_original_code:
struct _word_info_t *make_word_info(char *text, int freq)
{
    unsigned long len = strlen(text);
    struct _word_info_t *w = pool_alloc(sizeof(word_info_t));
    w->nbytes = len;
    w->freq = freq;
    w->length = utf8_len(text);
    return w;
}

variable_types: freq int

variable_types: struct _word_info_t { unsigned char nbytes; unsigned char length; int freq; } *


decompiled_code:
__int64 __fastcall is_chinese_punc(char *s1)
{
const char *v1; // rsi
void **i; // rbx

v1 = (const char *)&unk_EB;
for ( i = &off_128; ; ++i )
{
if ( !strcmp(s1, v1) )
return 1LL;
if ( i == (void **)&unk_170 )
break;
v1 = (const char *)*i;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func3(char *s1)
{
const char *v1; // rsi
void **i; // rbx

v1 = (const char *)&unk_EB;
for ( i = &off_128; ; ++i )
{
if ( !strcmp(s1, v1) )
return 1LL;
if ( i == (void **)&unk_170 )
break;
v1 = (const char *)*i;
}
return 0LL;
}

original_code:
int
is_chinese_punc(char* text)
{
    static char* ch_punc[] = {"，", "。", "：", "“", "”", "；", "-", "、", "《", "》"};
    static size_t ch_punc_size = sizeof(ch_punc) / sizeof(char*);
    int i;
    for(i = 0; i < ch_punc_size; i++)
        if(strcmp(text, ch_punc[i]) == 0)
            return 1;
    return 0;
}

canonical_original_code:
int is_chinese_punc(char *text)
{
    static char *ch_punc[] = {"，", "。", "：", "“", "”", "；", "-", "、", "《", "》"};
    static unsigned long ch_punc_size = sizeof(ch_punc) / sizeof(char*);
    int i;
    for(i = 0; i < ch_punc_size; i++)
        if(strcmp(text, ch_punc[i]) == 0)
            return 1;
    return 0;
}

return_type: int


decompiled_code:
__int64 dict_init()
{
__int64 result; // rax

result = hash_table_new();
root = result;
return result;
}

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

result = hash_table_new();
root = result;
return result;
}

original_code:
void
dict_init(void)
{
    root = hash_table_new();
}

canonical_original_code:
void dict_init()
{
    root = hash_table_new();
}


decompiled_code:
__int64 dict_deinit()
{
__int64 result; // rax

result = hash_table_destroy(root);
root = 0LL;
return result;
}

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

result = hash_table_destroy(root);
root = 0LL;
return result;
}

original_code:
void
dict_deinit(void)
{
    hash_table_destroy(root);
    root = ((void *)0);
}

canonical_original_code:
void dict_deinit()
{
    hash_table_destroy(root);
    root = ((void *)0);
}


decompiled_code:
__int64 __fastcall dict_search_word_info(__int64 a1, __int64 a2)
{
return hash_table_search(root, a1, a2);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, __int64 a2)
{
return hash_table_search(root, a1, a2);
}

original_code:
word_info_t*
dict_search_word_info(const char* text,
                      size_t tsize)
{
    word_info_t* ret = (word_info_t*)hash_table_search(root, text, tsize);
    return ret;
}

canonical_original_code:
struct _word_info_t *dict_search_word_info(char *text, unsigned long tsize)
{
    struct _word_info_t *ret = (word_info_t*)hash_table_search(root, text, tsize);
    return ret;
}

variable_types:
tsize
unsigned long

return_type: struct _word_info_t { unsigned char nbytes; unsigned char length; int freq; } *


decompiled_code:
char *__fastcall pool_alloc(size_t a1)
{
__int64 v1; // rdx

if ( a1 > 0x1FF )
return (char *)malloc(a1);
v1 = pool_size;
if ( pool_max_size - pool_size <= a1 )
return (char *)malloc(a1);
pool_size += a1;
return (char *)pool_mem + v1;
}

canonical_decompiled_code:
char *__fastcall func0(size_t a1)
{
__int64 v1; // rdx

if ( a1 > 0x1FF )
return (char *)malloc(a1);
v1 = pool_size;
if ( pool_max_size - pool_size <= a1 )
return (char *)malloc(a1);
pool_size += a1;
return (char *)pool_mem + v1;
}

original_code:
void*
pool_alloc(size_t size)
{
    if(size < 512 &&
       size < _pool_max_size - _pool_size)
    {
        void* ret = _pool_mem + _pool_size;
        _pool_size += size;
        return ret;
    }
    return malloc(size);
}

canonical_original_code:
void *pool_alloc(unsigned long size)
{
    if(size < 512 &&
       size < _pool_max_size - _pool_size)
    {
        void *ret = _pool_mem + _pool_size;
        _pool_size += size;
        return ret;
    }
    return malloc(size);
}

variable_types:
size
unsigned long

variable_types:
ret
void *

return_type: void *


decompiled_code:
void __fastcall pool_free(char *a1)
{
if ( pool_mem > a1 || a1 >= (char *)pool_mem + pool_max_size )
free(a1);
}

canonical_decompiled_code:
void __fastcall func1(char *a1)
{
if ( pool_mem > a1 || a1 >= (char *)pool_mem + pool_max_size )
free(a1);
}

original_code:
void
pool_free(void* ptr)
{
    if(ptr < _pool_mem ||
       ptr >= _pool_mem + _pool_max_size)
        free(ptr);
}

canonical_original_code:
void pool_free(void *ptr)
{
    if(ptr < _pool_mem ||
       ptr >= _pool_mem + _pool_max_size)
        free(ptr);
}

variable_types:
ptr
void *


decompiled_code:
void *pool_init()
{
void *result; // rax

pool_max_size = 0x200000LL;
result = malloc(0x200000uLL);
pool_size = 0LL;
pool_mem = result;
return result;
}

canonical_decompiled_code:
void *func2()
{
void *result; // rax

pool_max_size = 0x200000LL;
result = malloc(0x200000uLL);
pool_size = 0LL;
pool_mem = result;
return result;
}

original_code:
void
pool_init()
{
    _pool_max_size = 2097152;
    _pool_mem = malloc(_pool_max_size);
    _pool_size = 0;
}


decompiled_code:
void pool_deinit()
{
free(pool_mem);
pool_size = 0LL;
}

canonical_decompiled_code:
void func3()
{
free(pool_mem);
pool_size = 0LL;
}

original_code:
void
pool_deinit()
{
    free(_pool_mem);
    _pool_size = 0;
}


repo: mikedlowis-prototypes/sclpl

original_code:
static uint64_t hash64(uint64_t key)
{
    key = (~key) + (key << 21);
    key = key ^ (key >> 24);
    key = (key + (key << 3)) + (key << 8);
    key = key ^ (key >> 14);
    key = (key + (key << 2)) + (key << 4);
    key = key ^ (key >> 28);
    key = key + (key << 31);
    return key;
}

canonical_original_code:
static unsigned long hash64(unsigned long key)
{
    key = (~key) + (key << 21);
    key = key ^ (key >> 24);
    key = (key + (key << 3)) + (key << 8);
    key = key ^ (key >> 14);
    key = (key + (key << 2)) + (key << 4);
    key = key ^ (key >> 28);
    key = key + (key << 31);
    return key;
}

variable_types:
key
unsigned long


decompiled_code:
__int64 __fastcall num_buckets(unsigned int a1)
{
if ( a1 > 0x1C )
_assert_fail("idx < NUM_PRIMES", "source/gc.c", 0x22u, "num_buckets");
return (unsigned int)Primes[a1];
}

canonical_decompiled_code:
__int64 __fastcall func1(unsigned int a1)
{
if ( a1 > 0x1C )
_assert_fail("idx < NUM_PRIMES", "source/gc.c", 0x22u, "num_buckets");
return (unsigned int)Primes[a1];
}

original_code:
static unsigned int num_buckets(unsigned int idx) {
    ((idx < (sizeof(Primes)/sizeof(unsigned int))) ? (void) (0) : __assert_fail ("idx < NUM_PRIMES", "source/gc.c", 34, __extension__ __PRETTY_FUNCTION__));
    return Primes[idx];
}

variable_types:
idx
unsigned int

return_type: unsigned int


decompiled_code:
void __fastcall gc_sweep_table(__int64 a1)
{
unsigned int v1; // er12
__int64 v2; // r14
char *v3; // rbp
char *v4; // rax
_QWORD *v5; // rbx
_QWORD *v6; // rbp
void (*v7)(void); // rax

v1 = 0;
v2 = *(_QWORD *)(a1 + 8);
v3 = *(char **)(a1 + 16);
if ( (unsigned int)num_buckets(v2) )
{
do
{
v4 = &v3[8 * v1];
v5 = *(_QWORD **)v4;
*(_QWORD *)v4 = 0LL;
if ( v5 )
{
do
{
v6 = v5;
v5 = (_QWORD *)v5[2];
v7 = *(void (**)(void))(*v6 - 8LL);
if ( v7 )
v7();
free(v6);
}
while ( v5 );
v3 = *(char **)(a1 + 16);
v2 = *(_QWORD *)(a1 + 8);
}
++v1;
}
while ( (unsigned int)num_buckets(v2) > v1 );
}
free(v3);
}

original_code:
static void gc_sweep_table(hash_t* table) {
    unsigned int i;
    for (i = 0; i < num_buckets(table->bkt_count); i++) {
        hash_entry_t* node = table->buckets[i];
      table->buckets[i] = ((void *)0);
        while (node != ((void *)0)) {
            hash_entry_t* deadite = node;
            node = node->next;
            obj_t* obj = ((obj_t*)(deadite->object)-1);
            if (obj->destructor != ((void *)0))
                obj->destructor(deadite->object);
            free(deadite);
        }
    }
    free(table->buckets);
}

canonical_original_code:
static void gc_sweep_table(struct hash_t *table) {
    unsigned int i;
    for (i = 0; i < num_buckets(table->bkt_count); i++) {
        struct hash_entry_t *node = table->buckets[i];
      table->buckets[i] = ((void *)0);
        while (node != ((void *)0)) {
            struct hash_entry_t *deadite = node;
            node = node->next;
            struct obj_t *obj = ((obj_t*)(deadite->object)-1);
            if (obj->destructor != ((void *)0))
                obj->destructor(deadite->object);
            free(deadite);
        }
    }
    free(table->buckets);
}

variable_types: struct hash_t { unsigned long size; unsigned long bkt_count; struct hash_entry_t { struct obj_t { unsigned long refs; void (*destructor)(void *); } *object; unsigned int hash; struct hash_entry_t *next; } **buckets; } *

variable_types:
i
unsigned int

user_defined_types: struct hash_t { unsigned long size; unsigned long bkt_count; struct hash_entry_t **buckets; }

user_defined_types: struct hash_entry_t { struct obj_t *object; unsigned int hash; struct hash_entry_t *next; }


decompiled_code:
void gc_deinit(void)
{
Shutdown = 1;
gc_sweep_table((__int64)&Zero_Count_Table);
gc_sweep_table((__int64)&Multi_Ref_Table);
}

canonical_decompiled_code:
void func4(void)
{
Shutdown = 1;
func3((__int64)&Zero_Count_Table);
func3((__int64)&Multi_Ref_Table);
}

original_code:
void gc_deinit(void)
{
    Shutdown = 1;
    gc_sweep_table(&Zero_Count_Table);
    gc_sweep_table(&Multi_Ref_Table);
}

canonical_original_code:
void gc_deinit()
{
    Shutdown = 1;
    gc_sweep_table(&Zero_Count_Table);
    gc_sweep_table(&Multi_Ref_Table);
}


decompiled_code:
__int64 gc_mark()
{
jmp_buf env; // [rsp+10h] [rbp-D8h] BYREF

env[0].__saved_mask.__val[15] = 0x5555555555555555LL;
*(__m128i *)env[0].__jmpbuf = _mm_load_si128((const __m128i *)&LC2);
*(_OWORD *)&env[0].__jmpbuf[2] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__jmpbuf[4] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__jmpbuf[6] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__mask_was_saved = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__saved_mask.__val[1] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__saved_mask.__val[3] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__saved_mask.__val[5] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__saved_mask.__val[7] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__saved_mask.__val[9] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__saved_mask.__val[11] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__saved_mask.__val[13] = *(_OWORD *)env[0].__jmpbuf;
setjmp(env);
return gc_mark_stack();
}

canonical_decompiled_code:
__int64 func5()
{
jmp_buf env; // [rsp+10h] [rbp-D8h] BYREF

env[0].__saved_mask.__val[15] = 0x5555555555555555LL;
*(__m128i *)env[0].__jmpbuf = _mm_load_si128((const __m128i *)&LC2);
*(_OWORD *)&env[0].__jmpbuf[2] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__jmpbuf[4] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__jmpbuf[6] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__mask_was_saved = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__saved_mask.__val[1] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__saved_mask.__val[3] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__saved_mask.__val[5] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__saved_mask.__val[7] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__saved_mask.__val[9] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__saved_mask.__val[11] = *(_OWORD *)env[0].__jmpbuf;
*(_OWORD *)&env[0].__saved_mask.__val[13] = *(_OWORD *)env[0].__jmpbuf;
setjmp(env);
return func12();
}

original_code:
static void gc_mark(void) {
    jmp_buf env;
    volatile int noinline = 1;
    if (noinline) {
        memset(&env, 0x55, sizeof(jmp_buf));
        (void)_setjmp (env);
    }
    (noinline ? gc_mark_stack : ((void *)0))();
}

canonical_original_code:
static void gc_mark() {
    struct __jmp_buf_tag env[1];
    int noinline = 1;
    if (noinline) {
        memset(&env, 0x55, sizeof(jmp_buf));
        (void)_setjmp (env);
    }
    (noinline ? gc_mark_stack : ((void *)0))();
}

variable_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t { unsigned long __val[-1]; } __saved_mask; } [1]

variable_types: noinline int

user_defined_types: struct __jmp_buf_tag { long __jmpbuf[8]; int __mask_was_saved; struct __sigset_t __saved_mask; }


original_code:
static void hash_set(hash_t* hash, hash_entry_t* entry)
{
    unsigned int index;
    hash_entry_t *parent, *node, *deadite;
    if (hash->size >= num_buckets(hash->bkt_count))
        rehash(hash);
    entry->hash = hash64((uint64_t)(entry->object));
    index = (entry->hash % num_buckets(hash->bkt_count));
    parent = ((void *)0);
    node = hash->buckets[index];
    deadite = ((void *)0);
    find_entry(&parent, &node, entry);
    if ((parent == ((void *)0)) && (node == ((void *)0))) {
        hash->buckets[index] = entry;
        entry->next = ((void *)0);
        hash->size++;
    } else if (node == ((void *)0)) {
        parent->next = entry;
        entry->next = ((void *)0);
        hash->size++;
    } else if (parent == ((void *)0)) {
        deadite = node;
        entry->next = deadite->next;
        hash->buckets[index] = entry;
    } else {
        deadite = node;
        entry->next = deadite->next;
        parent->next = entry;
    }
    if (deadite != ((void *)0))
        free(deadite);
}

canonical_original_code:
static void hash_set(struct hash_t *hash, struct hash_entry_t *entry)
{
    unsigned int index;
    struct hash_entry_t *parent; struct hash_entry_t *node; struct hash_entry_t *deadite;
    if (hash->size >= num_buckets(hash->bkt_count))
        rehash(hash);
    entry->hash = hash64((unsigned long)(entry->object));
    index = (entry->hash % num_buckets(hash->bkt_count));
    parent = ((void *)0);
    node = hash->buckets[index];
    deadite = ((void *)0);
    find_entry(&parent, &node, entry);
    if ((parent == ((void *)0)) && (node == ((void *)0))) {
        hash->buckets[index] = entry;
        entry->next = ((void *)0);
        hash->size++;
    } else if (node == ((void *)0)) {
        parent->next = entry;
        entry->next = ((void *)0);
        hash->size++;
    } else if (parent == ((void *)0)) {
        deadite = node;
        entry->next = deadite->next;
        hash->buckets[index] = entry;
    } else {
        deadite = node;
        entry->next = deadite->next;
        parent->next = entry;
    }
    if (deadite != ((void *)0))
        free(deadite);
}

variable_types:
entry
struct hash_entry_t *

variable_types:
index
unsigned int

variable_types: struct hash_entry_t { struct obj_t { unsigned long refs; void (*destructor)(void *); } *object; unsigned int hash; struct hash_entry_t *next; } *


rehash

decompiled_code:
void __fastcall rehash(_QWORD *a1)
{
__int64 v2; // r13
__int64 v3; // rdi
_QWORD *v4; // r14
unsigned int v5; // er12
unsigned int v6; // eax
void *v7; // rax
__int64 v8; // rbx
__int64 v9; // rsi

v2 = a1[1];
v3 = v2 + 1;
if ( (unsigned __int64)(v2 + 1) <= 0x1C )
{
a1[1] = v3;
v4 = (_QWORD *)a1[2];
v5 = 0;
v6 = num_buckets(v3);
v7 = calloc(8uLL, v6);
*a1 = 0LL;
for ( a1[2] = v7; (unsigned int)num_buckets(v2) > v5; ++v5 )
{
v8 = v4[v5];
while ( v8 )
{
v9 = v8;
v8 = *(_QWORD *)(v8 + 16);
hash_set(a1, v9);
}
}
free(v4);
}
}

original_code:
static void rehash(hash_t* hash)
{
    unsigned int oldcount, i;
    hash_entry_t** oldbuckets;
    hash_entry_t *node, *entry;
    if ((hash->bkt_count+1) < (sizeof(Primes)/sizeof(unsigned int))) {
        oldcount = hash->bkt_count++;
        oldbuckets = hash->buckets;
        hash->buckets = (hash_entry_t**)calloc(sizeof(hash_entry_t*), num_buckets(hash->bkt_count));
        hash->size = 0;
        for (i = 0; i < num_buckets(oldcount); i++) {
            node = oldbuckets[i];
            while (node != ((void *)0)) {
                entry = node;
                node = entry->next;
                hash_set(hash, entry);
            }
        }
        free(oldbuckets);
    }
}

canonical_original_code:
static void rehash(struct hash_t *hash)
{
    unsigned int oldcount; unsigned int i;
    struct hash_entry_t **oldbuckets;
    struct hash_entry_t *node; struct hash_entry_t *entry;
    if ((hash->bkt_count+1) < (sizeof(Primes)/sizeof(unsigned int))) {
        oldcount = hash->bkt_count++;
        oldbuckets = hash->buckets;
        hash->buckets = (struct hash_entry_t **)calloc(sizeof(struct hash_entry_t *), num_buckets(hash->bkt_count));
        hash->size = 0;
        for (i = 0; i < num_buckets(oldcount); i++) {
            node = oldbuckets[i];
            while (node != ((void *)0)) {
                entry = node;
                node = entry->next;
                hash_set(hash, entry);
            }
        }
        free(oldbuckets);
    }
}

variable_types:
oldcount
unsigned int

variable_types: struct hash_entry_t { struct obj_t { unsigned long refs; void (*destructor)(void *); } *object; unsigned int hash; struct hash_entry_t *next; } **


original_code:
static hash_entry_t* hash_del(hash_t* hash, hash_entry_t* entry)
{
    unsigned int index;
    hash_entry_t *parent, *node, *ret = ((void *)0);
    entry->hash = hash64((uint64_t)(entry->object));
    index = (entry->hash % num_buckets(hash->bkt_count));
    parent = ((void *)0);
    node = hash->buckets[index];
    find_entry(&parent, &node, entry);
    if (node != ((void *)0)) {
        ret = node;
        node = node->next;
        if (parent != ((void *)0))
            parent->next = node;
        else
            hash->buckets[index] = node;
        hash->size--;
    }
    return ret;
}

canonical_original_code:
static struct hash_entry_t *hash_del(struct hash_t *hash, struct hash_entry_t *entry)
{
    unsigned int index;
    struct hash_entry_t *parent; struct hash_entry_t *node; struct hash_entry_t *ret = ((void *)0);
    entry->hash = hash64((unsigned long)(entry->object));
    index = (entry->hash % num_buckets(hash->bkt_count));
    parent = ((void *)0);
    node = hash->buckets[index];
    find_entry(&parent, &node, entry);
    if (node != ((void *)0)) {
        ret = node;
        node = node->next;
        if (parent != ((void *)0))
            parent->next = node;
        else
            hash->buckets[index] = node;
        hash->size--;
    }
    return ret;
}

variable_types: struct hash_t { unsigned long size; unsigned long bkt_count; struct hash_entry_t **buckets; } *

return_type: struct hash_entry_t { struct obj_t { unsigned long refs; void (*destructor)(void *); } *object; unsigned int hash; struct hash_entry_t *next; } *


decompiled_code:
void gc_mark_stack()
{
__int64 v0[2]; // [rsp+8h] [rbp-10h] BYREF

v0[0] = 0LL;
if ( Stack_Bottom <= (unsigned __int64)v0 )
gc_mark_region((__int64 *)Stack_Bottom, (unsigned __int64)v0);
else
gc_mark_region(v0, Stack_Bottom);
}

canonical_decompiled_code:
void func12()
{
__int64 v0[2]; // [rsp+8h] [rbp-10h] BYREF

v0[0] = 0LL;
if ( Stack_Bottom <= (unsigned __int64)v0 )
func11((__int64 *)Stack_Bottom, (unsigned __int64)v0);
else
func11(v0, Stack_Bottom);
}

original_code:
static void gc_mark_stack(void) {
    void* stack_top = ((void *)0);
    if (&stack_top < Stack_Bottom) {
        gc_mark_region(&stack_top, Stack_Bottom);
    } else {
        gc_mark_region(Stack_Bottom, &stack_top);
    }
}

canonical_original_code:
static void gc_mark_stack() {
    void *stack_top = ((void *)0);
    if (&stack_top < Stack_Bottom) {
        gc_mark_region(&stack_top, Stack_Bottom);
    } else {
        gc_mark_region(Stack_Bottom, &stack_top);
    }
}


decompiled_code:
int __fastcall gc_init(__int64 a1)
{
int result; // eax

Stack_Bottom = a1;
hash_init(&Zero_Count_Table);
hash_init(Multi_Ref_Table);
result = atexit(gc_deinit);
Shutdown = 0;
return result;
}

canonical_decompiled_code:
int __fastcall func13(__int64 a1)
{
int result; // eax

Stack_Bottom = a1;
func2(&Zero_Count_Table);
func2(Multi_Ref_Table);
result = atexit(gc_deinit);
Shutdown = 0;
return result;
}

original_code:
void gc_init(void** stack_bottom)
{
    Stack_Bottom = stack_bottom;
    hash_init(&Zero_Count_Table);
    hash_init(&Multi_Ref_Table);
    atexit(gc_deinit);
    Shutdown = 0;
}

canonical_original_code:
void gc_init(void **stack_bottom)
{
    Stack_Bottom = stack_bottom;
    hash_init(&Zero_Count_Table);
    hash_init(&Multi_Ref_Table);
    atexit(gc_deinit);
    Shutdown = 0;
}


decompiled_code:
void gc_collect()
{
qword_7A0 = qword_7E0;
Working_Table = (__int128)_mm_load_si128((const __m128i *)&Zero_Count_Table);
hash_init(&Zero_Count_Table);
gc_mark();
gc_sweep_table((__int64)&Working_Table);
}

canonical_decompiled_code:
void func14()
{
qword_7A0 = qword_7E0;
Working_Table = (__int128)_mm_load_si128((const __m128i *)&Zero_Count_Table);
func2(&Zero_Count_Table);
func5();
func3((__int64)&Working_Table);
}

original_code:
void gc_collect(void) {
    Working_Table = Zero_Count_Table;
    hash_init(&Zero_Count_Table);
    gc_mark();
    gc_sweep_table(&Working_Table);
}

canonical_original_code:
void gc_collect() {
    Working_Table = Zero_Count_Table;
    hash_init(&Zero_Count_Table);
    gc_mark();
    gc_sweep_table(&Working_Table);
}


decompiled_code:
__int64 __fastcall gc_addref(__int64 a1)
{
__int64 v1; // rax
__int64 v3; // rsi
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
int v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+10h] [rbp-18h]

v5 = 0;
v6 = 0LL;
if ( a1 )
{
if ( !Shutdown )
{
v1 = *(_QWORD *)(a1 - 16) + 1LL;
*(_QWORD *)(a1 - 16) = v1;
if ( v1 == 1 )
{
v4 = a1;
v3 = hash_del((__int64)&Zero_Count_Table, (__int64)&v4);
if ( !v3 )
_assert_fail("entry != NULL", "source/gc.c", 0x110u, "gc_addref");
hash_set(Multi_Ref_Table, v3);
}
}
}
return a1;
}

canonical_decompiled_code:
__int64 __fastcall func15(__int64 a1)
{
__int64 v1; // rax
__int64 v3; // rsi
__int64 v4; // [rsp+0h] [rbp-28h] BYREF
int v5; // [rsp+8h] [rbp-20h]
__int64 v6; // [rsp+10h] [rbp-18h]

v5 = 0;
v6 = 0LL;
if ( a1 )
{
if ( !Shutdown )
{
v1 = *(_QWORD *)(a1 - 16) + 1LL;
*(_QWORD *)(a1 - 16) = v1;
if ( v1 == 1 )
{
v4 = a1;
v3 = func10((__int64)&Zero_Count_Table, (__int64)&v4);
if ( !v3 )
_assert_fail("entry != NULL", "source/gc.c", 0x110u, "gc_addref");
func8(Multi_Ref_Table, v3);
}
}
}
return a1;
}

original_code:
void* gc_addref(void* ptr)
{
    hash_entry_t lookup = {0, 0, 0};
    hash_entry_t* entry;
    obj_t* obj = ((obj_t*)ptr-1);
    if ((ptr != ((void *)0)) && !Shutdown) {
        obj->refs++;
        if (obj->refs == 1) {
            lookup.object = ptr;
            entry = hash_del(&Zero_Count_Table, &lookup);
            ((entry != ((void *)0)) ? (void) (0) : __assert_fail ("entry != NULL", "source/gc.c", 272, __extension__ __PRETTY_FUNCTION__));
            hash_set(&Multi_Ref_Table, entry);
        }
    }
    return ptr;
}

canonical_original_code:
void *gc_addref(void *ptr)
{
    struct hash_entry_t lookup = {0, 0, 0};
    struct hash_entry_t *entry;
    struct obj_t *obj = ((obj_t*)ptr-1);
    if ((ptr != ((void *)0)) && !Shutdown) {
        obj->refs++;
        if (obj->refs == 1) {
            lookup.object = ptr;
            entry = hash_del(&Zero_Count_Table, &lookup);
            ((entry != ((void *)0)) ? (void) (0) : __assert_fail ("entry != NULL", "source/gc.c", 272, __extension__ __PRETTY_FUNCTION__));
            hash_set(&Multi_Ref_Table, entry);
        }
    }
    return ptr;
}

variable_types: struct hash_entry_t { struct obj_t { unsigned long refs; void (*destructor)(void *); } *object; unsigned int hash; struct hash_entry_t *next; }


decompiled_code:
void __fastcall gc_delref(__int64 a1)
{
__int64 v2; // rsi
__int64 v3; // [rsp+0h] [rbp-28h] BYREF
int v4; // [rsp+8h] [rbp-20h]
__int64 v5; // [rsp+10h] [rbp-18h]

v4 = 0;
v5 = 0LL;
if ( a1 )
{
if ( !Shutdown && (*(_QWORD *)(a1 - 16))-- == 1LL )
{
v3 = a1;
v2 = hash_del((__int64)Multi_Ref_Table, (__int64)&v3);
if ( !v2 )
_assert_fail("entry != NULL", "source/gc.c", 0x121u, "gc_delref");
hash_set(&Zero_Count_Table, v2);
}
}
}

canonical_decompiled_code:
void __fastcall func16(__int64 a1)
{
__int64 v2; // rsi
__int64 v3; // [rsp+0h] [rbp-28h] BYREF
int v4; // [rsp+8h] [rbp-20h]
__int64 v5; // [rsp+10h] [rbp-18h]

v4 = 0;
v5 = 0LL;
if ( a1 )
{
if ( !Shutdown && (*(_QWORD *)(a1 - 16))-- == 1LL )
{
v3 = a1;
v2 = func10((__int64)Multi_Ref_Table, (__int64)&v3);
if ( !v2 )
_assert_fail("entry != NULL", "source/gc.c", 0x121u, "gc_delref");
func8(&Zero_Count_Table, v2);
}
}
}

original_code:
void gc_delref(void* ptr)
{
    hash_entry_t lookup = {0, 0, 0};
    hash_entry_t* entry;
    obj_t* obj = ((obj_t*)ptr-1);
    if ((ptr != ((void *)0)) && !Shutdown) {
        obj->refs--;
        if (obj->refs == 0) {
            lookup.object = ptr;
            entry = hash_del(&Multi_Ref_Table, &lookup);
            ((entry != ((void *)0)) ? (void) (0) : __assert_fail ("entry != NULL", "source/gc.c", 289, __extension__ __PRETTY_FUNCTION__));
            hash_set(&Zero_Count_Table, entry);
        }
    }
}

canonical_original_code:
void gc_delref(void *ptr)
{
    struct hash_entry_t lookup = {0, 0, 0};
    struct hash_entry_t *entry;
    struct obj_t *obj = ((obj_t*)ptr-1);
    if ((ptr != ((void *)0)) && !Shutdown) {
        obj->refs--;
        if (obj->refs == 0) {
            lookup.object = ptr;
            entry = hash_del(&Multi_Ref_Table, &lookup);
            ((entry != ((void *)0)) ? (void) (0) : __assert_fail ("entry != NULL", "source/gc.c", 289, __extension__ __PRETTY_FUNCTION__));
            hash_set(&Zero_Count_Table, entry);
        }
    }
}

variable_types: struct obj_t { unsigned long refs; void (*destructor)(void *); } *


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

v2 = *a1;
*a1 = gc_addref(a2);
gc_delref(v2);
}

original_code:
void gc_swapref(void** dest, void* newref)
{
    void* oldref = *dest;
    *dest = gc_addref(newref);
    gc_delref(oldref);
}

canonical_original_code:
void gc_swapref(void **dest, void *newref)
{
    void *oldref = *dest;
    *dest = gc_addref(newref);
    gc_delref(oldref);
}

variable_types:
dest
void **

variable_types:
newref
void *

variable_types:
oldref
void *


main

canonical_name: main

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v4[0] = 0LL;
gc_init((__int64)v4);
return user_main((unsigned int)argc, argv);
}

canonical_decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v4[0] = 0LL;
func13((__int64)v4);
return user_main((unsigned int)argc, argv);
}

original_code:
int main(int argc, char** argv)
{
    void* stack_bottom = ((void *)0);
    gc_init(&stack_bottom);
    return user_main(argc, argv);
}

canonical_original_code:
int main(int argc, char **argv)
{
    void *stack_bottom = ((void *)0);
    gc_init(&stack_bottom);
    return user_main(argc, argv);
}

variable_types: argc int

variable_types:
argv
char **


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

switch ( *(_DWORD *)(a1 + 24) )
{
case 0:
result = Ident();
break;
case 1:
result = Char();
break;
case 2:
result = Integer();
break;
case 3:
result = Float();
break;
case 4:
result = Bool();
break;
case 5:
result = String();
break;
default:
result = 0LL;
break;
}
return result;
}

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

switch ( *(_DWORD *)(a1 + 24) )
{
case 0:
result = Ident();
break;
case 1:
result = Char();
break;
case 2:
result = Integer();
break;
case 3:
result = Float();
break;
case 4:
result = Bool();
break;
case 5:
result = String();
break;
default:
result = 0LL;
break;
}
return result;
}

original_code:
static AST* token_to_tree(Tok* tok)
{
    switch (tok->type) {
        case T_BOOL: return Bool(tok);
        case T_CHAR: return Char(tok);
        case T_STRING: return String(tok);
        case T_INT: return Integer(tok);
        case T_FLOAT: return Float(tok);
        case T_ID: return Ident(tok);
        default: return ((void *)0);
    }
}

canonical_original_code:
static struct AST *token_to_tree(struct Tok *tok)
{
    switch (tok->type) {
        case T_BOOL: return Bool(tok);
        case T_CHAR: return Char(tok);
        case T_STRING: return String(tok);
        case T_INT: return Integer(tok);
        case T_FLOAT: return Float(tok);
        case T_ID: return Ident(tok);
        default: return ((void *)0);
    }
}

variable_types: struct Tok { char *file; unsigned long line; unsigned long col; enum TokType { T_ID=0, T_CHAR=1, T_INT=2, T_FLOAT=3, T_BOOL=4, T_STRING=5, T_LBRACE=6, T_RBRACE=7, T_LBRACK=8, T_RBRACK=9, T_LPAR=10, T_RPAR=11, T_COMMA=12, T_SQUOTE=13, T_DQUOTE=14, T_END=15, T_COLON=16, T_AMP=17, T_REQUIRE=18, T_DEF=19, T_IF=20, T_FN=21, T_THEN=22, T_ELSE=23, T_END_FILE=24 } type; union { char *text; unsigned int character; long integer; double floating; _Bool boolean; } value; } *

return_type: struct AST { enum ASTType { AST_STRING=0, AST_SYMBOL=1, AST_CHAR=2, AST_INT=3, AST_FLOAT=4, AST_BOOL=5, AST_IDENT=6, AST_REQ=7, AST_DEF=8, AST_IF=9, AST_FUNC=10, AST_FNAPP=11, AST_LET=12, AST_TEMP=13 } type; union { struct { char *name; struct AST *type; struct AST *value; } def; struct { struct AST *cond; struct AST *bthen; struct AST *belse; } ifexpr; struct { struct vec_t { unsigned long count; unsigned long size; unsigned long capacity; void **buffer; } args; struct AST *body; } func; struct { struct AST *fn; struct vec_t args; } fnapp; struct { struct AST *temp; struct AST *value; struct AST *body; } let; char *text; unsigned int character; long integer; double floating; _Bool boolean; } value; } *

user_defined_types: struct Tok { char *file; unsigned long line; unsigned long col; enum TokType type; union { char *text; unsigned int character; long integer; double floating; _Bool boolean; } value; }

user_defined_types: struct AST { enum ASTType type; union { struct { char *name; struct AST *type; struct AST *value; } def; struct { struct AST *cond; struct AST *bthen; struct AST *belse; } ifexpr; struct { struct vec_t args; struct AST *body; } func; struct { struct AST *fn; struct vec_t args; } fnapp; struct { struct AST *temp; struct AST *value; struct AST *body; } let; char *text; unsigned int character; long integer; double floating; _Bool boolean; } value; }


decompiled_code:
__int64 __fastcall ast_free(unsigned int *a1)
{
__int64 result; // rax

result = *a1;
switch ( *a1 )
{
case 0u:
case 1u:
case 6u:
case 7u:
result = gc_delref(*((_QWORD *)a1 + 1));
break;
case 8u:
gc_delref(*((_QWORD *)a1 + 1));
result = gc_delref(*((_QWORD *)a1 + 3));
break;
case 9u:
gc_delref(*((_QWORD *)a1 + 1));
gc_delref(*((_QWORD *)a1 + 2));
result = gc_delref(*((_QWORD *)a1 + 3));
break;
case 0xAu:
vec_deinit(a1 + 2);
result = gc_delref(*((_QWORD *)a1 + 5));
break;
case 0xBu:
gc_delref(*((_QWORD *)a1 + 1));
result = vec_deinit(a1 + 4);
break;
default:
return result;
}
return result;
}

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

result = *a1;
switch ( *a1 )
{
case 0u:
case 1u:
case 6u:
case 7u:
result = gc_delref(*((_QWORD *)a1 + 1));
break;
case 8u:
gc_delref(*((_QWORD *)a1 + 1));
result = gc_delref(*((_QWORD *)a1 + 3));
break;
case 9u:
gc_delref(*((_QWORD *)a1 + 1));
gc_delref(*((_QWORD *)a1 + 2));
result = gc_delref(*((_QWORD *)a1 + 3));
break;
case 0xAu:
vec_deinit(a1 + 2);
result = gc_delref(*((_QWORD *)a1 + 5));
break;
case 0xBu:
gc_delref(*((_QWORD *)a1 + 1));
result = vec_deinit(a1 + 4);
break;
default:
return result;
}
return result;
}

original_code:
static void ast_free(void* ptr)
{
    AST* ast = (AST*)ptr;
    switch(ast->type) {
        case AST_REQ:
        case AST_IDENT:
        case AST_STRING:
        case AST_SYMBOL:
            gc_delref(ast->value.text);
            break;
        case AST_DEF:
            gc_delref(ast->value.def.name);
            gc_delref(ast->value.def.value);
            break;
        case AST_IF:
            gc_delref(ast->value.ifexpr.cond);
            gc_delref(ast->value.ifexpr.bthen);
            gc_delref(ast->value.ifexpr.belse);
            break;
        case AST_FUNC:
            vec_deinit(&(ast->value.func.args));
            gc_delref(ast->value.func.body);
            break;
        case AST_FNAPP:
            gc_delref(ast->value.fnapp.fn);
            vec_deinit(&(ast->value.fnapp.args));
            break;
        case AST_LET:
            break;
        case AST_TEMP:
            break;
        default:
            break;
    }
}

canonical_original_code:
static void ast_free(void *ptr)
{
    struct AST *ast = (AST*)ptr;
    switch(ast->type) {
        case AST_REQ:
        case AST_IDENT:
        case AST_STRING:
        case AST_SYMBOL:
            gc_delref(ast->value.text);
            break;
        case AST_DEF:
            gc_delref(ast->value.def.name);
            gc_delref(ast->value.def.value);
            break;
        case AST_IF:
            gc_delref(ast->value.ifexpr.cond);
            gc_delref(ast->value.ifexpr.bthen);
            gc_delref(ast->value.ifexpr.belse);
            break;
        case AST_FUNC:
            vec_deinit(&(ast->value.func.args));
            gc_delref(ast->value.func.body);
            break;
        case AST_FNAPP:
            gc_delref(ast->value.fnapp.fn);
            vec_deinit(&(ast->value.fnapp.args));
            break;
        case AST_LET:
            break;
        case AST_TEMP:
            break;
        default:
            break;
    }
}

variable_types:
ptr
void *

variable_types: struct AST { enum ASTType { AST_STRING=0, AST_SYMBOL=1, AST_CHAR=2, AST_INT=3, AST_FLOAT=4, AST_BOOL=5, AST_IDENT=6, AST_REQ=7, AST_DEF=8, AST_IF=9, AST_FUNC=10, AST_FNAPP=11, AST_LET=12, AST_TEMP=13 } type; union { struct { char *name; struct AST *type; struct AST *value; } def; struct { struct AST *cond; struct AST *bthen; struct AST *belse; } ifexpr; struct { struct vec_t { unsigned long count; unsigned long size; unsigned long capacity; void **buffer; } args; struct AST *body; } func; struct { struct AST *fn; struct vec_t args; } fnapp; struct { struct AST *temp; struct AST *value; struct AST *body; } let; char *text; unsigned int character; long integer; double floating; _Bool boolean; } value; } *


decompiled_code:
__int64 __fastcall string_value(__int64 a1)
{
if ( !a1 )
_assert_fail("val != NULL", "source/ast.c", 0x3Fu, "string_value");
if ( *(_DWORD *)a1 )
_assert_fail("val->type == AST_STRING", "source/ast.c", 0x40u, "string_value");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
if ( !a1 )
_assert_fail("val != NULL", "source/ast.c", 0x3Fu, "string_value");
if ( *(_DWORD *)a1 )
_assert_fail("val->type == AST_STRING", "source/ast.c", 0x40u, "string_value");
return *(_QWORD *)(a1 + 8);
}

original_code:
char* string_value(AST* val)
{
    ((val != ((void *)0)) ? (void) (0) : __assert_fail ("val != NULL", "source/ast.c", 63, __extension__ __PRETTY_FUNCTION__));
    ((val->type == AST_STRING) ? (void) (0) : __assert_fail ("val->type == AST_STRING", "source/ast.c", 64, __extension__ __PRETTY_FUNCTION__));
    return val->value.text;
}

canonical_original_code:
char *string_value(struct AST *val)
{
    ((val != ((void *)0)) ? (void) (0) : __assert_fail ("val != NULL", "source/ast.c", 63, __extension__ __PRETTY_FUNCTION__));
    ((val->type == AST_STRING) ? (void) (0) : __assert_fail ("val->type == AST_STRING", "source/ast.c", 64, __extension__ __PRETTY_FUNCTION__));
    return val->value.text;
}

return_type: char *

user_defined_types: enum ASTType { AST_STRING=0, AST_SYMBOL=1, AST_CHAR=2, AST_INT=3, AST_FLOAT=4, AST_BOOL=5, AST_IDENT=6, AST_REQ=7, AST_DEF=8, AST_IF=9, AST_FUNC=10, AST_FNAPP=11, AST_LET=12, AST_TEMP=13 }

user_defined_types: struct vec_t { unsigned long count; unsigned long size; unsigned long capacity; void **buffer; }


decompiled_code:
__int64 __fastcall symbol_value(__int64 a1)
{
if ( !a1 )
_assert_fail("val != NULL", "source/ast.c", 0x4Du, "symbol_value");
if ( *(_DWORD *)a1 != 1 )
_assert_fail("val->type == AST_SYMBOL", "source/ast.c", 0x4Eu, "symbol_value");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1)
{
if ( !a1 )
_assert_fail("val != NULL", "source/ast.c", 0x4Du, "symbol_value");
if ( *(_DWORD *)a1 != 1 )
_assert_fail("val->type == AST_SYMBOL", "source/ast.c", 0x4Eu, "symbol_value");
return *(_QWORD *)(a1 + 8);
}

original_code:
char* symbol_value(AST* val)
{
    ((val != ((void *)0)) ? (void) (0) : __assert_fail ("val != NULL", "source/ast.c", 77, __extension__ __PRETTY_FUNCTION__));
    ((val->type == AST_SYMBOL) ? (void) (0) : __assert_fail ("val->type == AST_SYMBOL", "source/ast.c", 78, __extension__ __PRETTY_FUNCTION__));
    return val->value.text;
}

canonical_original_code:
char *symbol_value(struct AST *val)
{
    ((val != ((void *)0)) ? (void) (0) : __assert_fail ("val != NULL", "source/ast.c", 77, __extension__ __PRETTY_FUNCTION__));
    ((val->type == AST_SYMBOL) ? (void) (0) : __assert_fail ("val->type == AST_SYMBOL", "source/ast.c", 78, __extension__ __PRETTY_FUNCTION__));
    return val->value.text;
}


decompiled_code:
__int64 __fastcall char_value(_DWORD *a1)
{
if ( !a1 )
_assert_fail("val != NULL", "source/ast.c", 0x5Bu, "char_value");
if ( *a1 != 2 )
_assert_fail("val->type == AST_CHAR", "source/ast.c", 0x5Cu, "char_value");
return (unsigned int)a1[2];
}

canonical_decompiled_code:
__int64 __fastcall func3(_DWORD *a1)
{
if ( !a1 )
_assert_fail("val != NULL", "source/ast.c", 0x5Bu, "char_value");
if ( *a1 != 2 )
_assert_fail("val->type == AST_CHAR", "source/ast.c", 0x5Cu, "char_value");
return (unsigned int)a1[2];
}

original_code:
uint32_t char_value(AST* val)
{
    ((val != ((void *)0)) ? (void) (0) : __assert_fail ("val != NULL", "source/ast.c", 91, __extension__ __PRETTY_FUNCTION__));
    ((val->type == AST_CHAR) ? (void) (0) : __assert_fail ("val->type == AST_CHAR", "source/ast.c", 92, __extension__ __PRETTY_FUNCTION__));
    return val->value.character;
}

canonical_original_code:
unsigned int char_value(struct AST *val)
{
    ((val != ((void *)0)) ? (void) (0) : __assert_fail ("val != NULL", "source/ast.c", 91, __extension__ __PRETTY_FUNCTION__));
    ((val->type == AST_CHAR) ? (void) (0) : __assert_fail ("val->type == AST_CHAR", "source/ast.c", 92, __extension__ __PRETTY_FUNCTION__));
    return val->value.character;
}


decompiled_code:
__int64 __fastcall integer_value(__int64 a1)
{
if ( !a1 )
_assert_fail("val != NULL", "source/ast.c", 0x69u, "integer_value");
if ( *(_DWORD *)a1 != 3 )
_assert_fail("val->type == AST_INT", "source/ast.c", 0x6Au, "integer_value");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1)
{
if ( !a1 )
_assert_fail("val != NULL", "source/ast.c", 0x69u, "integer_value");
if ( *(_DWORD *)a1 != 3 )
_assert_fail("val->type == AST_INT", "source/ast.c", 0x6Au, "integer_value");
return *(_QWORD *)(a1 + 8);
}

original_code:
intptr_t integer_value(AST* val)
{
    ((val != ((void *)0)) ? (void) (0) : __assert_fail ("val != NULL", "source/ast.c", 105, __extension__ __PRETTY_FUNCTION__));
    ((val->type == AST_INT) ? (void) (0) : __assert_fail ("val->type == AST_INT", "source/ast.c", 106, __extension__ __PRETTY_FUNCTION__));
    return val->value.integer;
}

canonical_original_code:
long integer_value(struct AST *val)
{
    ((val != ((void *)0)) ? (void) (0) : __assert_fail ("val != NULL", "source/ast.c", 105, __extension__ __PRETTY_FUNCTION__));
    ((val->type == AST_INT) ? (void) (0) : __assert_fail ("val->type == AST_INT", "source/ast.c", 106, __extension__ __PRETTY_FUNCTION__));
    return val->value.integer;
}

return_type: long


decompiled_code:
__int64 __fastcall temp_value(__int64 a1)
{
if ( !a1 )
_assert_fail("val != NULL", "source/ast.c", 0x70u, "temp_value");
if ( *(_DWORD *)a1 != 13 )
_assert_fail("val->type == AST_TEMP", "source/ast.c", 0x71u, "temp_value");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
if ( !a1 )
_assert_fail("val != NULL", "source/ast.c", 0x70u, "temp_value");
if ( *(_DWORD *)a1 != 13 )
_assert_fail("val->type == AST_TEMP", "source/ast.c", 0x71u, "temp_value");
return *(_QWORD *)(a1 + 8);
}

original_code:
intptr_t temp_value(AST* val)
{
    ((val != ((void *)0)) ? (void) (0) : __assert_fail ("val != NULL", "source/ast.c", 112, __extension__ __PRETTY_FUNCTION__));
    ((val->type == AST_TEMP) ? (void) (0) : __assert_fail ("val->type == AST_TEMP", "source/ast.c", 113, __extension__ __PRETTY_FUNCTION__));
    return val->value.integer;
}

canonical_original_code:
long temp_value(struct AST *val)
{
    ((val != ((void *)0)) ? (void) (0) : __assert_fail ("val != NULL", "source/ast.c", 112, __extension__ __PRETTY_FUNCTION__));
    ((val->type == AST_TEMP) ? (void) (0) : __assert_fail ("val->type == AST_TEMP", "source/ast.c", 113, __extension__ __PRETTY_FUNCTION__));
    return val->value.integer;
}


decompiled_code:
double __fastcall float_value(__int64 a1)
{
if ( !a1 )
_assert_fail("val != NULL", "source/ast.c", 0x7Eu, "float_value");
if ( *(_DWORD *)a1 != 4 )
_assert_fail("val->type == AST_FLOAT", "source/ast.c", 0x7Fu, "float_value");
return *(double *)(a1 + 8);
}

canonical_decompiled_code:
double __fastcall func6(__int64 a1)
{
if ( !a1 )
_assert_fail("val != NULL", "source/ast.c", 0x7Eu, "float_value");
if ( *(_DWORD *)a1 != 4 )
_assert_fail("val->type == AST_FLOAT", "source/ast.c", 0x7Fu, "float_value");
return *(double *)(a1 + 8);
}

original_code:
double float_value(AST* val)
{
    ((val != ((void *)0)) ? (void) (0) : __assert_fail ("val != NULL", "source/ast.c", 126, __extension__ __PRETTY_FUNCTION__));
    ((val->type == AST_FLOAT) ? (void) (0) : __assert_fail ("val->type == AST_FLOAT", "source/ast.c", 127, __extension__ __PRETTY_FUNCTION__));
    return val->value.floating;
}

canonical_original_code:
double float_value(struct AST *val)
{
    ((val != ((void *)0)) ? (void) (0) : __assert_fail ("val != NULL", "source/ast.c", 126, __extension__ __PRETTY_FUNCTION__));
    ((val->type == AST_FLOAT) ? (void) (0) : __assert_fail ("val->type == AST_FLOAT", "source/ast.c", 127, __extension__ __PRETTY_FUNCTION__));
    return val->value.floating;
}

return_type: double


decompiled_code:
__int64 __fastcall bool_value(__int64 a1)
{
if ( !a1 )
_assert_fail("val != NULL", "source/ast.c", 0x8Cu, "bool_value");
if ( *(_DWORD *)a1 != 5 )
_assert_fail("val->type == AST_BOOL", "source/ast.c", 0x8Du, "bool_value");
return *(unsigned __int8 *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
if ( !a1 )
_assert_fail("val != NULL", "source/ast.c", 0x8Cu, "bool_value");
if ( *(_DWORD *)a1 != 5 )
_assert_fail("val->type == AST_BOOL", "source/ast.c", 0x8Du, "bool_value");
return *(unsigned __int8 *)(a1 + 8);
}

original_code:
_Bool bool_value(AST* val)
{
    ((val != ((void *)0)) ? (void) (0) : __assert_fail ("val != NULL", "source/ast.c", 140, __extension__ __PRETTY_FUNCTION__));
    ((val->type == AST_BOOL) ? (void) (0) : __assert_fail ("val->type == AST_BOOL", "source/ast.c", 141, __extension__ __PRETTY_FUNCTION__));
    return val->value.boolean;
}

canonical_original_code:
_Bool bool_value(struct AST *val)
{
    ((val != ((void *)0)) ? (void) (0) : __assert_fail ("val != NULL", "source/ast.c", 140, __extension__ __PRETTY_FUNCTION__));
    ((val->type == AST_BOOL) ? (void) (0) : __assert_fail ("val->type == AST_BOOL", "source/ast.c", 141, __extension__ __PRETTY_FUNCTION__));
    return val->value.boolean;
}


decompiled_code:
__int64 __fastcall ident_value(__int64 a1)
{
if ( !a1 )
_assert_fail("val != NULL", "source/ast.c", 0x9Au, "ident_value");
if ( *(_DWORD *)a1 != 6 )
_assert_fail("val->type == AST_IDENT", "source/ast.c", 0x9Bu, "ident_value");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1)
{
if ( !a1 )
_assert_fail("val != NULL", "source/ast.c", 0x9Au, "ident_value");
if ( *(_DWORD *)a1 != 6 )
_assert_fail("val->type == AST_IDENT", "source/ast.c", 0x9Bu, "ident_value");
return *(_QWORD *)(a1 + 8);
}

original_code:
char* ident_value(AST* val)
{
    ((val != ((void *)0)) ? (void) (0) : __assert_fail ("val != NULL", "source/ast.c", 154, __extension__ __PRETTY_FUNCTION__));
    ((val->type == AST_IDENT) ? (void) (0) : __assert_fail ("val->type == AST_IDENT", "source/ast.c", 155, __extension__ __PRETTY_FUNCTION__));
    return val->value.text;
}

canonical_original_code:
char *ident_value(struct AST *val)
{
    ((val != ((void *)0)) ? (void) (0) : __assert_fail ("val != NULL", "source/ast.c", 154, __extension__ __PRETTY_FUNCTION__));
    ((val->type == AST_IDENT) ? (void) (0) : __assert_fail ("val->type == AST_IDENT", "source/ast.c", 155, __extension__ __PRETTY_FUNCTION__));
    return val->value.text;
}


decompiled_code:
__int64 __fastcall require_name(__int64 a1)
{
if ( !a1 )
_assert_fail("req != NULL", "source/ast.c", 0xA8u, "require_name");
if ( *(_DWORD *)a1 != 7 )
_assert_fail("req->type == AST_REQ", "source/ast.c", 0xA9u, "require_name");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func9(__int64 a1)
{
if ( !a1 )
_assert_fail("req != NULL", "source/ast.c", 0xA8u, "require_name");
if ( *(_DWORD *)a1 != 7 )
_assert_fail("req->type == AST_REQ", "source/ast.c", 0xA9u, "require_name");
return *(_QWORD *)(a1 + 8);
}

original_code:
char* require_name(AST* req)
{
    ((req != ((void *)0)) ? (void) (0) : __assert_fail ("req != NULL", "source/ast.c", 168, __extension__ __PRETTY_FUNCTION__));
    ((req->type == AST_REQ) ? (void) (0) : __assert_fail ("req->type == AST_REQ", "source/ast.c", 169, __extension__ __PRETTY_FUNCTION__));
    return req->value.text;
}

canonical_original_code:
char *require_name(struct AST *req)
{
    ((req != ((void *)0)) ? (void) (0) : __assert_fail ("req != NULL", "source/ast.c", 168, __extension__ __PRETTY_FUNCTION__));
    ((req->type == AST_REQ) ? (void) (0) : __assert_fail ("req->type == AST_REQ", "source/ast.c", 169, __extension__ __PRETTY_FUNCTION__));
    return req->value.text;
}


decompiled_code:
__int64 __fastcall def_name(__int64 a1)
{
if ( !a1 )
_assert_fail("def != NULL", "source/ast.c", 0xB7u, "def_name");
if ( *(_DWORD *)a1 != 8 )
_assert_fail("def->type == AST_DEF", "source/ast.c", 0xB8u, "def_name");
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1)
{
if ( !a1 )
_assert_fail("def != NULL", "source/ast.c", 0xB7u, "def_name");
if ( *(_DWORD *)a1 != 8 )
_assert_fail("def->type == AST_DEF", "source/ast.c", 0xB8u, "def_name");
return *(_QWORD *)(a1 + 8);
}

original_code:
char* def_name(AST* def)
{
    ((def != ((void *)0)) ? (void) (0) : __assert_fail ("def != NULL", "source/ast.c", 183, __extension__ __PRETTY_FUNCTION__));
    ((def->type == AST_DEF) ? (void) (0) : __assert_fail ("def->type == AST_DEF", "source/ast.c", 184, __extension__ __PRETTY_FUNCTION__));
    return def->value.def.name;
}

canonical_original_code:
char *def_name(struct AST *def)
{
    ((def != ((void *)0)) ? (void) (0) : __assert_fail ("def != NULL", "source/ast.c", 183, __extension__ __PRETTY_FUNCTION__));
    ((def->type == AST_DEF) ? (void) (0) : __assert_fail ("def->type == AST_DEF", "source/ast.c", 184, __extension__ __PRETTY_FUNCTION__));
    return def->value.def.name;
}


decompiled_code:
__int64 __fastcall def_value(__int64 a1)
{
if ( !a1 )
_assert_fail("def != NULL", "source/ast.c", 0xBEu, "def_value");
if ( *(_DWORD *)a1 != 8 )
_assert_fail("def->type == AST_DEF", "source/ast.c", 0xBFu, "def_value");
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1)
{
if ( !a1 )
_assert_fail("def != NULL", "source/ast.c", 0xBEu, "def_value");
if ( *(_DWORD *)a1 != 8 )
_assert_fail("def->type == AST_DEF", "source/ast.c", 0xBFu, "def_value");
return *(_QWORD *)(a1 + 24);
}

original_code:
AST* def_value(AST* def)
{
    ((def != ((void *)0)) ? (void) (0) : __assert_fail ("def != NULL", "source/ast.c", 190, __extension__ __PRETTY_FUNCTION__));
    ((def->type == AST_DEF) ? (void) (0) : __assert_fail ("def->type == AST_DEF", "source/ast.c", 191, __extension__ __PRETTY_FUNCTION__));
    return def->value.def.value;
}

canonical_original_code:
struct AST *def_value(struct AST *def)
{
    ((def != ((void *)0)) ? (void) (0) : __assert_fail ("def != NULL", "source/ast.c", 190, __extension__ __PRETTY_FUNCTION__));
    ((def->type == AST_DEF) ? (void) (0) : __assert_fail ("def->type == AST_DEF", "source/ast.c", 191, __extension__ __PRETTY_FUNCTION__));
    return def->value.def.value;
}

variable_types:
def
struct AST *


IfExpr

decompiled_code:
_OWORD *IfExpr()
{
return ast(9);
}

canonical_decompiled_code:
_OWORD *func12()
{
return ast(9);
}

original_code:
AST* IfExpr(void)
{
    return ast(AST_IF);
}

canonical_original_code:
struct AST *IfExpr()
{
    return ast(AST_IF);
}


decompiled_code:
__int64 __fastcall ifexpr_cond(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
AST* ifexpr_cond(AST* ifexpr)
{
    return ifexpr->value.ifexpr.cond;
}

canonical_original_code:
struct AST *ifexpr_cond(struct AST *ifexpr)
{
    return ifexpr->value.ifexpr.cond;
}

variable_types:
ifexpr
struct AST *


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

result = gc_addref(a2);
*(_QWORD *)(a1 + 8) = result;
return result;
}

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

result = gc_addref(a2);
*(_QWORD *)(a1 + 8) = result;
return result;
}

original_code:
void ifexpr_set_cond(AST* ifexpr, AST* cond)
{
    ifexpr->value.ifexpr.cond = (AST*)gc_addref(cond);
}

canonical_original_code:
void ifexpr_set_cond(struct AST *ifexpr, struct AST *cond)
{
    ifexpr->value.ifexpr.cond = (struct AST *)gc_addref(cond);
}

variable_types:
cond
struct AST *


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

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

original_code:
AST* ifexpr_then(AST* ifexpr)
{
    return ifexpr->value.ifexpr.bthen;
}

canonical_original_code:
struct AST *ifexpr_then(struct AST *ifexpr)
{
    return ifexpr->value.ifexpr.bthen;
}


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

result = gc_addref(a2);
*(_QWORD *)(a1 + 16) = result;
return result;
}

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

result = gc_addref(a2);
*(_QWORD *)(a1 + 16) = result;
return result;
}

original_code:
void ifexpr_set_then(AST* ifexpr, AST* bthen)
{
    ifexpr->value.ifexpr.bthen = (AST*)gc_addref(bthen);
}

canonical_original_code:
void ifexpr_set_then(struct AST *ifexpr, struct AST *bthen)
{
    ifexpr->value.ifexpr.bthen = (struct AST *)gc_addref(bthen);
}

variable_types:
bthen
struct AST *


decompiled_code:
__int64 __fastcall ifexpr_else(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

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

original_code:
AST* ifexpr_else(AST* ifexpr)
{
    return ifexpr->value.ifexpr.belse;
}

canonical_original_code:
struct AST *ifexpr_else(struct AST *ifexpr)
{
    return ifexpr->value.ifexpr.belse;
}


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

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

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

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

original_code:
void ifexpr_set_else(AST* ifexpr, AST* belse)
{
    ifexpr->value.ifexpr.belse = (AST*)gc_addref(belse);
}

canonical_original_code:
void ifexpr_set_else(struct AST *ifexpr, struct AST *belse)
{
    ifexpr->value.ifexpr.belse = (struct AST *)gc_addref(belse);
}

variable_types:
belse
struct AST *


Func

decompiled_code:
_OWORD *Func()
{
_OWORD *v0; // r12
_OWORD *result; // rax

v0 = ast(10);
vec_init((char *)v0 + 8);
result = v0;
*((_QWORD *)v0 + 5) = 0LL;
return result;
}

canonical_decompiled_code:
_OWORD *func19()
{
_OWORD *v0; // r12
_OWORD *result; // rax

v0 = ast(10);
vec_init((char *)v0 + 8);
result = v0;
*((_QWORD *)v0 + 5) = 0LL;
return result;
}

original_code:
AST* Func(void)
{
    AST* node = ast(AST_FUNC);
    vec_init(&(node->value.func.args));
    node->value.func.body = ((void *)0);
    return node;
}

canonical_original_code:
struct AST *Func()
{
    struct AST *node = ast(AST_FUNC);
    vec_init(&(node->value.func.args));
    node->value.func.body = ((void *)0);
    return node;
}


decompiled_code:
__int64 __fastcall func_args(__int64 a1)
{
return a1 + 8;
}

canonical_decompiled_code:
__int64 __fastcall func20(__int64 a1)
{
return a1 + 8;
}

original_code:
vec_t* func_args(AST* func)
{
    return &(func->value.func.args);
}

canonical_original_code:
struct vec_t *func_args(struct AST *func)
{
    return &(func->value.func.args);
}

variable_types: struct AST { enum ASTType { AST_STRING=0, AST_SYMBOL=1, AST_CHAR=2, AST_INT=3, AST_FLOAT=4, AST_BOOL=5, AST_IDENT=6, AST_REQ=7, AST_DEF=8, AST_IF=9, AST_FUNC=10, AST_FNAPP=11, AST_LET=12, AST_TEMP=13 } type; union { struct { char *name; struct AST *type; struct AST *value; } def; struct { struct AST *cond; struct AST *bthen; struct AST *belse; } ifexpr; struct { struct vec_t args; struct AST *body; } func; struct { struct AST *fn; struct vec_t args; } fnapp; struct { struct AST *temp; struct AST *value; struct AST *body; } let; char *text; unsigned int character; long integer; double floating; _Bool boolean; } value; } *

return_type: struct vec_t { unsigned long count; unsigned long size; unsigned long capacity; void **buffer; } *


decompiled_code:
__int64 __fastcall func_body(__int64 a1)
{
return *(_QWORD *)(a1 + 40);
}

canonical_decompiled_code:
__int64 __fastcall func21(__int64 a1)
{
return *(_QWORD *)(a1 + 40);
}

original_code:
AST* func_body(AST* func)
{
    return func->value.func.body;
}

canonical_original_code:
struct AST *func_body(struct AST *func)
{
    return func->value.func.body;
}

variable_types:
func
struct AST *


decompiled_code:
__int64 __fastcall func_add_arg(__int64 a1, __int64 a2)
{
__int64 v2; // rsi
__int64 v3; // rax

v2 = gc_addref(a2);
v3 = func_args(a1);
return vec_push_back(v3, v2);
}

canonical_decompiled_code:
__int64 __fastcall func22(__int64 a1, __int64 a2)
{
__int64 v2; // rsi
__int64 v3; // rax

v2 = gc_addref(a2);
v3 = func20(a1);
return vec_push_back(v3, v2);
}

original_code:
void func_add_arg(AST* func, AST* arg)
{
    vec_push_back(func_args(func), gc_addref(arg));
}

canonical_original_code:
void func_add_arg(struct AST *func, struct AST *arg)
{
    vec_push_back(func_args(func), gc_addref(arg));
}

variable_types:
arg
struct AST *


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

result = gc_addref(a2);
*(_QWORD *)(a1 + 40) = result;
return result;
}

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

result = gc_addref(a2);
*(_QWORD *)(a1 + 40) = result;
return result;
}

original_code:
void func_set_body(AST* func, AST* body)
{
    func->value.func.body = (AST*)gc_addref(body);
}

canonical_original_code:
void func_set_body(struct AST *func, struct AST *body)
{
    func->value.func.body = (struct AST *)gc_addref(body);
}

variable_types:
body
struct AST *


decompiled_code:
__int64 __fastcall fnapp_set_fn(__int64 a1, __int64 a2)
{
__int64 v2; // rbp

v2 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = gc_addref(a2);
return gc_delref(v2);
}

canonical_decompiled_code:
__int64 __fastcall func24(__int64 a1, __int64 a2)
{
__int64 v2; // rbp

v2 = *(_QWORD *)(a1 + 8);
*(_QWORD *)(a1 + 8) = gc_addref(a2);
return gc_delref(v2);
}

original_code:
void fnapp_set_fn(AST* fnapp, AST* fn)
{
    AST* old = fnapp->value.fnapp.fn;
    fnapp->value.fnapp.fn = (AST*)gc_addref(fn);
    gc_delref(old);
}

canonical_original_code:
void fnapp_set_fn(struct AST *fnapp, struct AST *fn)
{
    struct AST *old = fnapp->value.fnapp.fn;
    fnapp->value.fnapp.fn = (struct AST *)gc_addref(fn);
    gc_delref(old);
}

variable_types:
fn
struct AST *


decompiled_code:
__int64 __fastcall fnapp_fn(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func25(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
AST* fnapp_fn(AST* fnapp)
{
    return fnapp->value.fnapp.fn;
}

canonical_original_code:
struct AST *fnapp_fn(struct AST *fnapp)
{
    return fnapp->value.fnapp.fn;
}

variable_types:
fnapp
struct AST *


decompiled_code:
__int64 __fastcall fnapp_args(__int64 a1)
{
return a1 + 16;
}

canonical_decompiled_code:
__int64 __fastcall func26(__int64 a1)
{
return a1 + 16;
}

original_code:
vec_t* fnapp_args(AST* fnapp)
{
    return &(fnapp->value.fnapp.args);
}

canonical_original_code:
struct vec_t *fnapp_args(struct AST *fnapp)
{
    return &(fnapp->value.fnapp.args);
}


decompiled_code:
__int64 __fastcall fnapp_add_arg(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = gc_addref(a2);
return vec_push_back(a1 + 16, v2);
}

canonical_decompiled_code:
__int64 __fastcall func27(__int64 a1, __int64 a2)
{
__int64 v2; // rax

v2 = gc_addref(a2);
return vec_push_back(a1 + 16, v2);
}

original_code:
void fnapp_add_arg(AST* fnapp, AST* arg)
{
    vec_push_back(&(fnapp->value.fnapp.args), gc_addref(arg));
}

canonical_original_code:
void fnapp_add_arg(struct AST *fnapp, struct AST *arg)
{
    vec_push_back(&(fnapp->value.fnapp.args), gc_addref(arg));
}


decompiled_code:
__int64 __fastcall let_var(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

canonical_decompiled_code:
__int64 __fastcall func28(__int64 a1)
{
return *(_QWORD *)(a1 + 8);
}

original_code:
AST* let_var(AST* let)
{
    return let->value.let.temp;
}

canonical_original_code:
struct AST *let_var(struct AST *let)
{
    return let->value.let.temp;
}

variable_types:
let
struct AST *


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

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

original_code:
AST* let_val(AST* let)
{
    return let->value.let.value;
}

canonical_original_code:
struct AST *let_val(struct AST *let)
{
    return let->value.let.value;
}


decompiled_code:
__int64 __fastcall let_body(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

canonical_decompiled_code:
__int64 __fastcall func30(__int64 a1)
{
return *(_QWORD *)(a1 + 24);
}

original_code:
AST* let_body(AST* let)
{
    return let->value.let.body;
}

canonical_original_code:
struct AST *let_body(struct AST *let)
{
    return let->value.let.body;
}


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

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

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

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

original_code:
void let_set_body(AST* let, AST* body)
{
    let->value.let.body = (AST*)gc_addref(body);
}

canonical_original_code:
void let_set_body(struct AST *let, struct AST *body)
{
    let->value.let.body = (struct AST *)gc_addref(body);
}


TempVar

decompiled_code:
_OWORD *TempVar()
{
_OWORD *result; // rax
__int64 v1; // rcx

result = ast(13);
v1 = val_0 + 1;
*((_QWORD *)result + 1) = val_0;
val_0 = v1;
return result;
}

canonical_decompiled_code:
_OWORD *func32()
{
_OWORD *result; // rax
__int64 v1; // rcx

result = ast(13);
v1 = val_0 + 1;
*((_QWORD *)result + 1) = val_0;
val_0 = v1;
return result;
}

original_code:
AST* TempVar(void)
{
    static intptr_t val = 0;
    AST* node = ast(AST_TEMP);
    node->value.integer = val++;
    return node;
}

canonical_original_code:
struct AST *TempVar()
{
    static long val = 0;
    struct AST *node = ast(AST_TEMP);
    node->value.integer = val++;
    return node;
}

variable_types: val long


decompiled_code:
__int64 __fastcall normalize_fnapp(__int64 a1)
{
__int64 v1; // r12
unsigned int *v2; // r13
unsigned __int64 v3; // rbx
__int64 v4; // r13
unsigned int *v5; // rbp
__int64 v6; // r14
__int64 v7; // rax
int v8; // eax
__int64 v9; // rbx
__int64 v10; // r13
__int64 v11; // rsi
__int64 v12; // rax
__int64 v13; // rsi
__int64 v15; // r12
_BYTE v16[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = a1;
v2 = (unsigned int *)fnapp_fn();
if ( !isatomic_isra_0(*v2) )
{
v15 = TempVar();
fnapp_set_fn(a1, v15);
v1 = Let(v15, v2, a1);
}
v3 = 0LL;
vec_init(v16);
v4 = fnapp_args(a1);
while ( vec_size(v4) > v3 )
{
v5 = (unsigned int *)vec_at(v4, v3);
if ( !isatomic_isra_0(*v5) )
{
v6 = TempVar();
v7 = Let(v6, v5, 0LL);
vec_push_back(v16, v7);
vec_set(v4, v3, v6);
}
++v3;
}
v8 = vec_size(v16);
if ( v8 > 0 )
{
v9 = v8 - 1LL;
v10 = v8 - 2LL - (unsigned int)(v8 - 1);
do
{
v11 = v9--;
v12 = vec_at(v16, v11);
v13 = v1;
v1 = v12;
let_set_body(v12, v13);
}
while ( v9 != v10 );
}
vec_deinit(v16);
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1)
{
__int64 v1; // r12
unsigned int *v2; // r13
unsigned __int64 v3; // rbx
__int64 v4; // r13
unsigned int *v5; // rbp
__int64 v6; // r14
__int64 v7; // rax
int v8; // eax
__int64 v9; // rbx
__int64 v10; // r13
__int64 v11; // rsi
__int64 v12; // rax
__int64 v13; // rsi
__int64 v15; // r12
_BYTE v16[72]; // [rsp+0h] [rbp-48h] BYREF

v1 = a1;
v2 = (unsigned int *)fnapp_fn();
if ( !func0(*v2) )
{
v15 = TempVar();
fnapp_set_fn(a1, v15);
v1 = Let(v15, v2, a1);
}
v3 = 0LL;
vec_init(v16);
v4 = fnapp_args(a1);
while ( vec_size(v4) > v3 )
{
v5 = (unsigned int *)vec_at(v4, v3);
if ( !func0(*v5) )
{
v6 = TempVar();
v7 = Let(v6, v5, 0LL);
vec_push_back(v16, v7);
vec_set(v4, v3, v6);
}
++v3;
}
v8 = vec_size(v16);
if ( v8 > 0 )
{
v9 = v8 - 1LL;
v10 = v8 - 2LL - (unsigned int)(v8 - 1);
do
{
v11 = v9--;
v12 = vec_at(v16, v11);
v13 = v1;
v1 = v12;
let_set_body(v12, v13);
}
while ( v9 != v10 );
}
vec_deinit(v16);
return v1;
}

original_code:
static AST* normalize_fnapp(AST* tree)
{
    AST* normalized = tree;
    AST* fn = fnapp_fn(tree);
    if (!isatomic(fn)) {
        AST* temp = TempVar();
        fnapp_set_fn(tree, temp);
        normalized = Let(temp, fn, tree);
    }
    vec_t temps;
    vec_init(&temps);
    vec_t* args = fnapp_args(tree);
    for (int i = 0; i < vec_size(args); i++) {
        AST* arg = (AST*)vec_at(args, i);
        if (!isatomic(arg)) {
            AST* temp = TempVar();
            vec_push_back(&temps, Let(temp, arg, ((void *)0)));
            vec_set(args, i, temp);
        }
    }
    for (int i = vec_size(&temps); i > 0; i--) {
        AST* let = (AST*)vec_at(&temps,i-1);
        let_set_body(let, normalized);
        normalized = let;
    }
    vec_deinit(&temps);
    return normalized;
}

canonical_original_code:
static struct AST *normalize_fnapp(struct AST *tree)
{
    struct AST *normalized = tree;
    struct AST *fn = fnapp_fn(tree);
    if (!isatomic(fn)) {
        struct AST *temp = TempVar();
        fnapp_set_fn(tree, temp);
        normalized = Let(temp, fn, tree);
    }
    struct vec_t temps;
    vec_init(&temps);
    struct vec_t *args = fnapp_args(tree);
    for (int i = 0; i < vec_size(args); i++) {
        struct AST *arg = (AST*)vec_at(args, i);
        if (!isatomic(arg)) {
            struct AST *temp = TempVar();
            vec_push_back(&temps, Let(temp, arg, ((void *)0)));
            vec_set(args, i, temp);
        }
    }
    for (int i = vec_size(&temps); i > 0; i--) {
        struct AST *let = (AST*)vec_at(&temps,i-1);
        let_set_body(let, normalized);
        normalized = let;
    }
    vec_deinit(&temps);
    return normalized;
}

variable_types:
tree
struct AST *

variable_types: struct vec_t { unsigned long count; unsigned long size; unsigned long capacity; void **buffer; } *

variable_types: i int


isconst

decompiled_code:
__int64 __fastcall isconst(unsigned int *a1)
{
unsigned int v1; // eax
int v2; // edx
unsigned int v3; // er12
unsigned __int64 v5; // rbp
unsigned int *v6; // rax
unsigned int v7; // eax
__int64 v8; // rax
__int64 v9; // rax
unsigned int *v10; // rax
unsigned int v11; // eax

LOBYTE(v1) = isatomic_isra_0(*a1);
v3 = v1;
if ( !(_BYTE)v1 && v2 == 11 )
{
v5 = 0LL;
v6 = (unsigned int *)fnapp_fn(a1);
LOBYTE(v7) = isatomic_isra_0(*v6);
v3 = v7;
while ( 1 )
{
v8 = fnapp_args(a1);
if ( vec_size(v8) <= v5 )
break;
if ( (_BYTE)v3 )
{
v9 = fnapp_args(a1);
v10 = (unsigned int *)vec_at(v9, v5);
LOBYTE(v11) = isatomic_isra_0(*v10);
v3 = v11;
}
++v5;
}
}
return v3;
}

canonical_decompiled_code:
__int64 __fastcall func2(unsigned int *a1)
{
unsigned int v1; // eax
int v2; // edx
unsigned int v3; // er12
unsigned __int64 v5; // rbp
unsigned int *v6; // rax
unsigned int v7; // eax
__int64 v8; // rax
__int64 v9; // rax
unsigned int *v10; // rax
unsigned int v11; // eax

LOBYTE(v1) = func0(*a1);
v3 = v1;
if ( !(_BYTE)v1 && v2 == 11 )
{
v5 = 0LL;
v6 = (unsigned int *)fnapp_fn(a1);
LOBYTE(v7) = func0(*v6);
v3 = v7;
while ( 1 )
{
v8 = fnapp_args(a1);
if ( vec_size(v8) <= v5 )
break;
if ( (_BYTE)v3 )
{
v9 = fnapp_args(a1);
v10 = (unsigned int *)vec_at(v9, v5);
LOBYTE(v11) = func0(*v10);
v3 = v11;
}
++v5;
}
}
return v3;
}

original_code:
static _Bool isconst(AST* tree) {
    _Bool ret = isatomic(tree);
    if (!ret && tree->type == AST_FNAPP) {
        ret = isatomic(fnapp_fn(tree));
        for (int i = 0; i < vec_size(fnapp_args(tree)); i++) {
            ret = ret && isatomic(vec_at(fnapp_args(tree), i));
        }
    }
    return ret;
}

canonical_original_code:
static _Bool isconst(struct AST *tree) {
    _Bool ret = isatomic(tree);
    if (!ret && tree->type == AST_FNAPP) {
        ret = isatomic(fnapp_fn(tree));
        for (int i = 0; i < vec_size(fnapp_args(tree)); i++) {
            ret = ret && isatomic(vec_at(fnapp_args(tree), i));
        }
    }
    return ret;
}

variable_types: struct AST { enum ASTType { AST_STRING=0, AST_SYMBOL=1, AST_CHAR=2, AST_INT=3, AST_FLOAT=4, AST_BOOL=5, AST_IDENT=6, AST_REQ=7, AST_DEF=8, AST_IF=9, AST_FUNC=10, AST_FNAPP=11, AST_LET=12, AST_TEMP=13 } type; union { struct { char *name; struct AST *type; struct AST *value; } def; struct { struct AST *cond; struct AST *bthen; struct AST *belse; } ifexpr; struct { struct vec_t { unsigned long count; unsigned long size; unsigned long capacity; void **buffer; } args; struct AST *body; } func; struct { struct AST *fn; struct vec_t args; } fnapp; struct { struct AST *temp; struct AST *value; struct AST *body; } let; char *text; unsigned int character; long integer; double floating; _Bool boolean; } value; } *


normalize

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

if ( !a1 )
return 0LL;
switch ( *(_DWORD *)a1 )
{
case 8:
result = normalize_def();
break;
case 9:
result = normalize_if();
break;
case 0xA:
result = normalize_func();
break;
case 0xB:
result = normalize_fnapp(a1);
break;
case 0xC:
result = normalize_let();
break;
default:
JUMPOUT(0x44ALL);
}
return result;
}

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

if ( !a1 )
return 0LL;
switch ( *(_DWORD *)a1 )
{
case 8:
result = func4();
break;
case 9:
result = func5();
break;
case 0xA:
result = func6();
break;
case 0xB:
result = func1(a1);
break;
case 0xC:
result = func7();
break;
default:
JUMPOUT(0x44ALL);
}
return result;
}

original_code:
AST* normalize(AST* tree)
{
    if (((void *)0) == tree)
        return tree;
    switch (tree->type)
    {
        case AST_DEF: tree = normalize_def(tree); break;
        case AST_FNAPP: tree = normalize_fnapp(tree); break;
        case AST_IF: tree = normalize_if(tree); break;
        case AST_FUNC: tree = normalize_func(tree); break;
        case AST_LET: tree = normalize_let(tree); break;
        default: break;
    }
    return tree;
}

canonical_original_code:
struct AST *normalize(struct AST *tree)
{
    if (((void *)0) == tree)
        return tree;
    switch (tree->type)
    {
        case AST_DEF: tree = normalize_def(tree); break;
        case AST_FNAPP: tree = normalize_fnapp(tree); break;
        case AST_IF: tree = normalize_if(tree); break;
        case AST_FUNC: tree = normalize_func(tree); break;
        case AST_LET: tree = normalize_let(tree); break;
        default: break;
    }
    return tree;
}


original_code:
static AST* normalize_def(AST* tree)
{
    Tok name = { .value.text = def_name(tree) };
    return Def(&name, normalize(def_value(tree)));
}

canonical_original_code:
static struct AST *normalize_def(struct AST *tree)
{
    struct Tok name = { .value.text = def_name(tree) };
    return Def(&name, normalize(def_value(tree)));
}

variable_types: struct Tok { char *file; unsigned long line; unsigned long col; enum TokType { T_ID=0, T_CHAR=1, T_INT=2, T_FLOAT=3, T_BOOL=4, T_STRING=5, T_LBRACE=6, T_RBRACE=7, T_LBRACK=8, T_RBRACK=9, T_LPAR=10, T_RPAR=11, T_COMMA=12, T_SQUOTE=13, T_DQUOTE=14, T_END=15, T_COLON=16, T_AMP=17, T_REQUIRE=18, T_DEF=19, T_IF=20, T_FN=21, T_THEN=22, T_ELSE=23, T_END_FILE=24 } type; union { char *text; unsigned int character; long integer; double floating; _Bool boolean; } value; }


decompiled_code:
__int64 __fastcall normalize_if(__int64 a1)
{
__int64 v1; // rax
unsigned int *v2; // r12
__int64 v3; // rax
__int64 v4; // r13
__int64 v5; // rax
__int64 v6; // rbp
__int64 v7; // r15
__int64 v8; // r14
__int64 result; // rax
__int64 v10; // r14

v1 = ifexpr_cond();
v2 = (unsigned int *)normalize(v1);
v3 = ifexpr_then(a1);
v4 = normalize(v3);
v5 = ifexpr_else(a1);
v6 = normalize(v5);
if ( isatomic_isra_0(*v2) )
{
v10 = IfExpr();
ifexpr_set_cond(v10, v2);
ifexpr_set_then(v10, v4);
ifexpr_set_else(v10, v6);
result = v10;
}
else
{
v7 = TempVar();
v8 = IfExpr();
ifexpr_set_cond(v8, v7);
ifexpr_set_then(v8, v4);
ifexpr_set_else(v8, v6);
result = Let(v7, v2, v8);
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func5(__int64 a1)
{
__int64 v1; // rax
unsigned int *v2; // r12
__int64 v3; // rax
__int64 v4; // r13
__int64 v5; // rax
__int64 v6; // rbp
__int64 v7; // r15
__int64 v8; // r14
__int64 result; // rax
__int64 v10; // r14

v1 = ifexpr_cond();
v2 = (unsigned int *)func3(v1);
v3 = ifexpr_then(a1);
v4 = func3(v3);
v5 = ifexpr_else(a1);
v6 = func3(v5);
if ( func0(*v2) )
{
v10 = IfExpr();
ifexpr_set_cond(v10, v2);
ifexpr_set_then(v10, v4);
ifexpr_set_else(v10, v6);
result = v10;
}
else
{
v7 = TempVar();
v8 = IfExpr();
ifexpr_set_cond(v8, v7);
ifexpr_set_then(v8, v4);
ifexpr_set_else(v8, v6);
result = Let(v7, v2, v8);
}
return result;
}

original_code:
static AST* normalize_if(AST* tree)
{
    AST* cond = normalize(ifexpr_cond(tree));
    AST* thenbr = normalize(ifexpr_then(tree));
    AST* elsebr = normalize(ifexpr_else(tree));
    if (!isatomic(cond)) {
        AST* temp = TempVar();
        AST* body = IfExpr();
        ifexpr_set_cond(body, temp);
        ifexpr_set_then(body, thenbr);
        ifexpr_set_else(body, elsebr);
        tree = Let(temp, cond, body);
    } else {
        tree = IfExpr();
        ifexpr_set_cond(tree, cond);
        ifexpr_set_then(tree, thenbr);
        ifexpr_set_else(tree, elsebr);
    }
    return tree;
}

canonical_original_code:
static struct AST *normalize_if(struct AST *tree)
{
    struct AST *cond = normalize(ifexpr_cond(tree));
    struct AST *thenbr = normalize(ifexpr_then(tree));
    struct AST *elsebr = normalize(ifexpr_else(tree));
    if (!isatomic(cond)) {
        struct AST *temp = TempVar();
        struct AST *body = IfExpr();
        ifexpr_set_cond(body, temp);
        ifexpr_set_then(body, thenbr);
        ifexpr_set_else(body, elsebr);
        tree = Let(temp, cond, body);
    } else {
        tree = IfExpr();
        ifexpr_set_cond(tree, cond);
        ifexpr_set_then(tree, thenbr);
        ifexpr_set_else(tree, elsebr);
    }
    return tree;
}


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

v1 = func_body();
v2 = normalize(v1);
func_set_body(a1, v2);
return a1;
}

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

v1 = func_body();
v2 = func3(v1);
func_set_body(a1, v2);
return a1;
}

original_code:
static AST* normalize_func(AST* tree)
{
    func_set_body(tree, normalize(func_body(tree)));
    return tree;
}

canonical_original_code:
static struct AST *normalize_func(struct AST *tree)
{
    func_set_body(tree, normalize(func_body(tree)));
    return tree;
}


decompiled_code:
unsigned __int64 __fastcall vec_next_capacity(__int64 a1)
{
unsigned __int64 v1; // rax
int v2; // edx
__int64 v3; // rcx
unsigned __int64 v4; // rsi

v1 = a1 - 1;
v2 = 6;
v3 = 1LL;
do
{
v4 = v1 >> v3;
v3 *= 2LL;
v1 |= v4;
--v2;
}
while ( v2 );
return v1 + 1;
}

canonical_decompiled_code:
unsigned __int64 __fastcall func0(__int64 a1)
{
unsigned __int64 v1; // rax
int v2; // edx
__int64 v3; // rcx
unsigned __int64 v4; // rsi

v1 = a1 - 1;
v2 = 6;
v3 = 1LL;
do
{
v4 = v1 >> v3;
v3 *= 2LL;
v1 |= v4;
--v2;
}
while ( v2 );
return v1 + 1;
}

original_code:
static size_t vec_next_capacity(size_t req_size)
{
    size_t next_power = req_size;
    size_t num_bits = sizeof(size_t) * 8;
    size_t bit_n;
    next_power--;
    for (bit_n = 1; bit_n < num_bits; bit_n = bit_n << 1)
    {
        next_power = next_power | (next_power >> bit_n);
    }
    next_power++;
    return next_power;
}

canonical_original_code:
static unsigned long vec_next_capacity(unsigned long req_size)
{
    unsigned long next_power = req_size;
    unsigned long num_bits = sizeof(size_t) * 8;
    unsigned long bit_n;
    next_power--;
    for (bit_n = 1; bit_n < num_bits; bit_n = bit_n << 1)
    {
        next_power = next_power | (next_power >> bit_n);
    }
    next_power++;
    return next_power;
}


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

if ( !a1 )
_assert_fail("vec != NULL", "source/vec.c", 0x24u, "vec_reserve");
result = realloc(*(void **)(a1 + 24), 8 * a2);
*(_QWORD *)(a1 + 24) = result;
if ( !result )
_assert_fail("vec->buffer != NULL", "source/vec.c", 0x26u, "vec_reserve");
*(_QWORD *)(a1 + 16) = a2;
return result;
}

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

if ( !a1 )
_assert_fail("vec != NULL", "source/vec.c", 0x24u, "vec_reserve");
result = realloc(*(void **)(a1 + 24), 8 * a2);
*(_QWORD *)(a1 + 24) = result;
if ( !result )
_assert_fail("vec->buffer != NULL", "source/vec.c", 0x26u, "vec_reserve");
*(_QWORD *)(a1 + 16) = a2;
return result;
}

original_code:
static void vec_reserve(vec_t* vec, size_t size)
{
    ((vec != ((void *)0)) ? (void) (0) : __assert_fail ("vec != NULL", "source/vec.c", 36, __extension__ __PRETTY_FUNCTION__));
    vec->buffer = realloc( vec->buffer, sizeof(void*) * size );
    ((vec->buffer != ((void *)0)) ? (void) (0) : __assert_fail ("vec->buffer != NULL", "source/vec.c", 38, __extension__ __PRETTY_FUNCTION__));
    vec->capacity = size;
}

canonical_original_code:
static void vec_reserve(struct vec_t *vec, unsigned long size)
{
    ((vec != ((void *)0)) ? (void) (0) : __assert_fail ("vec != NULL", "source/vec.c", 36, __extension__ __PRETTY_FUNCTION__));
    vec->buffer = realloc( vec->buffer, sizeof(void *) * size );
    ((vec->buffer != ((void *)0)) ? (void) (0) : __assert_fail ("vec->buffer != NULL", "source/vec.c", 38, __extension__ __PRETTY_FUNCTION__));
    vec->capacity = size;
}

variable_types:
size
unsigned long


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

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

original_code:
size_t vec_size(vec_t* vec)
{
    return vec->count;
}

canonical_original_code:
unsigned long vec_size(struct vec_t *vec)
{
    return vec->count;
}


decompiled_code:
__int64 __fastcall vec_at(unsigned __int64 *a1, unsigned __int64 a2)
{
if ( *a1 <= a2 )
_assert_fail("index < vec->count", "source/vec.c", 0x1Eu, "vec_at");
return *(_QWORD *)(a1[3] + 8 * a2);
}

canonical_decompiled_code:
__int64 __fastcall func5(unsigned __int64 *a1, unsigned __int64 a2)
{
if ( *a1 <= a2 )
_assert_fail("index < vec->count", "source/vec.c", 0x1Eu, "vec_at");
return *(_QWORD *)(a1[3] + 8 * a2);
}

original_code:
void* vec_at(vec_t* vec, size_t index)
{
    ((index < vec->count) ? (void) (0) : __assert_fail ("index < vec->count", "source/vec.c", 30, __extension__ __PRETTY_FUNCTION__));
    return vec->buffer[index];
}

canonical_original_code:
void *vec_at(struct vec_t *vec, unsigned long index)
{
    ((index < vec->count) ? (void) (0) : __assert_fail ("index < vec->count", "source/vec.c", 30, __extension__ __PRETTY_FUNCTION__));
    return vec->buffer[index];
}

variable_types:
index
unsigned long


decompiled_code:
__int64 __fastcall vec_set(unsigned __int64 *a1, unsigned __int64 a2, __int64 a3)
{
if ( *a1 <= a2 )
_assert_fail("index < vec->count", "source/vec.c", 0x4Bu, "vec_set");
return gc_swapref(a1[3] + 8 * a2, a3);
}

canonical_decompiled_code:
__int64 __fastcall func7(unsigned __int64 *a1, unsigned __int64 a2, __int64 a3)
{
if ( *a1 <= a2 )
_assert_fail("index < vec->count", "source/vec.c", 0x4Bu, "vec_set");
return gc_swapref(a1[3] + 8 * a2, a3);
}

original_code:
void vec_set(vec_t* vec, size_t index, void* data)
{
    ((index < vec->count) ? (void) (0) : __assert_fail ("index < vec->count", "source/vec.c", 75, __extension__ __PRETTY_FUNCTION__));
    gc_swapref((void**)&(vec->buffer[index]), data);
}

canonical_original_code:
void vec_set(struct vec_t *vec, unsigned long index, void *data)
{
    ((index < vec->count) ? (void) (0) : __assert_fail ("index < vec->count", "source/vec.c", 75, __extension__ __PRETTY_FUNCTION__));
    gc_swapref((void **)&(vec->buffer[index]), data);
}

variable_types:
data
void *


decompiled_code:
__int64 __fastcall vec_clear(unsigned __int64 *a1)
{
unsigned __int64 v2; // rbx
__int64 v3; // rdi
__int64 result; // rax

if ( *a1 )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(a1[3] + 8 * v2++);
result = gc_delref(v3);
}
while ( *a1 > v2 );
}
*a1 = 0LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(unsigned __int64 *a1)
{
unsigned __int64 v2; // rbx
__int64 v3; // rdi
__int64 result; // rax

if ( *a1 )
{
v2 = 0LL;
do
{
v3 = *(_QWORD *)(a1[3] + 8 * v2++);
result = gc_delref(v3);
}
while ( *a1 > v2 );
}
*a1 = 0LL;
return result;
}

original_code:
void vec_clear(vec_t* vec)
{
    for (size_t i = 0; i < vec->count; i++)
        gc_delref(vec->buffer[i]);
    vec->count = 0;
}

canonical_original_code:
void vec_clear(struct vec_t *vec)
{
    for (unsigned long i = 0; i < vec->count; i++)
        gc_delref(vec->buffer[i]);
    vec->count = 0;
}

variable_types:
i
unsigned long


decompiled_code:
void __fastcall vec_deinit(__int64 a1)
{
vec_clear((unsigned __int64 *)a1);
free(*(void **)(a1 + 24));
}

canonical_decompiled_code:
void __fastcall func9(__int64 a1)
{
func8((unsigned __int64 *)a1);
free(*(void **)(a1 + 24));
}

original_code:
void vec_deinit(vec_t* vec)
{
    vec_clear(vec);
    free(vec->buffer);
}

canonical_original_code:
void vec_deinit(struct vec_t *vec)
{
    vec_clear(vec);
    free(vec->buffer);
}


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

result = "???";
if ( a1 <= 0x18 )
result = (const char *)*(&CSWTCH_3 + a1);
return result;
}

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

result = "???";
if ( a1 <= 0x18 )
result = (const char *)*(&CSWTCH_3 + a1);
return result;
}

original_code:
static const char* token_type_to_string(TokType type) {
    switch(type) {
        case T_STRING: return "T_STRING";
        case T_CHAR: return "T_CHAR";
        case T_INT: return "T_INT";
        case T_FLOAT: return "T_FLOAT";
        case T_BOOL: return "T_BOOL";
        case T_LBRACE: return "T_LBRACE";
        case T_RBRACE: return "T_RBRACE";
        case T_LBRACK: return "T_LBRACK";
        case T_RBRACK: return "T_RBRACK";
        case T_LPAR: return "T_LPAR";
        case T_RPAR: return "T_RPAR";
        case T_COMMA: return "T_COMMA";
        case T_ID: return "T_ID";
        case T_END: return "T_END";
        case T_COLON: return "T_COLON";
        case T_AMP: return "T_AMP";
        case T_SQUOTE: return "T_SQUOTE";
        case T_DQUOTE: return "T_DQUOTE";
        case T_END_FILE: return "T_END_FILE";
        default: return "???";
    }
}

canonical_original_code:
static char *token_type_to_string(enum TokType type) {
    switch(type) {
        case T_STRING: return "T_STRING";
        case T_CHAR: return "T_CHAR";
        case T_INT: return "T_INT";
        case T_FLOAT: return "T_FLOAT";
        case T_BOOL: return "T_BOOL";
        case T_LBRACE: return "T_LBRACE";
        case T_RBRACE: return "T_RBRACE";
        case T_LBRACK: return "T_LBRACK";
        case T_RBRACK: return "T_RBRACK";
        case T_LPAR: return "T_LPAR";
        case T_RPAR: return "T_RPAR";
        case T_COMMA: return "T_COMMA";
        case T_ID: return "T_ID";
        case T_END: return "T_END";
        case T_COLON: return "T_COLON";
        case T_AMP: return "T_AMP";
        case T_SQUOTE: return "T_SQUOTE";
        case T_DQUOTE: return "T_DQUOTE";
        case T_END_FILE: return "T_END_FILE";
        default: return "???";
    }
}

variable_types: enum TokType { T_ID=0, T_CHAR=1, T_INT=2, T_FLOAT=3, T_BOOL=4, T_STRING=5, T_LBRACE=6, T_RBRACE=7, T_LBRACK=8, T_RBRACK=9, T_LPAR=10, T_RPAR=11, T_COMMA=12, T_SQUOTE=13, T_DQUOTE=14, T_END=15, T_COLON=16, T_AMP=17, T_REQUIRE=18, T_DEF=19, T_IF=20, T_FN=21, T_THEN=22, T_ELSE=23, T_END_FILE=24 }


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

result = "???";
if ( a1 <= 0xD )
result = (const char *)*(&CSWTCH_5 + a1);
return result;
}

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

result = "???";
if ( a1 <= 0xD )
result = (const char *)*(&CSWTCH_5 + a1);
return result;
}

original_code:
static const char* tree_type_to_string(ASTType type) {
    switch(type) {
        case AST_STRING: return "T_STRING";
        case AST_SYMBOL: return "T_SYMBOL";
        case AST_IDENT: return "T_ID";
        case AST_CHAR: return "T_CHAR";
        case AST_INT: return "T_INT";
        case AST_FLOAT: return "T_FLOAT";
        case AST_BOOL: return "T_BOOL";
        case AST_TEMP: return "$";
        default: return "???";
    }
}

canonical_original_code:
static char *tree_type_to_string(enum ASTType type) {
    switch(type) {
        case AST_STRING: return "T_STRING";
        case AST_SYMBOL: return "T_SYMBOL";
        case AST_IDENT: return "T_ID";
        case AST_CHAR: return "T_CHAR";
        case AST_INT: return "T_INT";
        case AST_FLOAT: return "T_FLOAT";
        case AST_BOOL: return "T_BOOL";
        case AST_TEMP: return "$";
        default: return "???";
    }
}

variable_types: enum ASTType { AST_STRING=0, AST_SYMBOL=1, AST_CHAR=2, AST_INT=3, AST_FLOAT=4, AST_BOOL=5, AST_IDENT=6, AST_REQ=7, AST_DEF=8, AST_IF=9, AST_FUNC=10, AST_FNAPP=11, AST_LET=12, AST_TEMP=13 }


decompiled_code:
__int64 emit_staticlib()
{
return 0LL;
}

canonical_decompiled_code:
__int64 func0()
{
return 0LL;
}

original_code:
static int emit_staticlib(void) {
    return 0;
}

canonical_original_code:
static int emit_staticlib() {
    return 0;
}


usage

decompiled_code:
void __noreturn usage()
{
fprintf(
stderr,
"%s\n",
"Usage: sclpl [options...] [-A artifact] [file...]\n"
"\n"
"-A<artifact> Emit the given type of artifact\n"
"-h Print help information\n"
"-v Enable verbose status messages");
exit(1);
}

canonical_decompiled_code:
void __noreturn func5()
{
fprintf(
stderr,
"%s\n",
"Usage: sclpl [options...] [-A artifact] [file...]\n"
"\n"
"-A<artifact> Emit the given type of artifact\n"
"-h Print help information\n"
"-v Enable verbose status messages");
exit(1);
}

original_code:
void usage(void) {
    fprintf(stderr, "%s\n",
        "Usage: sclpl [options...] [-A artifact] [file...]\n"
        "\n-A<artifact> Emit the given type of artifact"
        "\n-h           Print help information"
        "\n-v           Enable verbose status messages");
    exit(1);
}

canonical_original_code:
void usage() {
    fprintf(stderr, "%s\n",
        "Usage: sclpl [options...] [-A artifact] [file...]\n"
        "\n-A<artifact> Emit the given type of artifact"
        "\n-h           Print help information"
        "\n-v           Enable verbose status messages");
    exit(1);
}


original_code:
int user_main(int argc, char **argv) {
    for ( ARGV0 = *argv, argc--, argv++; argv[0] && argv[0][1] && argv[0][0] == '-'; argc--, argv++ ) { int brk_; char argc_ , **argv_, *optarg_; if (argv[0][1] == '-' && !argv[0][2]) { argv++, argc--; break; } for (brk_=0, argv[0]++, argv_=argv; argv[0][0] && !brk_; argv[0]++) { if (argv_ != argv) break; argc_ = argv[0][0]; switch (argc_) {
        case 'A': Artifact = (optarg_ = __getopt(&argc,&argv), (!optarg_ ? ((usage()), abort(), (char*)0) : (brk_ = 1, optarg_))); break;
        case 'v': Verbose = 1; break;
        default: usage();
    } }};
    if (0 == strcmp("tok", Artifact)) {
        return emit_tokens();
    } else if (0 == strcmp("ast", Artifact)) {
        return emit_ast();
    } else if (0 == strcmp("anf", Artifact)) {
        return emit_anf();
    } else if (0 == strcmp("src", Artifact)) {
        return emit_csource();
    } else if (0 == strcmp("bin", Artifact)) {
        return emit_program();
    } else if (0 == strcmp("lib", Artifact)) {
        return emit_staticlib();
    } else {
        fprintf(stderr, "Unknonwn artifact type: '%s'\n\n", Artifact);
        usage();
    }
    return 1;
}

canonical_original_code:
int user_main(int argc, char **argv) {
    for ( ARGV0 = *argv, argc--, argv++; argv[0] && argv[0][1] && argv[0][0] == '-'; argc--, argv++ ) { int brk_; char argc_; char **argv_; char *optarg_; if (argv[0][1] == '-' && !argv[0][2]) { argv++, argc--; break; } for (brk_=0, argv[0]++, argv_=argv; argv[0][0] && !brk_; argv[0]++) { if (argv_ != argv) break; argc_ = argv[0][0]; switch (argc_) {
        case 'A': Artifact = (optarg_ = __getopt(&argc,&argv), (!optarg_ ? ((usage()), abort(), (char *)0) : (brk_ = 1, optarg_))); break;
        case 'v': Verbose = 1; break;
        default: usage();
    } }};
    if (0 == strcmp("tok", Artifact)) {
        return emit_tokens();
    } else if (0 == strcmp("ast", Artifact)) {
        return emit_ast();
    } else if (0 == strcmp("anf", Artifact)) {
        return emit_anf();
    } else if (0 == strcmp("src", Artifact)) {
        return emit_csource();
    } else if (0 == strcmp("bin", Artifact)) {
        return emit_program();
    } else if (0 == strcmp("lib", Artifact)) {
        return emit_staticlib();
    } else {
        fprintf(stderr, "Unknonwn artifact type: '%s'\n\n", Artifact);
        usage();
    }
    return 1;
}

variable_types: argc int

variable_types:
argv
char **


repo: mikedlowis/libcds

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

result = exn_assert("source/list/list.c", 177LL, a1 != 0LL, "NULL != list");
if ( *a1 )
result = mem_release();
return result;
}

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

result = exn_assert("source/list/list.c", 177LL, a1 != 0LL, "NULL != list");
if ( *a1 )
result = mem_release();
return result;
}

original_code:
static void list_free(void* p_list)
{
    list_t* list = (list_t*)p_list;
    exn_assert("source/list/list.c",177,((void *)0) != list,"NULL != list");
    if (((void *)0) != list->head)
        mem_release(list->head);
}

canonical_original_code:
static void list_free(void *p_list)
{
    struct list_t *list = (list_t*)p_list;
    exn_assert("source/list/list.c",177,((void *)0) != list,"NULL != list");
    if (((void *)0) != list->head)
        mem_release(list->head);
}

variable_types: struct list_t { struct list_node_t { void *contents; struct list_node_t *next; struct list_node_t *prev; } *head; struct list_node_t *tail; } *

user_defined_types: struct list_t { struct list_node_t *head; struct list_node_t *tail; }


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

result = exn_assert("source/list/list.c", 185LL, a1 != 0LL, "NULL != node");
if ( *a1 )
result = mem_release();
if ( a1[1] )
result = mem_release();
return result;
}

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

result = exn_assert("source/list/list.c", 185LL, a1 != 0LL, "NULL != node");
if ( *a1 )
result = mem_release();
if ( a1[1] )
result = mem_release();
return result;
}

original_code:
static void list_node_free(void* p_node)
{
    list_node_t* node = (list_node_t*)p_node;
    exn_assert("source/list/list.c",185,((void *)0) != node,"NULL != node");
    if (((void *)0) != node->contents)
        mem_release(node->contents);
    if (((void *)0) != node->next)
        mem_release(node->next);
}

canonical_original_code:
static void list_node_free(void *p_node)
{
    struct list_node_t *node = (list_node_t*)p_node;
    exn_assert("source/list/list.c",185,((void *)0) != node,"NULL != node");
    if (((void *)0) != node->contents)
        mem_release(node->contents);
    if (((void *)0) != node->next)
        mem_release(node->next);
}

variable_types: struct list_node_t { void *contents; struct list_node_t *next; struct list_node_t *prev; } *


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

result = (_QWORD *)mem_allocate(16LL, list_free);
*result = 0LL;
result[1] = 0LL;
return result;
}

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

result = (_QWORD *)mem_allocate(16LL, list_free);
*result = 0LL;
result[1] = 0LL;
return result;
}

original_code:
list_t* list_new(void)
{
    list_t* list = (list_t*)mem_allocate(sizeof(list_t), &list_free);
    list->head = ((void *)0);
    list->tail = ((void *)0);
    return list;
}

canonical_original_code:
struct list_t *list_new()
{
    struct list_t *list = (list_t*)mem_allocate(sizeof(list_t), &list_free);
    list->head = ((void *)0);
    list->tail = ((void *)0);
    return list;
}

return_type: struct list_t { struct list_node_t { void *contents; struct list_node_t *next; struct list_node_t *prev; } *head; struct list_node_t *tail; } *


decompiled_code:
__int64 __fastcall list_front(__int64 a1)
{
exn_assert("source/list/list.c", 29LL, a1 != 0, "NULL != list");
return *(_QWORD *)a1;
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
exn_assert("source/list/list.c", 29LL, a1 != 0, "NULL != list");
return *(_QWORD *)a1;
}

original_code:
list_node_t* list_front( list_t* list )
{
    exn_assert("source/list/list.c",29,((void *)0) != list,"NULL != list");
    return list->head;
}

canonical_original_code:
struct list_node_t *list_front(struct list_t *list)
{
    exn_assert("source/list/list.c",29,((void *)0) != list,"NULL != list");
    return list->head;
}

variable_types: struct list_t { struct list_node_t *head; struct list_node_t *tail; } *

return_type: struct list_node_t { void *contents; struct list_node_t *next; struct list_node_t *prev; } *