repsizebeat

decompiled_code:
__int64 repsizebeat()
{
return 1LL;
}

canonical_decompiled_code:
__int64 func12()
{
return 1LL;
}

original_code:
size_t
repsizebeat(KBeat *kbeat)
{
    return 1;
}

canonical_original_code:
unsigned long repsizebeat(struct KBeat *kbeat)
{
    return 1;
}

variable_types: struct KBeat { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } type; int value; } *


repsizeblist

repo: lecram/kibibeat

decompiled_code:
__int64 __fastcall repsizeblist(__int64 a1)
{
return *(unsigned int *)(a1 + 4) + 2LL;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1)
{
return *(unsigned int *)(a1 + 4) + 2LL;
}

original_code:
size_t
repsizeblist(KBlist *kblist)
{
    return (size_t) kblist->length + 2;
}

canonical_original_code:
unsigned long repsizeblist(struct KBlist *kblist)
{
    return (unsigned long) kblist->length + 2;
}

variable_types: struct KBlist { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } type; unsigned int length; struct KBnode { int beat; struct KBnode *next; } *first; struct KBnode *last; } *

return_type: unsigned long

user_defined_types: struct KBlist { enum Kob type; unsigned int length; struct KBnode *first; struct KBnode *last; }


repsizename

decompiled_code:
size_t __fastcall repsizename(__int64 a1)
{
return strlen((const char *)(a1 + 4)) + 1;
}

canonical_decompiled_code:
size_t __fastcall func14(__int64 a1)
{
return strlen((const char *)(a1 + 4)) + 1;
}

original_code:
size_t
repsizename(KName *kname)
{
    return strlen(kname->name) + 1;
}

canonical_original_code:
unsigned long repsizename(struct KName *kname)
{
    return strlen(kname->name) + 1;
}

variable_types: struct KName { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } type; char name[32]; } *

user_defined_types: struct KName { enum Kob type; char name[32]; }


repsizekob

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

v1 = *a1;
if ( *a1 == 3 )
return repsizeblist((__int64)a1);
if ( v1 > 3 )
{
if ( v1 == 4 )
result = repsizename((__int64)a1);
else
result = 0LL;
}
else if ( v1 == 1 )
{
result = repsizenumber((__int64)a1);
}
else if ( v1 == 2 )
{
result = repsizebeat();
}
else
{
result = 0LL;
}
return result;
}

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

v1 = *a1;
if ( *a1 == 3 )
return func13((__int64)a1);
if ( v1 > 3 )
{
if ( v1 == 4 )
result = func14((__int64)a1);
else
result = 0LL;
}
else if ( v1 == 1 )
{
result = func11((__int64)a1);
}
else if ( v1 == 2 )
{
result = func12();
}
else
{
result = 0LL;
}
return result;
}

original_code:
size_t
repsizekob(Kob *kob)
{
    switch(*kob) {
        case T_NUMBER:
            return repsizenumber((KNumber *) kob);
        case T_BEAT:
            return repsizebeat((KBeat *) kob);
        case T_BLIST:
            return repsizeblist((KBlist *) kob);
        case T_NAME:
            return repsizename((KName *) kob);
        default:
            return 0;
    }
}

canonical_original_code:
unsigned long repsizekob(enum Kob *kob)
{
    switch(*kob) {
        case T_NUMBER:
            return repsizenumber((struct KNumber *) kob);
        case T_BEAT:
            return repsizebeat((struct KBeat *) kob);
        case T_BLIST:
            return repsizeblist((struct KBlist *) kob);
        case T_NAME:
            return repsizename((struct KName *) kob);
        default:
            return 0;
    }
}

variable_types: enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *

user_defined_types: struct KNumber { enum Kob type; unsigned int value; }

user_defined_types: struct KBeat { enum Kob type; int value; }

user_defined_types: struct KBnode { int beat; struct KBnode *next; }


repnumber

decompiled_code:
int __fastcall repnumber(__int64 a1, char *a2)
{
int result; // eax
double v4; // xmm0_8
unsigned __int64 v5; // rsi

result = *(_DWORD *)(a1 + 4);
if ( result )
{
v4 = log10((double)result);
if ( v4 >= 9.223372036854776e18 )
v5 = (unsigned int)(int)(v4 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
v5 = (unsigned int)(int)v4;
result = snprintf(a2, v5 + 2, "%u", *(unsigned int *)(a1 + 4));
}
else
{
*(_WORD *)a2 = 48;
}
return result;
}

canonical_decompiled_code:
int __fastcall func16(__int64 a1, char *a2)
{
int result; // eax
double v4; // xmm0_8
unsigned __int64 v5; // rsi

result = *(_DWORD *)(a1 + 4);
if ( result )
{
v4 = log10((double)result);
if ( v4 >= 9.223372036854776e18 )
v5 = (unsigned int)(int)(v4 - 9.223372036854776e18) ^ 0x8000000000000000LL;
else
v5 = (unsigned int)(int)v4;
result = snprintf(a2, v5 + 2, "%u", *(unsigned int *)(a1 + 4));
}
else
{
*(_WORD *)a2 = 48;
}
return result;
}

original_code:
void
repnumber(KNumber *knumber, char *buffer)
{
    size_t length;
    if (knumber->value == 0U) {
        strcpy(buffer, "0");
        return;
    }
    length = (size_t) log10((double) knumber->value) + 1;
    (void) snprintf(buffer, length + 1, "%u", knumber->value);
}

canonical_original_code:
void repnumber(struct KNumber *knumber, char *buffer)
{
    unsigned long length;
    if (knumber->value == 0U) {
        strcpy(buffer, "0");
        return;
    }
    length = (unsigned long) log10((double) knumber->value) + 1;
    (void) snprintf(buffer, length + 1, "%u", knumber->value);
}

variable_types: struct KNumber { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } type; unsigned int value; } *

variable_types:
buffer
char *

variable_types:
length
unsigned long

return_type: void


repname

decompiled_code:
char *__fastcall repname(__int64 a1, _BYTE *a2)
{
*a2 = 36;
return strcpy(a2 + 1, (const char *)(a1 + 4));
}

canonical_decompiled_code:
char *__fastcall func19(__int64 a1, _BYTE *a2)
{
*a2 = 36;
return strcpy(a2 + 1, (const char *)(a1 + 4));
}

original_code:
void
repname(KName *kname, char *buffer)
{
    *buffer = '$';
    buffer++;
    strcpy(buffer, kname->name);
}

canonical_original_code:
void repname(struct KName *kname, char *buffer)
{
    *buffer = '$';
    buffer++;
    strcpy(buffer, kname->name);
}

user_defined_types: enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 }


repkob

decompiled_code:
void __fastcall repkob(unsigned int *a1, char *a2)
{
unsigned int v2; // eax

v2 = *a1;
if ( *a1 == 3 )
{
repblist((__int64)a1, a2);
}
else if ( v2 > 3 )
{
if ( v2 == 4 )
repname((__int64)a1, a2);
}
else if ( v2 == 1 )
{
repnumber((__int64)a1, a2);
}
else if ( v2 == 2 )
{
repbeat((__int64)a1, a2);
}
}

original_code:
void
repkob(Kob *kob, char *buffer)
{
    switch(*kob) {
        case EMPTY:
            return;
        case T_NUMBER:
            repnumber((KNumber *) kob, buffer);
            break;
        case T_BEAT:
            repbeat((KBeat *) kob, buffer);
            break;
        case T_BLIST:
            repblist((KBlist *) kob, buffer);
            break;
        case T_NAME:
            repname((KName *) kob, buffer);
            break;
    }
}

canonical_original_code:
void repkob(enum Kob *kob, char *buffer)
{
    switch(*kob) {
        case EMPTY:
            return;
        case T_NUMBER:
            repnumber((struct KNumber *) kob, buffer);
            break;
        case T_BEAT:
            repbeat((struct KBeat *) kob, buffer);
            break;
        case T_BLIST:
            repblist((struct KBlist *) kob, buffer);
            break;
        case T_NAME:
            repname((struct KName *) kob, buffer);
            break;
    }
}


cpyname

decompiled_code:
char *__fastcall cpyname(__int64 a1)
{
return newname((char *)(a1 + 4));
}

canonical_decompiled_code:
char *__fastcall func21(__int64 a1)
{
return func1((char *)(a1 + 4));
}

original_code:
KName *
cpyname(KName *kname)
{
    return newname(kname->name);
}

canonical_original_code:
struct KName *cpyname(struct KName *kname)
{
    return newname(kname->name);
}

variable_types:
kname
struct KName *

return_type: struct KName { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } type; char name[32]; } *


original_code:
int
blist_insert(KBlist *kblist, int index, int value)
{
    KBnode *kbnode;
    if (index < 0)
        index += kblist->length;
    if (index < 0 || index > (int) kblist->length)
        return 0;
    else if (index == 0) {
        kbnode = newbnode(value);
        kbnode->next = kblist->first;
        kblist->first = kbnode;
        if (kblist->length == 0U)
            kblist->last = kbnode;
    }
    else if (index == (int) kblist->length) {
        kbnode = newbnode(value);
        kbnode->next = ((void *)0);
        kblist->last->next = kbnode;
        kblist->last = kbnode;
    }
    else {
        int curidx = 0;
        KBnode *prev = kblist->first;
        KBnode *next;
        while (curidx < index - 1) {
            prev = prev->next;
            curidx++;
        }
        next = prev->next;
        prev->next = newbnode(value);
        prev->next->next = next;
    }
    kblist->length++;
    return 1;
}

canonical_original_code:
int blist_insert(struct KBlist *kblist, int index, int value)
{
    struct KBnode *kbnode;
    if (index < 0)
        index += kblist->length;
    if (index < 0 || index > (int) kblist->length)
        return 0;
    else if (index == 0) {
        kbnode = newbnode(value);
        kbnode->next = kblist->first;
        kblist->first = kbnode;
        if (kblist->length == 0U)
            kblist->last = kbnode;
    }
    else if (index == (int) kblist->length) {
        kbnode = newbnode(value);
        kbnode->next = ((void *)0);
        kblist->last->next = kbnode;
        kblist->last = kbnode;
    }
    else {
        int curidx = 0;
        struct KBnode *prev = kblist->first;
        struct KBnode *next;
        while (curidx < index - 1) {
            prev = prev->next;
            curidx++;
        }
        next = prev->next;
        prev->next = newbnode(value);
        prev->next->next = next;
    }
    kblist->length++;
    return 1;
}

variable_types: index int

variable_types: value int

variable_types: struct KBnode { int beat; struct KBnode *next; } *

variable_types: curidx int

return_type: int


original_code:
int
blist_remove(KBlist *kblist, int index)
{
    int value;
    if (index < 0)
        index += kblist->length;
    if (index < 0 || index >= (int) kblist->length)
        return -1;
    if (index == 0) {
        if (kblist->first == kblist->last) {
            value = kblist->first->beat;
            delbnode(&kblist->first);
            kblist->first = ((void *)0);
            kblist->last = ((void *)0);
        }
        else {
            KBnode *second;
            second = kblist->first->next;
            value = kblist->first->beat;
            delbnode(&kblist->first);
            kblist->first = second;
        }
    }
    else {
        int curidx = 0;
        KBnode *prev = kblist->first;
        KBnode *next;
        while (curidx < index - 1) {
            prev = prev->next;
            curidx++;
        }
        next = prev->next->next;
        value = prev->next->beat;
        delbnode(&prev->next);
        prev->next = next;
    }
    kblist->length--;
    return value;
}

canonical_original_code:
int blist_remove(struct KBlist *kblist, int index)
{
    int value;
    if (index < 0)
        index += kblist->length;
    if (index < 0 || index >= (int) kblist->length)
        return -1;
    if (index == 0) {
        if (kblist->first == kblist->last) {
            value = kblist->first->beat;
            delbnode(&kblist->first);
            kblist->first = ((void *)0);
            kblist->last = ((void *)0);
        }
        else {
            struct KBnode *second;
            second = kblist->first->next;
            value = kblist->first->beat;
            delbnode(&kblist->first);
            kblist->first = second;
        }
    }
    else {
        int curidx = 0;
        struct KBnode *prev = kblist->first;
        struct KBnode *next;
        while (curidx < index - 1) {
            prev = prev->next;
            curidx++;
        }
        next = prev->next->next;
        value = prev->next->beat;
        delbnode(&prev->next);
        prev->next = next;
    }
    kblist->length--;
    return value;
}


original_code:
int
blist_extend(KBlist *kblist, KBlist *other)
{
    unsigned int count = 0;
    unsigned int length = other->length;
    KBnode *ecur = other->first;
    if (kblist->length == 0U) {
        kblist->first = kblist->last = newbnode(ecur->beat);
        kblist->length++;
        count++;
        ecur = ecur->next;
    }
    for (; count < length; count++) {
        kblist->last->next = newbnode(ecur->beat);
        kblist->last = kblist->last->next;
        kblist->length++;
        ecur = ecur->next;
    }
    return (int) length;
}

canonical_original_code:
int blist_extend(struct KBlist *kblist, struct KBlist *other)
{
    unsigned int count = 0;
    unsigned int length = other->length;
    struct KBnode *ecur = other->first;
    if (kblist->length == 0U) {
        kblist->first = kblist->last = newbnode(ecur->beat);
        kblist->length++;
        count++;
        ecur = ecur->next;
    }
    for (; count < length; count++) {
        kblist->last->next = newbnode(ecur->beat);
        kblist->last = kblist->last->next;
        kblist->length++;
        ecur = ecur->next;
    }
    return (int) length;
}

variable_types:
other
struct KBlist *

variable_types:
count
unsigned int

variable_types:
length
unsigned int


kgetargs

decompiled_code:
__int64 __fastcall kgetargs(_QWORD *a1, unsigned int a2, __int64 a3)
{
unsigned int v4; // edx
__int64 result; // rax
__int64 v6; // rbx
_DWORD *v7; // rax
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v4 = slength(*a1);
result = 2LL;
if ( v4 >= a2 )
{
LODWORD(v6) = a2 - 1;
if ( (int)(a2 - 1) < 0 )
{
result = 0LL;
}
else
{
v6 = (int)v6;
do
{
v7 = (_DWORD *)spop(a1);
v8[0] = (__int64)v7;
if ( *v7 == 4 )
{
if ( (unsigned int)tget(a1[1], v7 + 1, v8) != 1 )
return 3LL;
v8[0] = cpykob(v8[0]);
}
*(_QWORD *)(a3 + 8 * v6--) = v8[0];
}
while ( (int)v6 >= 0 );
result = 0LL;
}
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func0(_QWORD *a1, unsigned int a2, __int64 a3)
{
unsigned int v4; // edx
__int64 result; // rax
__int64 v6; // rbx
_DWORD *v7; // rax
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

v4 = slength(*a1);
result = 2LL;
if ( v4 >= a2 )
{
LODWORD(v6) = a2 - 1;
if ( (int)(a2 - 1) < 0 )
{
result = 0LL;
}
else
{
v6 = (int)v6;
do
{
v7 = (_DWORD *)spop(a1);
v8[0] = (__int64)v7;
if ( *v7 == 4 )
{
if ( (unsigned int)tget(a1[1], v7 + 1, v8) != 1 )
return 3LL;
v8[0] = cpykob(v8[0]);
}
*(_QWORD *)(a3 + 8 * v6--) = v8[0];
}
while ( (int)v6 >= 0 );
result = 0LL;
}
}
return result;
}

original_code:
Error
kgetargs(KRuntime *kruntime, int arity, Kob *args[])
{
    if (slength(kruntime->stack) < (unsigned int) arity)
        return E_ARITY;
    for (arity--; arity >= 0; arity--) {
        Kob *kob;
        kob = spop(&kruntime->stack);
        if (*kob == T_NAME) {
            if (tget(kruntime->nable, ((KName *) kob)->name, &kob) == 1)
                kob = cpykob(kob);
            else
                return E_NAME;
        }
        args[arity] = kob;
    }
    return E_OK;
}

canonical_original_code:
enum Error kgetargs(struct KRuntime *kruntime, int arity, enum Kob *args[])
{
    if (slength(kruntime->stack) < (unsigned int) arity)
        return E_ARITY;
    for (arity--; arity >= 0; arity--) {
        enum Kob *kob;
        kob = spop(&kruntime->stack);
        if (*kob == T_NAME) {
            if (tget(kruntime->nable, ((struct KName *) kob)->name, &kob) == 1)
                kob = cpykob(kob);
            else
                return E_NAME;
        }
        args[arity] = kob;
    }
    return E_OK;
}

variable_types: struct KRuntime { struct KStack { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *kob; struct KStack *next; } *stack; struct KNable { int level; struct KEntry { char *name; enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *value; struct KEntry **next; } *header; } *nable; struct KTrack { struct KEvent { unsigned int delta; char note; char volume; } *event; struct KTrack *next; } *track; int comment; } *

variable_types: arity int

variable_types: enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *[]

return_type: enum Error { E_OK=0, E_TYPE=1, E_ARITY=2, E_NAME=3, E_SYNTAX=4, E_FILE=5 }

user_defined_types: struct KRuntime { struct KStack *stack; struct KNable *nable; struct KTrack *track; int comment; }

user_defined_types: struct KStack { enum Kob *kob; struct KStack *next; }

user_defined_types: struct KNable { int level; struct KEntry *header; }

user_defined_types: struct KTrack { struct KEvent *event; struct KTrack *next; }

user_defined_types: struct KEntry { char *name; enum Kob *value; struct KEntry **next; }


kinvert

original_code:
Error
kinvert(KRuntime *kruntime)
{
    Kob *args[1];
    Error error;
    KBnode *kbnode;
    error = kgetargs(kruntime, 1, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST)
        return E_TYPE;
    kbnode = ((KBlist *) args[0])->first;
    while (kbnode != ((void *)0)) {
        kbnode->beat = !kbnode->beat;
        kbnode = kbnode->next;
    }
    spush(&kruntime->stack, args[0]);
    return E_OK;
}

canonical_original_code:
enum Error kinvert(struct KRuntime *kruntime)
{
    enum Kob *args[1];
    enum Error error;
    struct KBnode *kbnode;
    error = kgetargs(kruntime, 1, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST)
        return E_TYPE;
    kbnode = ((struct KBlist *) args[0])->first;
    while (kbnode != ((void *)0)) {
        kbnode->beat = !kbnode->beat;
        kbnode = kbnode->next;
    }
    spush(&kruntime->stack, args[0]);
    return E_OK;
}

variable_types: enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *[1]

variable_types: enum Error { E_OK=0, E_TYPE=1, E_ARITY=2, E_NAME=3, E_SYNTAX=4, E_FILE=5 }

user_defined_types: struct KEvent { unsigned int delta; char note; char volume; }


kclear

original_code:
Error
kclear(KRuntime *kruntime)
{
    Kob *args[1];
    Error error;
    KBnode *kbnode;
    error = kgetargs(kruntime, 1, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST)
        return E_TYPE;
    kbnode = ((KBlist *) args[0])->first;
    while (kbnode != ((void *)0)) {
        kbnode->beat = 0;
        kbnode = kbnode->next;
    }
    spush(&kruntime->stack, args[0]);
    return E_OK;
}

canonical_original_code:
enum Error kclear(struct KRuntime *kruntime)
{
    enum Kob *args[1];
    enum Error error;
    struct KBnode *kbnode;
    error = kgetargs(kruntime, 1, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST)
        return E_TYPE;
    kbnode = ((struct KBlist *) args[0])->first;
    while (kbnode != ((void *)0)) {
        kbnode->beat = 0;
        kbnode = kbnode->next;
    }
    spush(&kruntime->stack, args[0]);
    return E_OK;
}

user_defined_types: enum Error { E_OK=0, E_TYPE=1, E_ARITY=2, E_NAME=3, E_SYNTAX=4, E_FILE=5 }


kor

original_code:
Error
kor(KRuntime *kruntime)
{
    Kob *args[2];
    Error error;
    KBnode *kbnode_a, *kbnode_b;
    error = kgetargs(kruntime, 2, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST || *args[1] != T_BLIST)
        return E_TYPE;
    kbnode_a = ((KBlist *) args[0])->first;
    kbnode_b = ((KBlist *) args[1])->first;
    while (kbnode_a != ((void *)0) && kbnode_b != ((void *)0)) {
        kbnode_a->beat = kbnode_a->beat | kbnode_b->beat;
        kbnode_a = kbnode_a->next;
        kbnode_b = kbnode_b->next;
    }
    spush(&kruntime->stack, args[0]);
    delblist((KBlist **) &args[1]);
    return E_OK;
}

canonical_original_code:
enum Error kor(struct KRuntime *kruntime)
{
    enum Kob *args[2];
    enum Error error;
    struct KBnode *kbnode_a; struct KBnode *kbnode_b;
    error = kgetargs(kruntime, 2, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST || *args[1] != T_BLIST)
        return E_TYPE;
    kbnode_a = ((struct KBlist *) args[0])->first;
    kbnode_b = ((struct KBlist *) args[1])->first;
    while (kbnode_a != ((void *)0) && kbnode_b != ((void *)0)) {
        kbnode_a->beat = kbnode_a->beat | kbnode_b->beat;
        kbnode_a = kbnode_a->next;
        kbnode_b = kbnode_b->next;
    }
    spush(&kruntime->stack, args[0]);
    delblist((struct KBlist **) &args[1]);
    return E_OK;
}

variable_types: enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *[2]


kand

original_code:
Error
kand(KRuntime *kruntime)
{
    Kob *args[2];
    Error error;
    KBnode *kbnode_a, *kbnode_b;
    error = kgetargs(kruntime, 2, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST || *args[1] != T_BLIST)
        return E_TYPE;
    kbnode_a = ((KBlist *) args[0])->first;
    kbnode_b = ((KBlist *) args[1])->first;
    while (kbnode_a != ((void *)0) && kbnode_b != ((void *)0)) {
        kbnode_a->beat = kbnode_a->beat & kbnode_b->beat;
        kbnode_a = kbnode_a->next;
        kbnode_b = kbnode_b->next;
    }
    spush(&kruntime->stack, args[0]);
    delblist((KBlist **) &args[1]);
    return E_OK;
}

canonical_original_code:
enum Error kand(struct KRuntime *kruntime)
{
    enum Kob *args[2];
    enum Error error;
    struct KBnode *kbnode_a; struct KBnode *kbnode_b;
    error = kgetargs(kruntime, 2, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST || *args[1] != T_BLIST)
        return E_TYPE;
    kbnode_a = ((struct KBlist *) args[0])->first;
    kbnode_b = ((struct KBlist *) args[1])->first;
    while (kbnode_a != ((void *)0) && kbnode_b != ((void *)0)) {
        kbnode_a->beat = kbnode_a->beat & kbnode_b->beat;
        kbnode_a = kbnode_a->next;
        kbnode_b = kbnode_b->next;
    }
    spush(&kruntime->stack, args[0]);
    delblist((struct KBlist **) &args[1]);
    return E_OK;
}


krepeat

decompiled_code:
__int64 __fastcall krepeat(_QWORD *a1)
{
unsigned int v1; // ebx
__int64 i; // r12
_DWORD *v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = kgetargs(a1, 2u, (__int64)&v4);
if ( !v1 )
{
if ( *v4 == 3 )
{
if ( *(_DWORD *)v5[0] == 1 )
{
for ( i = cpyblist(); *(_DWORD *)(v5[0] + 4) > 1u; --*(_DWORD *)(v5[0] + 4) )
blist_extend(i, v4);
spush(a1, i);
delblist(&v4);
delnumber(v5);
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func5(_QWORD *a1)
{
unsigned int v1; // ebx
__int64 i; // r12
_DWORD *v4; // [rsp+0h] [rbp-28h] BYREF
__int64 v5[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = func0(a1, 2u, (__int64)&v4);
if ( !v1 )
{
if ( *v4 == 3 )
{
if ( *(_DWORD *)v5[0] == 1 )
{
for ( i = cpyblist(); *(_DWORD *)(v5[0] + 4) > 1u; --*(_DWORD *)(v5[0] + 4) )
blist_extend(i, v4);
spush(a1, i);
delblist(&v4);
delnumber(v5);
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
return v1;
}

original_code:
Error
krepeat(KRuntime *kruntime)
{
    Kob *args[2];
    Error error;
    KBlist *kblist;
    error = kgetargs(kruntime, 2, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST || *args[1] != T_NUMBER)
        return E_TYPE;
    kblist = cpyblist((KBlist *) args[0]);
    for (; ((KNumber *) args[1])->value > 1; ((KNumber *) args[1])->value--)
        blist_extend(kblist, (KBlist *) args[0]);
    spush(&kruntime->stack, (Kob *) kblist);
    delblist((KBlist **) &args[0]);
    delnumber((KNumber **) &args[1]);
    return E_OK;
}

canonical_original_code:
enum Error krepeat(struct KRuntime *kruntime)
{
    enum Kob *args[2];
    enum Error error;
    struct KBlist *kblist;
    error = kgetargs(kruntime, 2, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST || *args[1] != T_NUMBER)
        return E_TYPE;
    kblist = cpyblist((struct KBlist *) args[0]);
    for (; ((struct KNumber *) args[1])->value > 1; ((struct KNumber *) args[1])->value--)
        blist_extend(kblist, (struct KBlist *) args[0]);
    spush(&kruntime->stack, (enum Kob *) kblist);
    delblist((struct KBlist **) &args[0]);
    delnumber((struct KNumber **) &args[1]);
    return E_OK;
}

variable_types: struct KBlist { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } type; unsigned int length; struct KBnode { int beat; struct KBnode *next; } *first; struct KBnode *last; } *


kpattern

decompiled_code:
__int64 __fastcall kpattern(_QWORD *a1)
{
unsigned int v1; // ebx
__int64 i; // rbp
__int64 v3; // r13
__int64 j; // rbp
__int64 v6; // [rsp+8h] [rbp-40h] BYREF
__int64 v7; // [rsp+10h] [rbp-38h] BYREF
__int64 v8[6]; // [rsp+18h] [rbp-30h] BYREF

v1 = kgetargs(a1, 2u, (__int64)&v7);
if ( !v1 )
{
if ( *(_DWORD *)v7 == 3 )
{
if ( *(_DWORD *)v8[0] == 3 )
{
v6 = newblist();
for ( i = *(_QWORD *)(v7 + 8); i; i = *(_QWORD *)(i + 8) )
blist_insert(v6, 0LL, 0LL);
v3 = newblist();
for ( j = *(_QWORD *)(v8[0] + 8); j; j = *(_QWORD *)(j + 8) )
{
if ( *(_DWORD *)j )
blist_extend(v3, v7);
else
blist_extend(v3, v6);
}
spush(a1, v3);
delblist(&v6);
delblist(&v7);
delblist(v8);
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
unsigned int v1; // ebx
__int64 i; // rbp
__int64 v3; // r13
__int64 j; // rbp
__int64 v6; // [rsp+8h] [rbp-40h] BYREF
__int64 v7; // [rsp+10h] [rbp-38h] BYREF
__int64 v8[6]; // [rsp+18h] [rbp-30h] BYREF

v1 = func0(a1, 2u, (__int64)&v7);
if ( !v1 )
{
if ( *(_DWORD *)v7 == 3 )
{
if ( *(_DWORD *)v8[0] == 3 )
{
v6 = newblist();
for ( i = *(_QWORD *)(v7 + 8); i; i = *(_QWORD *)(i + 8) )
blist_insert(v6, 0LL, 0LL);
v3 = newblist();
for ( j = *(_QWORD *)(v8[0] + 8); j; j = *(_QWORD *)(j + 8) )
{
if ( *(_DWORD *)j )
blist_extend(v3, v7);
else
blist_extend(v3, v6);
}
spush(a1, v3);
delblist(&v6);
delblist(&v7);
delblist(v8);
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
return v1;
}

original_code:
Error
kpattern(KRuntime *kruntime)
{
    Kob *args[2];
    Error error;
    KBlist *silence, *result;
    KBnode *kbnode;
    error = kgetargs(kruntime, 2, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST || *args[1] != T_BLIST)
        return E_TYPE;
    silence = newblist();
    kbnode = ((KBlist *) args[0])->first;
    while (kbnode != ((void *)0)) {
        blist_insert(silence, 0, 0);
        kbnode = kbnode->next;
    }
    result = newblist();
    kbnode = ((KBlist *) args[1])->first;
    while (kbnode != ((void *)0)) {
        if (kbnode->beat)
            blist_extend(result, (KBlist *) args[0]);
        else
            blist_extend(result, silence);
        kbnode = kbnode->next;
    }
    spush(&kruntime->stack, (Kob *) result);
    delblist(&silence);
    delblist((KBlist **) &args[0]);
    delblist((KBlist **) &args[1]);
    return E_OK;
}

canonical_original_code:
enum Error kpattern(struct KRuntime *kruntime)
{
    enum Kob *args[2];
    enum Error error;
    struct KBlist *silence; struct KBlist *result;
    struct KBnode *kbnode;
    error = kgetargs(kruntime, 2, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST || *args[1] != T_BLIST)
        return E_TYPE;
    silence = newblist();
    kbnode = ((struct KBlist *) args[0])->first;
    while (kbnode != ((void *)0)) {
        blist_insert(silence, 0, 0);
        kbnode = kbnode->next;
    }
    result = newblist();
    kbnode = ((struct KBlist *) args[1])->first;
    while (kbnode != ((void *)0)) {
        if (kbnode->beat)
            blist_extend(result, (struct KBlist *) args[0]);
        else
            blist_extend(result, silence);
        kbnode = kbnode->next;
    }
    spush(&kruntime->stack, (enum Kob *) result);
    delblist(&silence);
    delblist((struct KBlist **) &args[0]);
    delblist((struct KBlist **) &args[1]);
    return E_OK;
}


krleft

decompiled_code:
__int64 __fastcall krleft(_QWORD *a1)
{
unsigned int v1; // ebx
_DWORD *v2; // rbp
unsigned int v3; // eax
_DWORD *v5; // [rsp+0h] [rbp-28h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = kgetargs(a1, 2u, (__int64)&v5);
if ( !v1 )
{
v2 = v5;
if ( *v5 == 3 )
{
if ( *(_DWORD *)v6[0] == 1 )
{
for ( ; *(_DWORD *)(v6[0] + 4); --*(_DWORD *)(v6[0] + 4) )
{
v3 = blist_remove(v2, 0LL);
blist_insert(v2, (unsigned int)v2[1], v3);
}
spush(a1, v5);
delnumber(v6);
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func7(_QWORD *a1)
{
unsigned int v1; // ebx
_DWORD *v2; // rbp
unsigned int v3; // eax
_DWORD *v5; // [rsp+0h] [rbp-28h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = func0(a1, 2u, (__int64)&v5);
if ( !v1 )
{
v2 = v5;
if ( *v5 == 3 )
{
if ( *(_DWORD *)v6[0] == 1 )
{
for ( ; *(_DWORD *)(v6[0] + 4); --*(_DWORD *)(v6[0] + 4) )
{
v3 = blist_remove(v2, 0LL);
blist_insert(v2, (unsigned int)v2[1], v3);
}
spush(a1, v5);
delnumber(v6);
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
return v1;
}

original_code:
Error
krleft(KRuntime *kruntime)
{
    Kob *args[2];
    Error error;
    KBlist *kblist;
    error = kgetargs(kruntime, 2, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST || *args[1] != T_NUMBER)
        return E_TYPE;
    kblist = (KBlist *) args[0];
    for (; ((KNumber *) args[1])->value > 0; ((KNumber *) args[1])->value--)
        blist_insert(kblist, kblist->length, blist_remove(kblist, 0));
    spush(&kruntime->stack, args[0]);
    delnumber((KNumber **) &args[1]);
    return E_OK;
}

canonical_original_code:
enum Error krleft(struct KRuntime *kruntime)
{
    enum Kob *args[2];
    enum Error error;
    struct KBlist *kblist;
    error = kgetargs(kruntime, 2, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST || *args[1] != T_NUMBER)
        return E_TYPE;
    kblist = (struct KBlist *) args[0];
    for (; ((struct KNumber *) args[1])->value > 0; ((struct KNumber *) args[1])->value--)
        blist_insert(kblist, kblist->length, blist_remove(kblist, 0));
    spush(&kruntime->stack, args[0]);
    delnumber((struct KNumber **) &args[1]);
    return E_OK;
}


krright

decompiled_code:
__int64 __fastcall krright(_QWORD *a1)
{
unsigned int v1; // ebx
_DWORD *v2; // r12
unsigned int v3; // eax
_DWORD *v5; // [rsp+0h] [rbp-28h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = kgetargs(a1, 2u, (__int64)&v5);
if ( !v1 )
{
v2 = v5;
if ( *v5 == 3 )
{
if ( *(_DWORD *)v6[0] == 1 )
{
for ( ; *(_DWORD *)(v6[0] + 4); --*(_DWORD *)(v6[0] + 4) )
{
v3 = blist_remove(v2, 0xFFFFFFFFLL);
blist_insert(v2, 0LL, v3);
}
spush(a1, v5);
delnumber(v6);
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func8(_QWORD *a1)
{
unsigned int v1; // ebx
_DWORD *v2; // r12
unsigned int v3; // eax
_DWORD *v5; // [rsp+0h] [rbp-28h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = func0(a1, 2u, (__int64)&v5);
if ( !v1 )
{
v2 = v5;
if ( *v5 == 3 )
{
if ( *(_DWORD *)v6[0] == 1 )
{
for ( ; *(_DWORD *)(v6[0] + 4); --*(_DWORD *)(v6[0] + 4) )
{
v3 = blist_remove(v2, 0xFFFFFFFFLL);
blist_insert(v2, 0LL, v3);
}
spush(a1, v5);
delnumber(v6);
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
return v1;
}

original_code:
Error
krright(KRuntime *kruntime)
{
    Kob *args[2];
    Error error;
    KBlist *kblist;
    error = kgetargs(kruntime, 2, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST || *args[1] != T_NUMBER)
        return E_TYPE;
    kblist = (KBlist *) args[0];
    for (; ((KNumber *) args[1])->value > 0; ((KNumber *) args[1])->value--)
        blist_insert(kblist, 0, blist_remove(kblist, -1));
    spush(&kruntime->stack, args[0]);
    delnumber((KNumber **) &args[1]);
    return E_OK;
}

canonical_original_code:
enum Error krright(struct KRuntime *kruntime)
{
    enum Kob *args[2];
    enum Error error;
    struct KBlist *kblist;
    error = kgetargs(kruntime, 2, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST || *args[1] != T_NUMBER)
        return E_TYPE;
    kblist = (struct KBlist *) args[0];
    for (; ((struct KNumber *) args[1])->value > 0; ((struct KNumber *) args[1])->value--)
        blist_insert(kblist, 0, blist_remove(kblist, -1));
    spush(&kruntime->stack, args[0]);
    delnumber((struct KNumber **) &args[1]);
    return E_OK;
}


kpleft

decompiled_code:
__int64 __fastcall kpleft(_QWORD *a1)
{
unsigned int v1; // ebx
_DWORD *v2; // r12
_DWORD *v4; // [rsp+0h] [rbp-38h] BYREF
_DWORD *v5; // [rsp+8h] [rbp-30h] BYREF
__int64 v6[5]; // [rsp+10h] [rbp-28h] BYREF

v1 = kgetargs(a1, 3u, (__int64)&v4);
if ( !v1 )
{
v2 = v4;
if ( *v4 == 3 )
{
if ( *v5 == 1 )
{
if ( *(_DWORD *)v6[0] == 2 )
{
for ( ; v5[1]; --v5[1] )
blist_insert(v2, (unsigned int)v2[1], *(unsigned int *)(v6[0] + 4));
spush(a1, v4);
delnumber(&v5);
delbeat(v6);
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func9(_QWORD *a1)
{
unsigned int v1; // ebx
_DWORD *v2; // r12
_DWORD *v4; // [rsp+0h] [rbp-38h] BYREF
_DWORD *v5; // [rsp+8h] [rbp-30h] BYREF
__int64 v6[5]; // [rsp+10h] [rbp-28h] BYREF

v1 = func0(a1, 3u, (__int64)&v4);
if ( !v1 )
{
v2 = v4;
if ( *v4 == 3 )
{
if ( *v5 == 1 )
{
if ( *(_DWORD *)v6[0] == 2 )
{
for ( ; v5[1]; --v5[1] )
blist_insert(v2, (unsigned int)v2[1], *(unsigned int *)(v6[0] + 4));
spush(a1, v4);
delnumber(&v5);
delbeat(v6);
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
return v1;
}

original_code:
Error
kpleft(KRuntime *kruntime)
{
    Kob *args[3];
    Error error;
    KBlist *kblist;
    error = kgetargs(kruntime, 3, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST || *args[1] != T_NUMBER || *args[2] != T_BEAT)
        return E_TYPE;
    kblist = (KBlist *) args[0];
    for (; ((KNumber *) args[1])->value > 0; ((KNumber *) args[1])->value--)
        blist_insert(kblist, kblist->length, ((KBeat *) args[2])->value);
    spush(&kruntime->stack, args[0]);
    delnumber((KNumber **) &args[1]);
    delbeat((KBeat **) &args[2]);
    return E_OK;
}

canonical_original_code:
enum Error kpleft(struct KRuntime *kruntime)
{
    enum Kob *args[3];
    enum Error error;
    struct KBlist *kblist;
    error = kgetargs(kruntime, 3, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST || *args[1] != T_NUMBER || *args[2] != T_BEAT)
        return E_TYPE;
    kblist = (struct KBlist *) args[0];
    for (; ((struct KNumber *) args[1])->value > 0; ((struct KNumber *) args[1])->value--)
        blist_insert(kblist, kblist->length, ((struct KBeat *) args[2])->value);
    spush(&kruntime->stack, args[0]);
    delnumber((struct KNumber **) &args[1]);
    delbeat((struct KBeat **) &args[2]);
    return E_OK;
}

variable_types: enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *[3]


kpright

decompiled_code:
__int64 __fastcall kpright(_QWORD *a1)
{
unsigned int v1; // ebx
_DWORD *v2; // r12
_DWORD *v4; // [rsp+0h] [rbp-38h] BYREF
_DWORD *v5; // [rsp+8h] [rbp-30h] BYREF
__int64 v6[5]; // [rsp+10h] [rbp-28h] BYREF

v1 = kgetargs(a1, 3u, (__int64)&v4);
if ( !v1 )
{
v2 = v4;
if ( *v4 == 3 )
{
if ( *v5 == 1 )
{
if ( *(_DWORD *)v6[0] == 2 )
{
for ( ; v5[1]; --v5[1] )
blist_insert(v2, 0LL, *(unsigned int *)(v6[0] + 4));
spush(a1, v4);
delnumber(&v5);
delbeat(v6);
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
return v1;
}

original_code:
Error
kpright(KRuntime *kruntime)
{
    Kob *args[3];
    Error error;
    KBlist *kblist;
    error = kgetargs(kruntime, 3, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST ||
        *args[1] != T_NUMBER ||
        *args[2] != T_BEAT)
        return E_TYPE;
    kblist = (KBlist *) args[0];
    for (; ((KNumber *) args[1])->value > 0; ((KNumber *) args[1])->value--)
        blist_insert(kblist, 0, ((KBeat *) args[2])->value);
    spush(&kruntime->stack, args[0]);
    delnumber((KNumber **) &args[1]);
    delbeat((KBeat **) &args[2]);
    return E_OK;
}

canonical_original_code:
enum Error kpright(struct KRuntime *kruntime)
{
    enum Kob *args[3];
    enum Error error;
    struct KBlist *kblist;
    error = kgetargs(kruntime, 3, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST ||
        *args[1] != T_NUMBER ||
        *args[2] != T_BEAT)
        return E_TYPE;
    kblist = (struct KBlist *) args[0];
    for (; ((struct KNumber *) args[1])->value > 0; ((struct KNumber *) args[1])->value--)
        blist_insert(kblist, 0, ((struct KBeat *) args[2])->value);
    spush(&kruntime->stack, args[0]);
    delnumber((struct KNumber **) &args[1]);
    delbeat((struct KBeat **) &args[2]);
    return E_OK;
}


ksubdiv

decompiled_code:
__int64 __fastcall ksubdiv(_QWORD *a1)
{
__int64 result; // rax
__int64 v2[5]; // [rsp+0h] [rbp-28h] BYREF

result = kgetargs(a1, 3u, (__int64)v2);
if ( !(_DWORD)result )
{
result = 1LL;
if ( *(_DWORD *)v2[0] == 3 && *(_DWORD *)v2[1] == 1 )
result = *(_DWORD *)v2[2] != 1;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(_QWORD *a1)
{
__int64 result; // rax
__int64 v2[5]; // [rsp+0h] [rbp-28h] BYREF

result = func0(a1, 3u, (__int64)v2);
if ( !(_DWORD)result )
{
result = 1LL;
if ( *(_DWORD *)v2[0] == 3 && *(_DWORD *)v2[1] == 1 )
result = *(_DWORD *)v2[2] != 1;
}
return result;
}

original_code:
Error
ksubdiv(KRuntime *kruntime)
{
    Kob *args[3];
    Error error;
    error = kgetargs(kruntime, 3, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST ||
        *args[1] != T_NUMBER ||
        *args[2] != T_NUMBER)
        return E_TYPE;
    return E_OK;
}

canonical_original_code:
enum Error ksubdiv(struct KRuntime *kruntime)
{
    enum Kob *args[3];
    enum Error error;
    error = kgetargs(kruntime, 3, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST ||
        *args[1] != T_NUMBER ||
        *args[2] != T_NUMBER)
        return E_TYPE;
    return E_OK;
}


kset

decompiled_code:
__int64 __fastcall kset(_QWORD *a1)
{
__int64 v1; // rax
_DWORD *v2; // rsi
__int64 result; // rax
int v4; // edx
_DWORD *v5; // [rsp+0h] [rbp-18h] BYREF
_DWORD *v6; // [rsp+8h] [rbp-10h] BYREF

if ( (unsigned int)slength(*a1) <= 1 )
return 2LL;
v1 = *a1;
v2 = *(_DWORD **)*a1;
v5 = v2;
v6 = **(_DWORD ***)(v1 + 8);
if ( *v2 == 4 )
{
v4 = tget(a1[1], v2 + 1, &v5);
result = 3LL;
if ( v4 != 1 )
return result;
v5 = (_DWORD *)cpykob(v5);
}
result = 1LL;
if ( *v6 == 4 )
{
tset(a1[1], v6 + 1, v5);
*a1 = *(_QWORD *)(*(_QWORD *)(*a1 + 8LL) + 8LL);
delname(&v6);
result = 0LL;
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func12(_QWORD *a1)
{
__int64 v1; // rax
_DWORD *v2; // rsi
__int64 result; // rax
int v4; // edx
_DWORD *v5; // [rsp+0h] [rbp-18h] BYREF
_DWORD *v6; // [rsp+8h] [rbp-10h] BYREF

if ( (unsigned int)slength(*a1) <= 1 )
return 2LL;
v1 = *a1;
v2 = *(_DWORD **)*a1;
v5 = v2;
v6 = **(_DWORD ***)(v1 + 8);
if ( *v2 == 4 )
{
v4 = tget(a1[1], v2 + 1, &v5);
result = 3LL;
if ( v4 != 1 )
return result;
v5 = (_DWORD *)cpykob(v5);
}
result = 1LL;
if ( *v6 == 4 )
{
tset(a1[1], v6 + 1, v5);
*a1 = *(_QWORD *)(*(_QWORD *)(*a1 + 8LL) + 8LL);
delname(&v6);
result = 0LL;
}
return result;
}

original_code:
Error
kset(KRuntime *kruntime)
{
    Kob *kob_a, *kob_b;
    if (slength(kruntime->stack) < 2U)
        return E_ARITY;
    kob_b = kruntime->stack->kob;
    kob_a = kruntime->stack->next->kob;
    if (*kob_b == T_NAME) {
        if (tget(kruntime->nable, ((KName *) kob_b)->name, &kob_b) == 1)
            kob_b = cpykob(kob_b);
        else
            return E_NAME;
    }
    if (*kob_a != T_NAME)
        return E_TYPE;
    tset(kruntime->nable, ((KName *) kob_a)->name, kob_b);
    kruntime->stack = kruntime->stack->next->next;
    delname((KName **) &kob_a);
    return E_OK;
}

canonical_original_code:
enum Error kset(struct KRuntime *kruntime)
{
    enum Kob *kob_a; enum Kob *kob_b;
    if (slength(kruntime->stack) < 2U)
        return E_ARITY;
    kob_b = kruntime->stack->kob;
    kob_a = kruntime->stack->next->kob;
    if (*kob_b == T_NAME) {
        if (tget(kruntime->nable, ((struct KName *) kob_b)->name, &kob_b) == 1)
            kob_b = cpykob(kob_b);
        else
            return E_NAME;
    }
    if (*kob_a != T_NAME)
        return E_TYPE;
    tset(kruntime->nable, ((struct KName *) kob_a)->name, kob_b);
    kruntime->stack = kruntime->stack->next->next;
    delname((struct KName **) &kob_a);
    return E_OK;
}

variable_types: enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *


kmix

decompiled_code:
__int64 __fastcall kmix(_QWORD *a1)
{
unsigned int v1; // ebx
__int64 v2; // rax
_DWORD *v4; // [rsp+0h] [rbp-38h] BYREF
__int64 v5; // [rsp+8h] [rbp-30h] BYREF
__int64 v6; // [rsp+10h] [rbp-28h] BYREF
__int64 v7[4]; // [rsp+18h] [rbp-20h] BYREF

v1 = kgetargs(a1, 4u, (__int64)&v4);
if ( !v1 )
{
if ( *v4 == 3 )
{
if ( *(_DWORD *)v5 == 1 )
{
if ( *(_DWORD *)v6 == 1 )
{
if ( *(_DWORD *)v7[0] == 1 )
{
v2 = trackfromblist(
v4,
(unsigned int)*(char *)(v5 + 4),
(unsigned int)*(char *)(v6 + 4),
*(unsigned int *)(v7[0] + 4));
a1[2] = trackmix(a1[2], v2);
delblist(&v4);
delnumber(&v5);
delnumber(&v6);
delnumber(v7);
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1)
{
unsigned int v1; // ebx
__int64 v2; // rax
_DWORD *v4; // [rsp+0h] [rbp-38h] BYREF
__int64 v5; // [rsp+8h] [rbp-30h] BYREF
__int64 v6; // [rsp+10h] [rbp-28h] BYREF
__int64 v7[4]; // [rsp+18h] [rbp-20h] BYREF

v1 = func0(a1, 4u, (__int64)&v4);
if ( !v1 )
{
if ( *v4 == 3 )
{
if ( *(_DWORD *)v5 == 1 )
{
if ( *(_DWORD *)v6 == 1 )
{
if ( *(_DWORD *)v7[0] == 1 )
{
v2 = trackfromblist(
v4,
(unsigned int)*(char *)(v5 + 4),
(unsigned int)*(char *)(v6 + 4),
*(unsigned int *)(v7[0] + 4));
a1[2] = trackmix(a1[2], v2);
delblist(&v4);
delnumber(&v5);
delnumber(&v6);
delnumber(v7);
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
else
{
v1 = 1;
}
}
return v1;
}

original_code:
Error
kmix(KRuntime *kruntime)
{
    Kob *args[4];
    Error error;
    KTrack *ktrack;
    error = kgetargs(kruntime, 4, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST || *args[1] != T_NUMBER ||
        *args[2] != T_NUMBER || *args[3] != T_NUMBER)
        return E_TYPE;
    ktrack = trackfromblist((KBlist *) args[0],
                            (char) ((KNumber *) args[1])->value,
                            (char) ((KNumber *) args[2])->value,
                            ((KNumber *) args[3])->value);
    kruntime->track = trackmix(kruntime->track, ktrack);
    delblist((KBlist **) &args[0]);
    delnumber((KNumber **) &args[1]);
    delnumber((KNumber **) &args[2]);
    delnumber((KNumber **) &args[3]);
    return E_OK;
}

canonical_original_code:
enum Error kmix(struct KRuntime *kruntime)
{
    enum Kob *args[4];
    enum Error error;
    struct KTrack *ktrack;
    error = kgetargs(kruntime, 4, args);
    if (error != E_OK) return error;
    if (*args[0] != T_BLIST || *args[1] != T_NUMBER ||
        *args[2] != T_NUMBER || *args[3] != T_NUMBER)
        return E_TYPE;
    ktrack = trackfromblist((struct KBlist *) args[0],
                            (char) ((struct KNumber *) args[1])->value,
                            (char) ((struct KNumber *) args[2])->value,
                            ((struct KNumber *) args[3])->value);
    kruntime->track = trackmix(kruntime->track, ktrack);
    delblist((struct KBlist **) &args[0]);
    delnumber((struct KNumber **) &args[1]);
    delnumber((struct KNumber **) &args[2]);
    delnumber((struct KNumber **) &args[3]);
    return E_OK;
}

variable_types: enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *[4]

variable_types: struct KTrack { struct KEvent { unsigned int delta; char note; char volume; } *event; struct KTrack *next; } *


kparsenumber

decompiled_code:
__int64 __fastcall kparsenumber(const char *a1)
{
__int64 v1; // rax

v1 = strtol(a1, 0LL, 0);
return newnumber(v1);
}

canonical_decompiled_code:
__int64 __fastcall func0(const char *a1)
{
__int64 v1; // rax

v1 = strtol(a1, 0LL, 0);
return newnumber(v1);
}

original_code:
KNumber *
kparsenumber(char *token)
{
    return newnumber((unsigned int) strtol(token, ((void *)0), 0));
}

canonical_original_code:
struct KNumber *kparsenumber(char *token)
{
    return newnumber((unsigned int) strtol(token, ((void *)0), 0));
}

variable_types:
token
char *

return_type: struct KNumber { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } type; unsigned int value; } *


kparsebeat

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

if ( *a1 == 43 )
result = newbeat(1LL);
else
result = newbeat(0LL);
return result;
}

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

if ( *a1 == 43 )
result = newbeat(1LL);
else
result = newbeat(0LL);
return result;
}

original_code:
KBeat *
kparsebeat(char *token)
{
    if (*token == '+')
        return newbeat(1);
    else
        return newbeat(0);
}

canonical_original_code:
struct KBeat *kparsebeat(char *token)
{
    if (*token == '+')
        return newbeat(1);
    else
        return newbeat(0);
}

return_type: struct KBeat { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } type; int value; } *


kparseblist

decompiled_code:
__int64 __fastcall kparseblist(__int64 a1)
{
__int64 v1; // rbp
_BYTE *v2; // rbx
char v3; // al

v1 = newblist();
v2 = (_BYTE *)(a1 + 1);
v3 = *(_BYTE *)(a1 + 1);
if ( v3 != 93 )
{
do
{
if ( v3 == 43 )
{
blist_insert(v1, *(unsigned int *)(v1 + 4), 1LL);
}
else if ( v3 == 45 )
{
blist_insert(v1, *(unsigned int *)(v1 + 4), 0LL);
}
v3 = *++v2;
}
while ( *v2 != 93 );
}
return v1;
}

original_code:
KBlist *
kparseblist(char *token)
{
    KBlist *kblist;
    kblist = newblist();
    token++;
    while (*token != ']') {
        if (*token == '+')
            blist_insert(kblist, (int) kblist->length, 1);
        else if (*token == '-')
            blist_insert(kblist, (int) kblist->length, 0);
        token++;
    }
    return kblist;
}

canonical_original_code:
struct KBlist *kparseblist(char *token)
{
    struct KBlist *kblist;
    kblist = newblist();
    token++;
    while (*token != ']') {
        if (*token == '+')
            blist_insert(kblist, (int) kblist->length, 1);
        else if (*token == '-')
            blist_insert(kblist, (int) kblist->length, 0);
        token++;
    }
    return kblist;
}

return_type: struct KBlist { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } type; unsigned int length; struct KBnode { int beat; struct KBnode *next; } *first; struct KBnode *last; } *


kparsename

decompiled_code:
__int64 __fastcall kparsename(__int64 a1)
{
return newname(a1 + 1);
}

canonical_decompiled_code:
__int64 __fastcall func3(__int64 a1)
{
return newname(a1 + 1);
}

original_code:
KName *
kparsename(char *token)
{
    return newname(token + 1);
}

canonical_original_code:
struct KName *kparsename(char *token)
{
    return newname(token + 1);
}


kisnumber

decompiled_code:
__int64 __fastcall kisnumber(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
const unsigned __int16 *v3; // rax

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = a1;
v3 = *_ctype_b_loc();
while ( (v3[v1] & 0x800) != 0 )
{
v1 = *++v2;
if ( !*v2 )
return 1LL;
}
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func4(_BYTE *a1)
{
char v1; // bl
_BYTE *v2; // rbp
const unsigned __int16 *v3; // rax

v1 = *a1;
if ( !*a1 )
return 1LL;
v2 = a1;
v3 = *_ctype_b_loc();
while ( (v3[v1] & 0x800) != 0 )
{
v1 = *++v2;
if ( !*v2 )
return 1LL;
}
return 0LL;
}

original_code:
int
kisnumber(char *token)
{
    for (; *token != '\0'; token++)
        if (!((*__ctype_b_loc ())[(int) ((*token))] & (unsigned short int) _ISdigit))
            return 0;
    return 1;
}

canonical_original_code:
int kisnumber(char *token)
{
    for (; *token != '\0'; token++)
        if (!((*__ctype_b_loc ())[(int) ((*token))] & (unsigned short) _ISdigit))
            return 0;
    return 1;
}


kisbeat

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

v1 = 1;
if ( strcmp(a1, "+") )
v1 = strcmp(a1, "-") == 0;
return v1;
}

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

v1 = 1;
if ( strcmp(a1, "+") )
v1 = strcmp(a1, "-") == 0;
return v1;
}

original_code:
int
kisbeat(char *token)
{
    return (!strcmp(token, "+") || !strcmp(token, "-"));
}


kisblist

decompiled_code:
_BOOL8 __fastcall kisblist(const char *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == 91 )
result = a1[strlen(a1) - 1] == 93;
return result;
}

canonical_decompiled_code:
_BOOL8 __fastcall func6(const char *a1)
{
_BOOL8 result; // rax

result = 0LL;
if ( *a1 == 91 )
result = a1[strlen(a1) - 1] == 93;
return result;
}

original_code:
int
kisblist(char *token)
{
    return (*token == '[' && *(token + strlen(token) - 1) == ']');
}


kisname

decompiled_code:
_BOOL8 __fastcall kisname(_BYTE *a1)
{
return *a1 == 36;
}

canonical_decompiled_code:
_BOOL8 __fastcall func7(_BYTE *a1)
{
return *a1 == 36;
}

original_code:
int
kisname(char *token)
{
    return (*token == '$');
}


kparse

decompiled_code:
__int64 __fastcall kparse(char *a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

if ( (unsigned int)kisnumber(a1) )
return kparsenumber(a1);
if ( kisbeat(a1) )
return kparsebeat(a1);
if ( kisblist(a1) )
return kparseblist((__int64)a1);
v1 = kisname(a1);
result = 0LL;
if ( v1 )
result = kparsename((__int64)a1);
return result;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1)
{
_BOOL4 v1; // edx
__int64 result; // rax

if ( (unsigned int)func4(a1) )
return func0(a1);
if ( func5(a1) )
return func1(a1);
if ( func6(a1) )
return func2((__int64)a1);
v1 = func7(a1);
result = 0LL;
if ( v1 )
result = func3((__int64)a1);
return result;
}

original_code:
Kob *
kparse(char *token)
{
    if (kisnumber(token))
        return (Kob *) kparsenumber(token);
    else if (kisbeat(token))
        return (Kob *) kparsebeat(token);
    else if (kisblist(token))
        return (Kob *) kparseblist(token);
    else if (kisname(token))
        return (Kob *) kparsename(token);
    else
        return ((void *)0);
}

canonical_original_code:
enum Kob *kparse(char *token)
{
    if (kisnumber(token))
        return (enum Kob *) kparsenumber(token);
    else if (kisbeat(token))
        return (enum Kob *) kparsebeat(token);
    else if (kisblist(token))
        return (enum Kob *) kparseblist(token);
    else if (kisname(token))
        return (enum Kob *) kparsename(token);
    else
        return ((void *)0);
}

return_type: enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *


delevent

decompiled_code:
void __fastcall delevent(void **a1)
{
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func0(void **a1)
{
free(*a1);
*a1 = 0LL;
}

original_code:
void
delevent(KEvent **kevent)
{
    free(*kevent);
    *kevent = ((void *)0);
}

canonical_original_code:
void delevent(struct KEvent **kevent)
{
    free(*kevent);
    *kevent = ((void *)0);
}

variable_types: struct KEvent { unsigned int delta; char note; char volume; } **


deltrack

decompiled_code:
void __fastcall deltrack(__int64 *a1)
{
__int64 v1; // rbx
void **v2; // rbp

v1 = *a1;
while ( v1 )
{
v2 = (void **)v1;
v1 = *(_QWORD *)(v1 + 8);
delevent(v2);
free(v2);
}
*a1 = 0LL;
}

original_code:
void
deltrack(KTrack **ktrack)
{
    KTrack *a, *b;
    a = *ktrack;
    while (a != ((void *)0)) {
        b = a->next;
        delevent(&a->event);
        free(a);
        a = b;
    }
    *ktrack = ((void *)0);
}

canonical_original_code:
void deltrack(struct KTrack **ktrack)
{
    struct KTrack *a; struct KTrack *b;
    a = *ktrack;
    while (a != ((void *)0)) {
        b = a->next;
        delevent(&a->event);
        free(a);
        a = b;
    }
    *ktrack = ((void *)0);
}

variable_types: struct KTrack { struct KEvent { unsigned int delta; char note; char volume; } *event; struct KTrack *next; } **


closer

decompiled_code:
_BOOL8 __fastcall closer(_DWORD **a1, _DWORD **a2)
{
if ( !a1 )
return 1LL;
if ( a2 )
return **a1 >= **a2;
return 0LL;
}

canonical_decompiled_code:
_BOOL8 __fastcall func2(_DWORD **a1, _DWORD **a2)
{
if ( !a1 )
return 1LL;
if ( a2 )
return **a1 >= **a2;
return 0LL;
}

original_code:
int
closer(KTrack *ktrack_a, KTrack *ktrack_b)
{
    if (ktrack_a == ((void *)0))
        return 1;
    if (ktrack_b == ((void *)0))
        return 0;
    if (ktrack_a->event->delta < ktrack_b->event->delta)
        return 0;
    else
        return 1;
}

canonical_original_code:
int closer(struct KTrack *ktrack_a, struct KTrack *ktrack_b)
{
    if (ktrack_a == ((void *)0))
        return 1;
    if (ktrack_b == ((void *)0))
        return 0;
    if (ktrack_a->event->delta < ktrack_b->event->delta)
        return 0;
    else
        return 1;
}


newruntime

decompiled_code:
_QWORD *newruntime()
{
_QWORD *v0; // rbx

v0 = malloc(0x20uLL);
*v0 = newstack();
v0[1] = newnable();
v0[2] = 0LL;
*((_DWORD *)v0 + 6) = 0;
return v0;
}

canonical_decompiled_code:
_QWORD *func0()
{
_QWORD *v0; // rbx

v0 = malloc(0x20uLL);
*v0 = newstack();
v0[1] = newnable();
v0[2] = 0LL;
*((_DWORD *)v0 + 6) = 0;
return v0;
}

original_code:
KRuntime *
newruntime()
{
    KRuntime *kruntime;
    kruntime = (KRuntime *) malloc(sizeof(KRuntime));
    kruntime->stack = newstack();
    kruntime->nable = newnable();
    kruntime->track = ((void *)0);
    kruntime->comment = 0;
    return kruntime;
}

canonical_original_code:
struct KRuntime *newruntime()
{
    struct KRuntime *kruntime;
    kruntime = (struct KRuntime *) malloc(sizeof(KRuntime));
    kruntime->stack = newstack();
    kruntime->nable = newnable();
    kruntime->track = ((void *)0);
    kruntime->comment = 0;
    return kruntime;
}

return_type: struct KRuntime { struct KStack { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *kob; struct KStack *next; } *stack; struct KNable { int level; struct KEntry { char *name; enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *value; struct KEntry **next; } *header; } *nable; struct KTrack { struct KEvent { unsigned int delta; char note; char volume; } *event; struct KTrack *next; } *track; int comment; } *


delruntime

decompiled_code:
void __fastcall delruntime(void **a1)
{
delstack(*a1);
delnable((char *)*a1 + 8);
deltrack((char *)*a1 + 16);
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func1(void **a1)
{
delstack(*a1);
delnable((char *)*a1 + 8);
deltrack((char *)*a1 + 16);
free(*a1);
*a1 = 0LL;
}

original_code:
void
delruntime(KRuntime **kruntime)
{
    delstack(&(*kruntime)->stack);
    delnable(&(*kruntime)->nable);
    deltrack(&(*kruntime)->track);
    free(*kruntime);
    *kruntime = ((void *)0);
}

canonical_original_code:
void delruntime(struct KRuntime **kruntime)
{
    delstack(&(*kruntime)->stack);
    delnable(&(*kruntime)->nable);
    deltrack(&(*kruntime)->track);
    free(*kruntime);
    *kruntime = ((void *)0);
}

variable_types: struct KRuntime { struct KStack { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *kob; struct KStack *next; } *stack; struct KNable { int level; struct KEntry { char *name; enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *value; struct KEntry **next; } *header; } *nable; struct KTrack { struct KEvent { unsigned int delta; char note; char volume; } *event; struct KTrack *next; } *track; int comment; } **


kprocess

decompiled_code:
__int64 __fastcall kprocess(__int64 a1, const char *a2)
{
const char *v3; // rax
bool v4; // dl
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
char v9; // dl
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
const char *v14; // rsi
char v15; // dl
bool v16; // cf
bool v17; // zf
const char *v18; // rdi
__int64 v19; // rcx
const char *v20; // rsi
char v21; // dl
bool v22; // cf
bool v23; // zf
const char *v24; // rdi
__int64 v25; // rcx
const char *v26; // rsi
char v27; // dl
bool v28; // cf
bool v29; // zf
const char *v30; // rdi
__int64 v31; // rcx
const char *v32; // rsi
char v33; // dl
bool v34; // cf
bool v35; // zf
const char *v36; // rdi
__int64 v37; // rcx
const char *v38; // rsi
char v39; // dl
bool v40; // cf
bool v41; // zf
const char *v42; // rdi
__int64 v43; // rcx
const char *v44; // rsi
char v45; // dl
bool v46; // cf
bool v47; // zf
const char *v48; // rdi
__int64 v49; // rcx
const char *v50; // rsi
char v51; // dl
bool v52; // cf
bool v53; // zf
const char *v54; // rdi
__int64 v55; // rcx
const char *v56; // rsi
char v57; // dl
bool v58; // cf
bool v59; // zf
const char *v60; // rdi
__int64 v61; // rcx
const char *v62; // rsi
char v63; // dl
bool v64; // cf
bool v65; // zf
const char *v66; // rdi
__int64 v67; // rcx
const char *v68; // rsi
char v69; // dl
bool v70; // cf
bool v71; // zf
const char *v72; // rdi
__int64 v73; // rcx
const char *v74; // rsi
__int64 v76; // rsi

v3 = a2;
v4 = strcmp(a2, "~") != 0;
v5 = 0;
v6 = !v4;
if ( !v4 )
return kinvert(a1);
v7 = (const char *)&unk_2A1;
v8 = 2LL;
do
{
if ( !v8 )
break;
v5 = *a2 < (unsigned int)*v7;
v6 = *a2++ == *v7++;
--v8;
}
while ( v6 );
v9 = (!v5 && !v6) - v5;
v10 = 0;
v11 = v9 == 0;
if ( !v9 )
return kclear(a1, a2);
v12 = (const char *)&unk_2A3;
v13 = 2LL;
v14 = v3;
do
{
if ( !v13 )
break;
v10 = *v14 < (unsigned int)*v12;
v11 = *v14++ == *v12++;
--v13;
}
while ( v11 );
v15 = (!v10 && !v11) - v10;
v16 = 0;
v17 = v15 == 0;
if ( !v15 )
return kor(a1, v14);
v18 = (const char *)&unk_2A5;
v19 = 2LL;
v20 = v3;
do
{
if ( !v19 )
break;
v16 = *v20 < (unsigned int)*v18;
v17 = *v20++ == *v18++;
--v19;
}
while ( v17 );
v21 = (!v16 && !v17) - v16;
v22 = 0;
v23 = v21 == 0;
if ( !v21 )
return kand(a1, v20);
v24 = (const char *)&unk_2A7;
v25 = 2LL;
v26 = v3;
do
{
if ( !v25 )
break;
v22 = *v26 < (unsigned int)*v24;
v23 = *v26++ == *v24++;
--v25;
}
while ( v23 );
v27 = (!v22 && !v23) - v22;
v28 = 0;
v29 = v27 == 0;
if ( !v27 )
return krepeat(a1, v26);
v30 = (const char *)&unk_2A9;
v31 = 2LL;
v32 = v3;
do
{
if ( !v31 )
break;
v28 = *v32 < (unsigned int)*v30;
v29 = *v32++ == *v30++;
--v31;
}
while ( v29 );
v33 = (!v28 && !v29) - v28;
v34 = 0;
v35 = v33 == 0;
if ( !v33 )
return kpattern(a1, v32);
v36 = (const char *)&unk_2AB;
v37 = 3LL;
v38 = v3;
do
{
if ( !v37 )
break;
v34 = *v38 < (unsigned int)*v36;
v35 = *v38++ == *v36++;
--v37;
}
while ( v35 );
v39 = (!v34 && !v35) - v34;
v40 = 0;
v41 = v39 == 0;
if ( !v39 )
return krleft(a1, v38);
v42 = (const char *)&unk_2AE;
v43 = 3LL;
v44 = v3;
do
{
if ( !v43 )
break;
v40 = *v44 < (unsigned int)*v42;
v41 = *v44++ == *v42++;
--v43;
}
while ( v41 );
v45 = (!v40 && !v41) - v40;
v46 = 0;
v47 = v45 == 0;
if ( !v45 )
return krright(a1, v44);
v48 = (const char *)&unk_2B1;
v49 = 2LL;
v50 = v3;
do
{
if ( !v49 )
break;
v46 = *v50 < (unsigned int)*v48;
v47 = *v50++ == *v48++;
--v49;
}
while ( v47 );
v51 = (!v46 && !v47) - v46;
v52 = 0;
v53 = v51 == 0;
if ( !v51 )
return kpleft(a1, v50);
v54 = (const char *)&unk_2B3;
v55 = 2LL;
v56 = v3;
do
{
if ( !v55 )
break;
v52 = *v56 < (unsigned int)*v54;
v53 = *v56++ == *v54++;
--v55;
}
while ( v53 );
v57 = (!v52 && !v53) - v52;
v58 = 0;
v59 = v57 == 0;
if ( !v57 )
return kpright(a1, v56);
v60 = (const char *)&unk_2B5;
v61 = 2LL;
v62 = v3;
do
{
if ( !v61 )
break;
v58 = *v62 < (unsigned int)*v60;
v59 = *v62++ == *v60++;
--v61;
}
while ( v59 );
v63 = (!v58 && !v59) - v58;
v64 = 0;
v65 = v63 == 0;
if ( !v63 )
return ksubdiv(a1, v62);
v66 = (const char *)&unk_2B7;
v67 = 2LL;
v68 = v3;
do
{
if ( !v67 )
break;
v64 = *v68 < (unsigned int)*v66;
v65 = *v68++ == *v66++;
--v67;
}
while ( v65 );
v69 = (!v64 && !v65) - v64;
v70 = 0;
v71 = v69 == 0;
if ( !v69 )
return kset(a1, v68);
v72 = (const char *)&unk_2B9;
v73 = 2LL;
v74 = v3;
do
{
if ( !v73 )
break;
v70 = *v74 < (unsigned int)*v72;
v71 = *v74++ == *v72++;
--v73;
}
while ( v71 );
if ( (!v70 && !v71) == v70 )
return kmix(a1, v74);
v76 = kparse(v3, v74);
if ( !v76 )
return 4LL;
spush(a1, v76);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(__int64 a1, const char *a2)
{
const char *v3; // rax
bool v4; // dl
bool v5; // cf
bool v6; // zf
const char *v7; // rdi
__int64 v8; // rcx
char v9; // dl
bool v10; // cf
bool v11; // zf
const char *v12; // rdi
__int64 v13; // rcx
const char *v14; // rsi
char v15; // dl
bool v16; // cf
bool v17; // zf
const char *v18; // rdi
__int64 v19; // rcx
const char *v20; // rsi
char v21; // dl
bool v22; // cf
bool v23; // zf
const char *v24; // rdi
__int64 v25; // rcx
const char *v26; // rsi
char v27; // dl
bool v28; // cf
bool v29; // zf
const char *v30; // rdi
__int64 v31; // rcx
const char *v32; // rsi
char v33; // dl
bool v34; // cf
bool v35; // zf
const char *v36; // rdi
__int64 v37; // rcx
const char *v38; // rsi
char v39; // dl
bool v40; // cf
bool v41; // zf
const char *v42; // rdi
__int64 v43; // rcx
const char *v44; // rsi
char v45; // dl
bool v46; // cf
bool v47; // zf
const char *v48; // rdi
__int64 v49; // rcx
const char *v50; // rsi
char v51; // dl
bool v52; // cf
bool v53; // zf
const char *v54; // rdi
__int64 v55; // rcx
const char *v56; // rsi
char v57; // dl
bool v58; // cf
bool v59; // zf
const char *v60; // rdi
__int64 v61; // rcx
const char *v62; // rsi
char v63; // dl
bool v64; // cf
bool v65; // zf
const char *v66; // rdi
__int64 v67; // rcx
const char *v68; // rsi
char v69; // dl
bool v70; // cf
bool v71; // zf
const char *v72; // rdi
__int64 v73; // rcx
const char *v74; // rsi
__int64 v76; // rsi

v3 = a2;
v4 = strcmp(a2, "~") != 0;
v5 = 0;
v6 = !v4;
if ( !v4 )
return kinvert(a1);
v7 = (const char *)&unk_2A1;
v8 = 2LL;
do
{
if ( !v8 )
break;
v5 = *a2 < (unsigned int)*v7;
v6 = *a2++ == *v7++;
--v8;
}
while ( v6 );
v9 = (!v5 && !v6) - v5;
v10 = 0;
v11 = v9 == 0;
if ( !v9 )
return kclear(a1, a2);
v12 = (const char *)&unk_2A3;
v13 = 2LL;
v14 = v3;
do
{
if ( !v13 )
break;
v10 = *v14 < (unsigned int)*v12;
v11 = *v14++ == *v12++;
--v13;
}
while ( v11 );
v15 = (!v10 && !v11) - v10;
v16 = 0;
v17 = v15 == 0;
if ( !v15 )
return kor(a1, v14);
v18 = (const char *)&unk_2A5;
v19 = 2LL;
v20 = v3;
do
{
if ( !v19 )
break;
v16 = *v20 < (unsigned int)*v18;
v17 = *v20++ == *v18++;
--v19;
}
while ( v17 );
v21 = (!v16 && !v17) - v16;
v22 = 0;
v23 = v21 == 0;
if ( !v21 )
return kand(a1, v20);
v24 = (const char *)&unk_2A7;
v25 = 2LL;
v26 = v3;
do
{
if ( !v25 )
break;
v22 = *v26 < (unsigned int)*v24;
v23 = *v26++ == *v24++;
--v25;
}
while ( v23 );
v27 = (!v22 && !v23) - v22;
v28 = 0;
v29 = v27 == 0;
if ( !v27 )
return krepeat(a1, v26);
v30 = (const char *)&unk_2A9;
v31 = 2LL;
v32 = v3;
do
{
if ( !v31 )
break;
v28 = *v32 < (unsigned int)*v30;
v29 = *v32++ == *v30++;
--v31;
}
while ( v29 );
v33 = (!v28 && !v29) - v28;
v34 = 0;
v35 = v33 == 0;
if ( !v33 )
return kpattern(a1, v32);
v36 = (const char *)&unk_2AB;
v37 = 3LL;
v38 = v3;
do
{
if ( !v37 )
break;
v34 = *v38 < (unsigned int)*v36;
v35 = *v38++ == *v36++;
--v37;
}
while ( v35 );
v39 = (!v34 && !v35) - v34;
v40 = 0;
v41 = v39 == 0;
if ( !v39 )
return krleft(a1, v38);
v42 = (const char *)&unk_2AE;
v43 = 3LL;
v44 = v3;
do
{
if ( !v43 )
break;
v40 = *v44 < (unsigned int)*v42;
v41 = *v44++ == *v42++;
--v43;
}
while ( v41 );
v45 = (!v40 && !v41) - v40;
v46 = 0;
v47 = v45 == 0;
if ( !v45 )
return krright(a1, v44);
v48 = (const char *)&unk_2B1;
v49 = 2LL;
v50 = v3;
do
{
if ( !v49 )
break;
v46 = *v50 < (unsigned int)*v48;
v47 = *v50++ == *v48++;
--v49;
}
while ( v47 );
v51 = (!v46 && !v47) - v46;
v52 = 0;
v53 = v51 == 0;
if ( !v51 )
return kpleft(a1, v50);
v54 = (const char *)&unk_2B3;
v55 = 2LL;
v56 = v3;
do
{
if ( !v55 )
break;
v52 = *v56 < (unsigned int)*v54;
v53 = *v56++ == *v54++;
--v55;
}
while ( v53 );
v57 = (!v52 && !v53) - v52;
v58 = 0;
v59 = v57 == 0;
if ( !v57 )
return kpright(a1, v56);
v60 = (const char *)&unk_2B5;
v61 = 2LL;
v62 = v3;
do
{
if ( !v61 )
break;
v58 = *v62 < (unsigned int)*v60;
v59 = *v62++ == *v60++;
--v61;
}
while ( v59 );
v63 = (!v58 && !v59) - v58;
v64 = 0;
v65 = v63 == 0;
if ( !v63 )
return ksubdiv(a1, v62);
v66 = (const char *)&unk_2B7;
v67 = 2LL;
v68 = v3;
do
{
if ( !v67 )
break;
v64 = *v68 < (unsigned int)*v66;
v65 = *v68++ == *v66++;
--v67;
}
while ( v65 );
v69 = (!v64 && !v65) - v64;
v70 = 0;
v71 = v69 == 0;
if ( !v69 )
return kset(a1, v68);
v72 = (const char *)&unk_2B9;
v73 = 2LL;
v74 = v3;
do
{
if ( !v73 )
break;
v70 = *v74 < (unsigned int)*v72;
v71 = *v74++ == *v72++;
--v73;
}
while ( v71 );
if ( (!v70 && !v71) == v70 )
return kmix(a1, v74);
v76 = kparse(v3, v74);
if ( !v76 )
return 4LL;
spush(a1, v76);
return 0LL;
}

original_code:
Error
kprocess(KRuntime *kruntime, char *token)
{
    Error error = E_OK;
    if (!strcmp(token, "~"))
        error = kinvert(kruntime);
    else if (!strcmp(token, "@"))
        error = kclear(kruntime);
    else if (!strcmp(token, "|"))
        error = kor(kruntime);
    else if (!strcmp(token, "&"))
        error = kand(kruntime);
    else if (!strcmp(token, "*"))
        error = krepeat(kruntime);
    else if (!strcmp(token, "^"))
        error = kpattern(kruntime);
    else if (!strcmp(token, "<<"))
        error = krleft(kruntime);
    else if (!strcmp(token, ">>"))
        error = krright(kruntime);
    else if (!strcmp(token, "<"))
        error = kpleft(kruntime);
    else if (!strcmp(token, ">"))
        error = kpright(kruntime);
    else if (!strcmp(token, "/"))
        error = ksubdiv(kruntime);
    else if (!strcmp(token, "="))
        error = kset(kruntime);
    else if (!strcmp(token, "x"))
        error = kmix(kruntime);
    else {
        Kob *kob;
        kob = kparse(token);
        if (kob == EMPTY)
            return E_SYNTAX;
        spush(&kruntime->stack, kob);
    }
    return error;
}

canonical_original_code:
enum Error kprocess(struct KRuntime *kruntime, char *token)
{
    enum Error error = E_OK;
    if (!strcmp(token, "~"))
        error = kinvert(kruntime);
    else if (!strcmp(token, "@"))
        error = kclear(kruntime);
    else if (!strcmp(token, "|"))
        error = kor(kruntime);
    else if (!strcmp(token, "&"))
        error = kand(kruntime);
    else if (!strcmp(token, "*"))
        error = krepeat(kruntime);
    else if (!strcmp(token, "^"))
        error = kpattern(kruntime);
    else if (!strcmp(token, "<<"))
        error = krleft(kruntime);
    else if (!strcmp(token, ">>"))
        error = krright(kruntime);
    else if (!strcmp(token, "<"))
        error = kpleft(kruntime);
    else if (!strcmp(token, ">"))
        error = kpright(kruntime);
    else if (!strcmp(token, "/"))
        error = ksubdiv(kruntime);
    else if (!strcmp(token, "="))
        error = kset(kruntime);
    else if (!strcmp(token, "x"))
        error = kmix(kruntime);
    else {
        enum Kob *kob;
        kob = kparse(token);
        if (kob == EMPTY)
            return E_SYNTAX;
        spush(&kruntime->stack, kob);
    }
    return error;
}


printreport

decompiled_code:
int __fastcall printreport(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, const char *a8, __int64 a9)
{
int result; // eax

printf("%s:%u:%u: ", a8, (unsigned int)a9, HIDWORD(a9));
result = a7;
switch ( a7 )
{
case 0:
result = puts("Ok.");
break;
case 1:
result = puts("Type error.");
break;
case 2:
result = puts("Arity error.");
break;
case 3:
result = puts("Name error.");
break;
case 4:
result = puts("Syntax error.");
break;
case 5:
result = puts("File error.");
break;
default:
return result;
}
return result;
}

canonical_decompiled_code:
int __fastcall func0(__int64 a1, __int64 a2, __int64 a3, __int64 a4, __int64 a5, __int64 a6, int a7, const char *a8, __int64 a9)
{
int result; // eax

printf("%s:%u:%u: ", a8, (unsigned int)a9, HIDWORD(a9));
result = a7;
switch ( a7 )
{
case 0:
result = puts("Ok.");
break;
case 1:
result = puts("Type error.");
break;
case 2:
result = puts("Arity error.");
break;
case 3:
result = puts("Name error.");
break;
case 4:
result = puts("Syntax error.");
break;
case 5:
result = puts("File error.");
break;
default:
return result;
}
return result;
}

original_code:
void
printreport(KReport kreport)
{
    printf("%s:%u:%u: ",
           kreport.filename,
           kreport.line_id,
           kreport.token_id);
    switch (kreport.error) {
        case E_OK:
            (void) puts("Ok.");
            break;
        case E_TYPE:
            (void) puts("Type error.");
            break;
        case E_ARITY:
            (void) puts("Arity error.");
            break;
        case E_NAME:
            (void) puts("Name error.");
            break;
        case E_SYNTAX:
            (void) puts("Syntax error.");
            break;
        case E_FILE:
            (void) puts("File error.");
            break;
    }
}

canonical_original_code:
void printreport(struct KReport kreport)
{
    printf("%s:%u:%u: ",
           kreport.filename,
           kreport.line_id,
           kreport.token_id);
    switch (kreport.error) {
        case E_OK:
            (void) puts("Ok.");
            break;
        case E_TYPE:
            (void) puts("Type error.");
            break;
        case E_ARITY:
            (void) puts("Arity error.");
            break;
        case E_NAME:
            (void) puts("Name error.");
            break;
        case E_SYNTAX:
            (void) puts("Syntax error.");
            break;
        case E_FILE:
            (void) puts("File error.");
            break;
    }
}

variable_types: struct KReport { enum Error { E_OK=0, E_TYPE=1, E_ARITY=2, E_NAME=3, E_SYNTAX=4, E_FILE=5 } error; char *filename; unsigned int line_id; unsigned int token_id; }

user_defined_types: struct KReport { enum Error error; char *filename; unsigned int line_id; unsigned int token_id; }


decompiled_code:
int __fastcall add_second_dic(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rbx
_QWORD *v4; // rax

v2 = Marcov3Used;
v3 = 16LL * Marcov3Used + 4477184;
qword_445108[2 * Marcov3Used] = a2;
LODWORD(v4) = v2 + 1;
Marcov3Used = (int)v4;
if ( (int)v4 > 490 )
LODWORD(v4) = puts("louise_love : MarkovList3 memory leaked.");
if ( *(_DWORD *)a1 )
{
v4 = getWordList(*(_QWORD **)(a1 + 8), *(_DWORD *)a1 - 1);
*v4 = v3;
++*(_DWORD *)a1;
}
else
{
*(_QWORD *)(a1 + 8) = v3;
*(_DWORD *)a1 = 1;
}
return (int)v4;
}

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

v2 = Marcov3Used;
v3 = 16LL * Marcov3Used + 4477184;
qword_445108[2 * Marcov3Used] = a2;
LODWORD(v4) = v2 + 1;
Marcov3Used = (int)v4;
if ( (int)v4 > 490 )
LODWORD(v4) = puts("louise_love : MarkovList3 memory leaked.");
if ( *(_DWORD *)a1 )
{
v4 = getWordList(*(_QWORD **)(a1 + 8), *(_DWORD *)a1 - 1);
*v4 = v3;
++*(_DWORD *)a1;
}
else
{
*(_QWORD *)(a1 + 8) = v3;
*(_DWORD *)a1 = 1;
}
return (int)v4;
}

original_code:
void add_second_dic(struct SecondStageDic* dic,const struct Word* word){
 struct WordList* insert = &MarcovList3[Marcov3Used];
 insert->word = word;
 Marcov3Used++;
 if(Marcov3Used > ((491)-1)){
  printf("" "louise_love : MarkovList3 memory leaked.\n");
 }
 if(dic->list_size == 0){
  dic->list = insert;
  dic->list_size=1;
 }else{
  struct WordList* last = getWordList(dic->list,dic->list_size-1);
  last->next = insert;
  dic->list_size++;
 }
}

canonical_original_code:
void add_second_dic(struct SecondStageDic *dic, struct Word *word){
 struct WordList *insert = &MarcovList3[Marcov3Used];
 insert->word = word;
 Marcov3Used++;
 if(Marcov3Used > ((491)-1)){
  printf("" "louise_love : MarkovList3 memory leaked.\n");
 }
 if(dic->list_size == 0){
  dic->list = insert;
  dic->list_size=1;
 }else{
  struct WordList *last = getWordList(dic->list,dic->list_size-1);
  last->next = insert;
  dic->list_size++;
 }
}

variable_types: struct SecondStageDic { int list_size; struct WordList { struct WordList *next; struct Word { short id; short surface; short reading; short pos; } *word; } *list; } *

variable_types:
word
struct Word *

user_defined_types: struct SecondStageDic { int list_size; struct WordList *list; }

user_defined_types: struct WordList { struct WordList *next; struct Word *word; }


decompiled_code:
int __fastcall add_first_dic(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rbx
_QWORD *v4; // rax
int v5; // esi

v2 = Marcov2Used;
v3 = 16LL * Marcov2Used + 4485056;
qword_446FC8[2 * Marcov2Used] = a2;
LODWORD(v4) = v2 + 1;
Marcov2Used = (int)v4;
if ( (int)v4 > 491 )
LODWORD(v4) = puts("louise_love : MarkovList3 memory leaked.");
v5 = *(_DWORD *)(a1 + 2032);
if ( v5 )
{
v4 = getWordList(*(_QWORD **)(a1 + 2040), v5 - 1);
*v4 = v3;
++*(_DWORD *)(a1 + 2032);
}
else
{
*(_QWORD *)(a1 + 2040) = v3;
*(_DWORD *)(a1 + 2032) = 1;
}
return (int)v4;
}

canonical_decompiled_code:
int __fastcall func8(__int64 a1, __int64 a2)
{
int v2; // eax
__int64 v3; // rbx
_QWORD *v4; // rax
int v5; // esi

v2 = Marcov2Used;
v3 = 16LL * Marcov2Used + 4485056;
qword_446FC8[2 * Marcov2Used] = a2;
LODWORD(v4) = v2 + 1;
Marcov2Used = (int)v4;
if ( (int)v4 > 491 )
LODWORD(v4) = puts("louise_love : MarkovList3 memory leaked.");
v5 = *(_DWORD *)(a1 + 2032);
if ( v5 )
{
v4 = getWordList(*(_QWORD **)(a1 + 2040), v5 - 1);
*v4 = v3;
++*(_DWORD *)(a1 + 2032);
}
else
{
*(_QWORD *)(a1 + 2040) = v3;
*(_DWORD *)(a1 + 2032) = 1;
}
return (int)v4;
}

original_code:
void add_first_dic(struct FirstStageDic* dic,const struct Word* word){
 struct WordList* insert = &MarcovList2[Marcov2Used];
 insert->word = word;
 Marcov2Used++;
 if(Marcov2Used > (491)){
  printf("" "louise_love : MarkovList3 memory leaked.\n");
 }
 if(dic->list_size == 0){
  dic->list = insert;
  dic->list_size=1;
 }else{
  struct WordList* last = getWordList(dic->list,dic->list_size-1);
  last->next = insert;
  dic->list_size++;
 }
}

canonical_original_code:
void add_first_dic(struct FirstStageDic *dic, struct Word *word){
 struct WordList *insert = &MarcovList2[Marcov2Used];
 insert->word = word;
 Marcov2Used++;
 if(Marcov2Used > (491)){
  printf("" "louise_love : MarkovList3 memory leaked.\n");
 }
 if(dic->list_size == 0){
  dic->list = insert;
  dic->list_size=1;
 }else{
  struct WordList *last = getWordList(dic->list,dic->list_size-1);
  last->next = insert;
  dic->list_size++;
 }
}

variable_types: struct FirstStageDic { struct SecondStageDic { int list_size; struct WordList { struct WordList *next; struct Word { short id; short surface; short reading; short pos; } *word; } *list; } next[-1]; int list_size; struct WordList *list; } *

user_defined_types: struct FirstStageDic { struct SecondStageDic next[-1]; int list_size; struct WordList *list; }


buildDictionary

decompiled_code:
int buildDictionary()
{
int result; // eax
_WORD *v1; // rbx
__int16 i; // r12
__int16 v3; // bp

memset(&Dic, 0, 0x3F800uLL);
result = 0;
memset(&MarcovList2, 0, 0x1EB0uLL);
memset(&MarcovList3, 0, 0x1EA0uLL);
v1 = &unk_402568;
for ( i = -1; ; i = v3 )
{
v3 = *(v1 - 2);
if ( v1 == (_WORD *)&_GNU_EH_FRAME_HDR )
break;
if ( v3 >= 0 )
{
result = add_first_dic(((__int64)v3 << 11) + 4217088, (__int64)v1);
if ( i >= 0 )
result = add_second_dic(16 * (v3 + ((__int64)i << 7)) + 4217088, (__int64)v1);
}
v1 += 4;
}
return result;
}

original_code:
void buildDictionary(void){
 short i;
 short beforebefore = -1;
 short before = -1;
 memset(Dic,0,sizeof(Dic));
 memset(MarcovList2,0,sizeof(MarcovList2));
 memset(MarcovList3,0,sizeof(MarcovList3));
 for(i=0;i<(491);i++){
  const struct Word* copipe = &Copipe[i];
  if(before >= 0){
   struct FirstStageDic* dic = &Dic[before];
   add_first_dic(dic,copipe);
   if(beforebefore >= 0){
    struct SecondStageDic* second_dic = &(Dic[beforebefore].next[before]);
    add_second_dic(second_dic,copipe);
   }
  }
  beforebefore = before;
  before = copipe->reading;
 }
}

canonical_original_code:
void buildDictionary(){
 short i;
 short beforebefore = -1;
 short before = -1;
 memset(Dic,0,sizeof(Dic));
 memset(MarcovList2,0,sizeof(MarcovList2));
 memset(MarcovList3,0,sizeof(MarcovList3));
 for(i=0;i<(491);i++){
  struct Word *copipe = &Copipe[i];
  if(before >= 0){
   struct FirstStageDic *dic = &Dic[before];
   add_first_dic(dic,copipe);
   if(beforebefore >= 0){
    struct SecondStageDic *second_dic = &(Dic[beforebefore].next[before]);
    add_second_dic(second_dic,copipe);
   }
  }
  beforebefore = before;
  before = copipe->reading;
 }
}

variable_types: i short

variable_types: beforebefore short

variable_types: before short

variable_types: struct Word { short id; short surface; short reading; short pos; } *


nextRand

decompiled_code:
__int64 __fastcall nextRand(__int64 a1)
{
unsigned int v1; // eax

v1 = 214013 * *(_DWORD *)(a1 + 12) + 2531011;
*(_DWORD *)(a1 + 12) = v1;
return HIWORD(v1) & 0x7FFF;
}

original_code:
unsigned int nextRand(struct CopipeStatus* status){
 unsigned int result;
 status->seed *= 214013;
 status->seed += 2531011;
 result = status->seed;
 result = result >> 0x10;
 result &= 0x7fff;
 return result;
}

canonical_original_code:
unsigned int nextRand(struct CopipeStatus *status){
 unsigned int result;
 status->seed *= 214013;
 status->seed += 2531011;
 result = status->seed;
 result = result >> 0x10;
 result &= 0x7fff;
 return result;
}

variable_types: struct CopipeStatus { short beforebefore; short before; short now; short now_str; short now_str_size; short now_str_ptr; unsigned int seed; } *

variable_types:
result
unsigned int

return_type: unsigned int


initCopipeStatus

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

*(_WORD *)a1 = -1;
*(_WORD *)(a1 + 2) = -1;
*(_WORD *)(a1 + 4) = 0;
*(_WORD *)(a1 + 6) = 0;
result = strlen(Surface);
*(_DWORD *)(a1 + 8) = (unsigned __int16)result;
*(_DWORD *)(a1 + 12) = 0;
return result;
}

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

*(_WORD *)a1 = -1;
*(_WORD *)(a1 + 2) = -1;
*(_WORD *)(a1 + 4) = 0;
*(_WORD *)(a1 + 6) = 0;
result = strlen(Surface);
*(_DWORD *)(a1 + 8) = (unsigned __int16)result;
*(_DWORD *)(a1 + 12) = 0;
return result;
}

original_code:
void initCopipeStatus(struct CopipeStatus* status){
 status->beforebefore=-1;
 status->before=-1;
 status->now=0;
 status->now_str = 0;
 status->now_str_size = strlen(Surface[status->now_str]);
 status->now_str_ptr = 0;
 status->seed = 0;
}

canonical_original_code:
void initCopipeStatus(struct CopipeStatus *status){
 status->beforebefore=-1;
 status->before=-1;
 status->now=0;
 status->now_str = 0;
 status->now_str_size = strlen(Surface[status->now_str]);
 status->now_str_ptr = 0;
 status->seed = 0;
}

user_defined_types: struct CopipeStatus { short beforebefore; short before; short now; short now_str; short now_str_size; short now_str_ptr; unsigned int seed; }


main

canonical_name: main

decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_WORD v3[12]; // [rsp+0h] [rbp-18h] BYREF

buildDictionary();
initCopipeStatus((__int64)v3);
while ( 1 )
{
printf("%s", (&Surface)[v3[3]]);
nextCopipeStatus((__int64)v3);
}
}

canonical_decompiled_code:
int __cdecl __noreturn main(int argc, const char **argv, const char **envp)
{
_WORD v3[12]; // [rsp+0h] [rbp-18h] BYREF

func9();
func11((__int64)v3);
while ( 1 )
{
printf("%s", (&Surface)[v3[3]]);
func12((__int64)v3);
}
}

original_code:
int main(int argc,char* argv[]){
 buildDictionary();
 int i;
 struct CopipeStatus status;
 initCopipeStatus(&status);
 for(;;){
  printf("%s",Surface[status.now_str]);
  nextCopipeStatus(&status);
 }
}

canonical_original_code:
int main(int argc, char *argv[]){
 buildDictionary();
 int i;
 struct CopipeStatus status;
 initCopipeStatus(&status);
 for(;;){
  printf("%s",Surface[status.now_str]);
  nextCopipeStatus(&status);
 }
}

variable_types: argc int

variable_types:
argv
char *[]

variable_types: i int

variable_types: struct CopipeStatus { short beforebefore; short before; short now; short now_str; short now_str_size; short now_str_ptr; unsigned int seed; }


repo: leecbaker/colorbase

decompiled_code:
int __cdecl main(int argc, const char **argv, const char **envp)
{
unsigned int v3; // eax

while ( 1 )
{
v3 = getchar();
if ( v3 == -1 )
break;
printf("\x1B[30m%c", v3);
}
printf("\x1B[30m%c", 0xFFFFFFFFLL);
return 0;
}

original_code:
int main() {
 while(1) {
  int ch = getchar();
  switch(ch) {
   case (-1):
    printf("\e[30m%c",ch);
    return 0;
   case 'A':
   case 'a':
    printf("\e[32m%c", ch);
    break;
   case 'C':
   case 'c':
    printf("\e[34m%c", ch);
    break;
   case 'G':
   case 'g':
    printf("\e[33m%c", ch);
    break;
   case 'T':
   case 't':
    printf("\e[31m%c", ch);
    break;
   default:
    printf("\e[30m%c",ch);
    break;
  }
 }
}

variable_types: ch int


repo: leevon/rhizel

decompiled_code:
__int64 __fastcall find_section(__int64 a1, const char *a2)
{
__int64 i; // rbx

for ( i = a1; i; i = *(_QWORD *)(i + 16) )
{
if ( *(_QWORD *)i && !strcmp(*(const char **)i, a2) )
break;
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func1(__int64 a1, const char *a2)
{
__int64 i; // rbx

for ( i = a1; i; i = *(_QWORD *)(i + 16) )
{
if ( *(_QWORD *)i && !strcmp(*(const char **)i, a2) )
break;
}
return i;
}

original_code:
static struct cfg_section *find_section(struct cfg_section *sec_head, char *name)
{
    struct cfg_section *sec_curr = sec_head;
    while (sec_curr)
    {
        if (sec_curr->name && strcmp(sec_curr->name, name) == 0)
            return sec_curr;
        sec_curr = sec_curr->next;
    }
    return ((void *)0);
}

variable_types:
name
char *

variable_types: struct cfg_section { char *name; struct cfg_obj { char *name; char *value; struct cfg_obj *next; } *obj; struct cfg_section *next; } *

user_defined_types: struct cfg_section { char *name; struct cfg_obj *obj; struct cfg_section *next; }


decompiled_code:
void __fastcall cfg_free(void *ptr)
{
void **v1; // r12
void **v2; // r13
void **v3; // rbx
void **v4; // rbp

v1 = (void **)ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (void **)v1[2];
v3 = (void **)v2[1];
while ( v3 )
{
v4 = v3;
v3 = (void **)v3[2];
free(*v4);
free(v4[1]);
free(v4);
}
free(*v2);
free(v2);
}
while ( v1 );
}
}

canonical_decompiled_code:
void __fastcall func6(void *ptr)
{
void **v1; // r12
void **v2; // r13
void **v3; // rbx
void **v4; // rbp

v1 = (void **)ptr;
if ( ptr )
{
do
{
v2 = v1;
v1 = (void **)v1[2];
v3 = (void **)v2[1];
while ( v3 )
{
v4 = v3;
v3 = (void **)v3[2];
free(*v4);
free(v4[1]);
free(v4);
}
free(*v2);
free(v2);
}
while ( v1 );
}
}

original_code:
void cfg_free(cfg_st *handler)
{
    struct cfg_section *sec_curr = handler;
    struct cfg_section *next = ((void *)0);
    while (sec_curr)
    {
        next = sec_curr->next;
        struct cfg_obj *obj_curr = sec_curr->obj;
        struct cfg_obj *arg_next = ((void *)0);
        while (obj_curr)
        {
            arg_next = obj_curr->next;
            free(obj_curr->name);
            free(obj_curr->value);
            free(obj_curr);
            obj_curr = arg_next;
        }
        free(sec_curr->name);
        free(sec_curr);
        sec_curr = next;
    }
    return;
}

canonical_original_code:
void cfg_free(struct cfg_section *handler)
{
    struct cfg_section *sec_curr = handler;
    struct cfg_section *next = ((void *)0);
    while (sec_curr)
    {
        next = sec_curr->next;
        struct cfg_obj *obj_curr = sec_curr->obj;
        struct cfg_obj *arg_next = ((void *)0);
        while (obj_curr)
        {
            arg_next = obj_curr->next;
            free(obj_curr->name);
            free(obj_curr->value);
            free(obj_curr);
            obj_curr = arg_next;
        }
        free(sec_curr->name);
        free(sec_curr);
        sec_curr = next;
    }
    return;
}

variable_types: struct cfg_obj { char *name; char *value; struct cfg_obj *next; } *


decompiled_code:
__int64 __fastcall cfg_read_str(__int64 a1, const char *a2, const char *a3, char **a4, const char *a5)
{
__int64 v6; // rbx
const char *v7; // r14
__int64 v10; // rbx
char *v11; // rax
__int64 result; // rax
const char *v13; // r14
char *v14; // rax

if ( a4 == 0LL || a3 == 0LL )
return 0xFFFFFFFFLL;
v6 = a1;
v7 = a2;
if ( !a1 )
return 0xFFFFFFFFLL;
if ( a2 )
{
if ( !*a2 )
v7 = "global";
}
else
{
v7 = "global";
}
while ( !*(_QWORD *)v6 || strcmp(v7, *(const char **)v6) )
{
v6 = *(_QWORD *)(v6 + 16);
if ( !v6 )
goto LABEL_12;
}
v10 = *(_QWORD *)(v6 + 8);
if ( !v10 )
{
LABEL_12:
if ( a5 )
{
v11 = strdup(a5);
*a4 = v11;
result = v11 == 0LL ? -1 : 1;
}
else
{
*a4 = 0LL;
result = 1LL;
}
return result;
}
while ( 1 )
{
if ( *(_QWORD *)v10 )
{
v13 = *(const char **)(v10 + 8);
if ( v13 )
{
if ( !strcmp(*(const char **)v10, a3) )
break;
}
}
v10 = *(_QWORD *)(v10 + 16);
if ( !v10 )
goto LABEL_12;
}
v14 = strdup(v13);
*a4 = v14;
return (unsigned int)-(v14 == 0LL);
}

canonical_decompiled_code:
__int64 __fastcall func8(__int64 a1, const char *a2, const char *a3, char **a4, const char *a5)
{
__int64 v6; // rbx
const char *v7; // r14
__int64 v10; // rbx
char *v11; // rax
__int64 result; // rax
const char *v13; // r14
char *v14; // rax

if ( a4 == 0LL || a3 == 0LL )
return 0xFFFFFFFFLL;
v6 = a1;
v7 = a2;
if ( !a1 )
return 0xFFFFFFFFLL;
if ( a2 )
{
if ( !*a2 )
v7 = "global";
}
else
{
v7 = "global";
}
while ( !*(_QWORD *)v6 || strcmp(v7, *(const char **)v6) )
{
v6 = *(_QWORD *)(v6 + 16);
if ( !v6 )
goto LABEL_12;
}
v10 = *(_QWORD *)(v6 + 8);
if ( !v10 )
{
LABEL_12:
if ( a5 )
{
v11 = strdup(a5);
*a4 = v11;
result = v11 == 0LL ? -1 : 1;
}
else
{
*a4 = 0LL;
result = 1LL;
}
return result;
}
while ( 1 )
{
if ( *(_QWORD *)v10 )
{
v13 = *(const char **)(v10 + 8);
if ( v13 )
{
if ( !strcmp(*(const char **)v10, a3) )
break;
}
}
v10 = *(_QWORD *)(v10 + 16);
if ( !v10 )
goto LABEL_12;
}
v14 = strdup(v13);
*a4 = v14;
return (unsigned int)-(v14 == 0LL);
}

original_code:
int cfg_read_str(cfg_st *handler,
        char *section, char *name, char **value, char *default_value)
{
    if (!handler || !name || !value)
        return -1;
    if (section == ((void *)0) || *section == 0)
        section = "global";
    struct cfg_section *sec_curr = handler;
    while (sec_curr)
    {
        if (sec_curr->name && strcmp(section, sec_curr->name) == 0)
            break;
        sec_curr = sec_curr->next;
    }
    if (sec_curr)
    {
        struct cfg_obj *obj = sec_curr->obj;
        while (obj)
        {
            if (obj->name && obj->value && strcmp(obj->name, name) == 0)
            {
                *value = strdup(obj->value);
                if (*value == ((void *)0))
                    return -1;
                return 0;
            }
            obj = obj->next;
        }
    }
    if (default_value)
    {
        *value = strdup(default_value);
        if (*value == ((void *)0))
            return -1;
    }
    else
    {
        *value = ((void *)0);
    }
    return 1;
}

canonical_original_code:
int cfg_read_str(struct cfg_section *handler, char *section, char *name, char **value, char *default_value)
{
    if (!handler || !name || !value)
        return -1;
    if (section == ((void *)0) || *section == 0)
        section = "global";
    struct cfg_section *sec_curr = handler;
    while (sec_curr)
    {
        if (sec_curr->name && strcmp(section, sec_curr->name) == 0)
            break;
        sec_curr = sec_curr->next;
    }
    if (sec_curr)
    {
        struct cfg_obj *obj = sec_curr->obj;
        while (obj)
        {
            if (obj->name && obj->value && strcmp(obj->name, name) == 0)
            {
                *value = strdup(obj->value);
                if (*value == ((void *)0))
                    return -1;
                return 0;
            }
            obj = obj->next;
        }
    }
    if (default_value)
    {
        *value = strdup(default_value);
        if (*value == ((void *)0))
            return -1;
    }
    else
    {
        *value = ((void *)0);
    }
    return 1;
}

variable_types:
section
char *

variable_types:
value
char **

user_defined_types: struct cfg_obj { char *name; char *value; struct cfg_obj *next; }


decompiled_code:
__int64 __fastcall cfg_read_strn(__int64 a1, const char *a2, const char *a3, void *a4, size_t a5, const char *a6)
{
int v8; // ebx
char *v9; // r13
char *src; // [rsp+8h] [rbp-30h] BYREF

src = 0LL;
v8 = cfg_read_str(a1, a2, a3, &src, a6);
if ( v8 >= 0 )
{
memset(a4, 0, a5);
v9 = src;
if ( src )
{
strncpy((char *)a4, src, a5);
free(v9);
}
}
return (unsigned int)v8;
}

canonical_decompiled_code:
__int64 __fastcall func10(__int64 a1, const char *a2, const char *a3, void *a4, size_t a5, const char *a6)
{
int v8; // ebx
char *v9; // r13
char *src; // [rsp+8h] [rbp-30h] BYREF

src = 0LL;
v8 = func8(a1, a2, a3, &src, a6);
if ( v8 >= 0 )
{
memset(a4, 0, a5);
v9 = src;
if ( src )
{
strncpy((char *)a4, src, a5);
free(v9);
}
}
return (unsigned int)v8;
}

original_code:
int cfg_read_strn(cfg_st *handler,
        char *section, char *name, char *value, size_t n, char *default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, default_value);
    if (ret < 0)
        return ret;
    memset(value, 0, n);
    if (s)
    {
        strncpy(value, s, n);
        free(s);
    }
    return ret;
}

canonical_original_code:
int cfg_read_strn(struct cfg_section *handler, char *section, char *name, char *value, unsigned long n, char *default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, default_value);
    if (ret < 0)
        return ret;
    memset(value, 0, n);
    if (s)
    {
        strncpy(value, s, n);
        free(s);
    }
    return ret;
}

variable_types:
value
char *

variable_types:
n
unsigned long

variable_types:
s
char *

variable_types: ret int


decompiled_code:
__int64 __fastcall cfg_read_int(__int64 a1, const char *a2, const char *a3, _DWORD *a4, int a5)
{
__int64 result; // rax
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

result = ini_read_num(a1, a2, a3, v8, 0);
if ( (_DWORD)result )
{
if ( (int)result > 0 )
*a4 = a5;
}
else
{
*a4 = v8[0];
}
return result;
}

canonical_decompiled_code:
__int64 __fastcall func11(__int64 a1, const char *a2, const char *a3, _DWORD *a4, int a5)
{
__int64 result; // rax
__int64 v8[4]; // [rsp+8h] [rbp-20h] BYREF

result = func9(a1, a2, a3, v8, 0);
if ( (_DWORD)result )
{
if ( (int)result > 0 )
*a4 = a5;
}
else
{
*a4 = v8[0];
}
return result;
}

original_code:
int cfg_read_int(cfg_st *handler,
        char *section, char *name, int *value, int default_value)
{
    do { long long int v; int ret = ini_read_num(handler, section, name, &v, 0); if (ret == 0) { *value = (int)v; } else if (ret > 0) { *value = default_value; } return ret; } while (0);
}

canonical_original_code:
int cfg_read_int(struct cfg_section *handler, char *section, char *name, int *value, int default_value)
{
    do { long long v; int ret = ini_read_num(handler, section, name, &v, 0); if (ret == 0) { *value = (int)v; } else if (ret > 0) { *value = default_value; } return ret; } while (0);
}

variable_types:
value
int *

variable_types:
v
long long


decompiled_code:
__int64 __fastcall cfg_read_float(__int64 a1, const char *a2, const char *a3, int *a4, __m128i a5)
{
int v6; // er12
int v7; // eax
unsigned int v8; // ebx
char *nptr; // [rsp+8h] [rbp-20h] BYREF

v6 = _mm_cvtsi128_si32(a5);
nptr = 0LL;
v7 = cfg_read_str(a1, a2, a3, &nptr, 0LL);
v8 = v7;
if ( v7 )
{
if ( v7 > 0 )
*a4 = v6;
}
else
{
*(float *)a4 = strtof(nptr, 0LL);
free(nptr);
}
return v8;
}

canonical_decompiled_code:
__int64 __fastcall func12(__int64 a1, const char *a2, const char *a3, int *a4, __m128i a5)
{
int v6; // er12
int v7; // eax
unsigned int v8; // ebx
char *nptr; // [rsp+8h] [rbp-20h] BYREF

v6 = _mm_cvtsi128_si32(a5);
nptr = 0LL;
v7 = func8(a1, a2, a3, &nptr, 0LL);
v8 = v7;
if ( v7 )
{
if ( v7 > 0 )
*a4 = v6;
}
else
{
*(float *)a4 = strtof(nptr, 0LL);
free(nptr);
}
return v8;
}

original_code:
int cfg_read_float(cfg_st *handler,
        char *section, char *name, float *value, float default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, ((void *)0));
    if (ret == 0)
    {
        *value = strtof(s, ((void *)0));
        free(s);
    }
    else if (ret > 0)
    {
        *value = default_value;
    }
    return ret;
}

canonical_original_code:
int cfg_read_float(struct cfg_section *handler, char *section, char *name, float *value, float default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, ((void *)0));
    if (ret == 0)
    {
        *value = strtof(s, ((void *)0));
        free(s);
    }
    else if (ret > 0)
    {
        *value = default_value;
    }
    return ret;
}

variable_types:
value
float *


decompiled_code:
__int64 __fastcall cfg_read_double(__int64 a1, const char *a2, const char *a3, double *a4, double a5)
{
int v6; // eax
unsigned int v7; // ebx
char *nptr; // [rsp+8h] [rbp-20h] BYREF

nptr = 0LL;
v6 = cfg_read_str(a1, a2, a3, &nptr, 0LL);
v7 = v6;
if ( v6 )
{
if ( v6 > 0 )
*a4 = a5;
}
else
{
*a4 = strtod(nptr, 0LL);
free(nptr);
}
return v7;
}

canonical_decompiled_code:
__int64 __fastcall func13(__int64 a1, const char *a2, const char *a3, double *a4, double a5)
{
int v6; // eax
unsigned int v7; // ebx
char *nptr; // [rsp+8h] [rbp-20h] BYREF

nptr = 0LL;
v6 = func8(a1, a2, a3, &nptr, 0LL);
v7 = v6;
if ( v6 )
{
if ( v6 > 0 )
*a4 = a5;
}
else
{
*a4 = strtod(nptr, 0LL);
free(nptr);
}
return v7;
}

original_code:
int cfg_read_double(cfg_st *handler,
        char *section, char *name, double *value, double default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, ((void *)0));
    if (ret == 0)
    {
        *value = strtod(s, ((void *)0));
        free(s);
    }
    else if (ret > 0)
    {
        *value = default_value;
    }
    return ret;
}

canonical_original_code:
int cfg_read_double(struct cfg_section *handler, char *section, char *name, double *value, double default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, ((void *)0));
    if (ret == 0)
    {
        *value = strtod(s, ((void *)0));
        free(s);
    }
    else if (ret > 0)
    {
        *value = default_value;
    }
    return ret;
}

variable_types:
value
double *


decompiled_code:
__int64 __fastcall cfg_read_ipv4_addr(__int64 a1, const char *a2, const char *a3, __int64 a4, const char *a5)
{
int v6; // ebx
char *v7; // r12
char *v8; // r13
__int16 v9; // ax
char *s; // [rsp+8h] [rbp-30h] BYREF

s = 0LL;
v6 = cfg_read_str(a1, a2, a3, &s, a5);
if ( v6 >= 0 )
{
*(_QWORD *)a4 = 0LL;
*(_QWORD *)(a4 + 8) = 0LL;
if ( s )
{
v7 = strtok(s, ": \t");
if ( v7 && (v8 = strtok(0LL, ": \t")) != 0LL && (*(_WORD *)a4 = 2, inet_aton(v7, (struct in_addr *)(a4 + 4))) )
{
v9 = atoi(v8);
*(_WORD *)(a4 + 2) = _bswap_16(v9);
free(s);
}
else
{
free(s);
v6 = -1;
}
}
}
return (unsigned int)v6;
}

canonical_decompiled_code:
__int64 __fastcall func14(__int64 a1, const char *a2, const char *a3, __int64 a4, const char *a5)
{
int v6; // ebx
char *v7; // r12
char *v8; // r13
__int16 v9; // ax
char *s; // [rsp+8h] [rbp-30h] BYREF

s = 0LL;
v6 = func8(a1, a2, a3, &s, a5);
if ( v6 >= 0 )
{
*(_QWORD *)a4 = 0LL;
*(_QWORD *)(a4 + 8) = 0LL;
if ( s )
{
v7 = strtok(s, ": \t");
if ( v7 && (v8 = strtok(0LL, ": \t")) != 0LL && (*(_WORD *)a4 = 2, inet_aton(v7, (struct in_addr *)(a4 + 4))) )
{
v9 = atoi(v8);
*(_WORD *)(a4 + 2) = func5(v9);
free(s);
}
else
{
free(s);
v6 = -1;
}
}
}
return (unsigned int)v6;
}

original_code:
int cfg_read_ipv4_addr(cfg_st *handler,
        char *section, char *name, struct sockaddr_in *addr, char *default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, default_value);
    if (ret < 0)
        return ret;
    memset(addr, 0, sizeof(struct sockaddr_in));
    if (s)
    {
        char *ip = strtok(s, ": \t");
        if (ip == ((void *)0))
        {
            free(s);
            return -1;
        }
        char *port = strtok(((void *)0), ": \t");
        if (port == ((void *)0))
        {
            free(s);
            return -1;
        }
        addr->sin_family = 2;
        if (inet_aton(ip, &addr->sin_addr) == 0)
        {
            free(s);
            return -1;
        }
        addr->sin_port = htons((uint16_t)atoi(port));
        free(s);
    }
    return ret;
}

canonical_original_code:
int cfg_read_ipv4_addr(struct cfg_section *handler, char *section, char *name, struct sockaddr_in *addr, char *default_value)
{
    char *s = ((void *)0);
    int ret = cfg_read_str(handler, section, name, &s, default_value);
    if (ret < 0)
        return ret;
    memset(addr, 0, sizeof(struct sockaddr_in));
    if (s)
    {
        char *ip = strtok(s, ": \t");
        if (ip == ((void *)0))
        {
            free(s);
            return -1;
        }
        char *port = strtok(((void *)0), ": \t");
        if (port == ((void *)0))
        {
            free(s);
            return -1;
        }
        addr->sin_family = 2;
        if (inet_aton(ip, &addr->sin_addr) == 0)
        {
            free(s);
            return -1;
        }
        addr->sin_port = htons((unsigned short)atoi(port));
        free(s);
    }
    return ret;
}

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

variable_types:
ip
char *

variable_types:
port
char *

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