getKey

original_code:
int getKey(char usrKey[], unsigned char ** keys)
{
 int size = strlen(usrKey);
 int numKeys = size / 2;
 int i = 0, tmp = 0;
 unsigned char * tkp;
 if(size % 2 == 1 || size == 0)
 {
  keys = ((void *)0);
  return -1;
 }
 *keys = (unsigned char *)malloc(sizeof(unsigned char) * numKeys);
 if(*keys != ((void *)0))
  tkp = *keys;
 while(usrKey[i] != '\0')
 {
  switch(usrKey[i])
  {
   case '0':
    break;
   case '1':
    if(i % 2 == 0)
     tmp |= 0x10;
    else
     tmp |= 0x01;
    break;
   case '2':
    if(i % 2 == 0)
     tmp |= 0x20;
    else
     tmp |= 0x02;
    break;
   case '3':
    if(i % 2 == 0)
     tmp |= 0x30;
    else
     tmp |= 0x03;
    break;
   case '4':
    if(i % 2 == 0)
     tmp |= 0x40;
    else
     tmp |= 0x04;
    break;
   case '5':
    if(i % 2 == 0)
     tmp |= 0x50;
    else
     tmp |= 0x05;
    break;
   case '6':
    if(i % 2 == 0)
     tmp |= 0x60;
    else
     tmp |= 0x06;
    break;
   case '7':
    if(i % 2 == 0)
     tmp |= 0x70;
    else
     tmp |= 0x07;
    break;
   case '8':
    if(i % 2 == 0)
     tmp |= 0x80;
    else
     tmp |= 0x08;
    break;
   case '9':
    if(i % 2 == 0)
     tmp |= 0x90;
    else
     tmp |= 0x09;
    break;
   case 'a':
   case 'A':
    if(i % 2 == 0)
     tmp |= 0xa0;
    else
     tmp |= 0x0a;
    break;
   case 'b':
   case 'B':
    if(i % 2 == 0)
     tmp |= 0xb0;
    else
     tmp |= 0x0b;
    break;
   case 'c':
   case 'C':
    if(i % 2 == 0)
     tmp |= 0xc0;
    else
     tmp |= 0x0c;
    break;
   case 'd':
   case 'D':
    if(i % 2 == 0)
     tmp |= 0xd0;
    else
     tmp |= 0x0d;
    break;
   case 'e':
   case 'E':
    if(i % 2 == 0)
     tmp |= 0xe0;
    else
     tmp |= 0x0e;
    break;
   case 'f':
   case 'F':
    if(i % 2 == 0)
     tmp |= 0xf0;
    else
     tmp |= 0x0f;
    break;
   default:
    free(*keys);
    return -1;
  }
  if(i % 2 == 1)
  {
   *tkp++ = (unsigned char)tmp;
   tmp = 0;
  }
  i++;
 }
 return numKeys;
}

canonical_original_code:
int getKey(char usrKey[], unsigned char **keys)
{
 int size = strlen(usrKey);
 int numKeys = size / 2;
 int i = 0; int tmp = 0;
 unsigned char *tkp;
 if(size % 2 == 1 || size == 0)
 {
  keys = ((void *)0);
  return -1;
 }
 *keys = (unsigned char *)malloc(sizeof(unsigned char) * numKeys);
 if(*keys != ((void *)0))
  tkp = *keys;
 while(usrKey[i] != '\0')
 {
  switch(usrKey[i])
  {
   case '0':
    break;
   case '1':
    if(i % 2 == 0)
     tmp |= 0x10;
    else
     tmp |= 0x01;
    break;
   case '2':
    if(i % 2 == 0)
     tmp |= 0x20;
    else
     tmp |= 0x02;
    break;
   case '3':
    if(i % 2 == 0)
     tmp |= 0x30;
    else
     tmp |= 0x03;
    break;
   case '4':
    if(i % 2 == 0)
     tmp |= 0x40;
    else
     tmp |= 0x04;
    break;
   case '5':
    if(i % 2 == 0)
     tmp |= 0x50;
    else
     tmp |= 0x05;
    break;
   case '6':
    if(i % 2 == 0)
     tmp |= 0x60;
    else
     tmp |= 0x06;
    break;
   case '7':
    if(i % 2 == 0)
     tmp |= 0x70;
    else
     tmp |= 0x07;
    break;
   case '8':
    if(i % 2 == 0)
     tmp |= 0x80;
    else
     tmp |= 0x08;
    break;
   case '9':
    if(i % 2 == 0)
     tmp |= 0x90;
    else
     tmp |= 0x09;
    break;
   case 'a':
   case 'A':
    if(i % 2 == 0)
     tmp |= 0xa0;
    else
     tmp |= 0x0a;
    break;
   case 'b':
   case 'B':
    if(i % 2 == 0)
     tmp |= 0xb0;
    else
     tmp |= 0x0b;
    break;
   case 'c':
   case 'C':
    if(i % 2 == 0)
     tmp |= 0xc0;
    else
     tmp |= 0x0c;
    break;
   case 'd':
   case 'D':
    if(i % 2 == 0)
     tmp |= 0xd0;
    else
     tmp |= 0x0d;
    break;
   case 'e':
   case 'E':
    if(i % 2 == 0)
     tmp |= 0xe0;
    else
     tmp |= 0x0e;
    break;
   case 'f':
   case 'F':
    if(i % 2 == 0)
     tmp |= 0xf0;
    else
     tmp |= 0x0f;
    break;
   default:
    free(*keys);
    return -1;
  }
  if(i % 2 == 1)
  {
   *tkp++ = (unsigned char)tmp;
   tmp = 0;
  }
  i++;
 }
 return numKeys;
}

variable_types: numKeys int

variable_types: tmp int

variable_types:
tkp
unsigned char *


repo: lecram/bbking

decompiled_code:
// attributes: thunk
int bb_clean(void)
{
return endwin();
}

canonical_decompiled_code:
int func0(void)
{
return endwin();
}

original_code:
void
bb_clean()
{
    endwin();
}

canonical_original_code:
void bb_clean()
{
    endwin();
}

return_type: void


decompiled_code:
int bb_init()
{
setlocale(6, &locale);
initscr();
cbreak();
noecho();
nonl();
intrflush(stdscr, 0);
keypad(stdscr, 1);
curs_set(0);
if ( has_colors() )
{
start_color();
init_pair(1, 1, 0);
init_pair(2, 2, 0);
init_pair(3, 3, 0);
init_pair(4, 4, 0);
init_pair(5, 6, 0);
init_pair(6, 5, 0);
init_pair(7, 7, 0);
}
return atexit((void (*)(void))bb_clean);
}

canonical_decompiled_code:
int func1()
{
setlocale(6, &locale);
initscr();
cbreak();
noecho();
nonl();
intrflush(stdscr, 0);
keypad(stdscr, 1);
curs_set(0);
if ( has_colors() )
{
start_color();
init_pair(1, 1, 0);
init_pair(2, 2, 0);
init_pair(3, 3, 0);
init_pair(4, 4, 0);
init_pair(5, 6, 0);
init_pair(6, 5, 0);
init_pair(7, 7, 0);
}
return atexit((void (*)(void))bb_clean);
}

original_code:
void
bb_init()
{
    setlocale(6, "");
    initscr();
    cbreak();
    noecho();
    nonl();
    intrflush(stdscr, 0);
    keypad(stdscr, 1);
    curs_set(0);
    if (has_colors()) {
        start_color();
        init_pair(RED, 1, 0);
        init_pair(GREEN, 2, 0);
        init_pair(YELLOW, 3, 0);
        init_pair(BLUE, 4, 0);
        init_pair(CYAN, 6, 0);
        init_pair(MAGENTA, 5, 0);
        init_pair(WHITE, 7, 0);
    }
    atexit(bb_clean);
}


input

decompiled_code:
int __fastcall input(char *a1, int a2)
{
int v2; // ebx

nocbreak();
echo();
curs_set(1);
if ( wmove(stdscr, LINES - 2, 0) != -1 )
wgetnstr(stdscr, a1, a2 - 1);
if ( COLS > 0 )
{
v2 = 0;
do
{
if ( wmove(stdscr, LINES - 2, v2) != -1 )
waddch(stdscr, 0x20uLL);
++v2;
}
while ( COLS > v2 );
}
cbreak();
noecho();
return curs_set(0);
}

canonical_decompiled_code:
int __fastcall func2(char *a1, int a2)
{
int v2; // ebx

nocbreak();
echo();
curs_set(1);
if ( wmove(stdscr, LINES - 2, 0) != -1 )
wgetnstr(stdscr, a1, a2 - 1);
if ( COLS > 0 )
{
v2 = 0;
do
{
if ( wmove(stdscr, LINES - 2, v2) != -1 )
waddch(stdscr, 0x20uLL);
++v2;
}
while ( COLS > v2 );
}
cbreak();
noecho();
return curs_set(0);
}

original_code:
void
input(char buffer[], int maxlen)
{
    int i;
    nocbreak();
    echo();
    curs_set(1);
    (wmove((stdscr),((LINES - 2)),((0))) == (-1) ? (-1) : wgetnstr((stdscr),((buffer)),((maxlen - 1))));
    for (i = 0; i < COLS; i++)
        (wmove((stdscr),((LINES - 2)),((i))) == (-1) ? (-1) : waddch((stdscr),((' '))));
    cbreak();
    noecho();
    curs_set(0);
}

variable_types:
buffer
char []

variable_types: maxlen int

variable_types: i int


interactive

repo: lecram/kibibeat

original_code:
void
interactive(KReport *kreport)
{
    char line[256];
    char token[32];
    char *c;
    int i;
    KRuntime *kruntime;
    KBuffer *kbuffer;
    kruntime = newruntime();
    kbuffer = newbuffer();
    while (1) {
        printf("> ");
        if (fgets(line, 256, stdin) == ((void *)0))
            break;
        if (strcmp(line, "exit\n") == 0)
            break;
        else {
            kreport->token_id = 0;
            c = line;
            while (1) {
                while (((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _ISspace) && *c != '\n')
                    c++;
                if (*c == '\n')
                    break;
                kreport->token_id++;
                for (i = 0; !((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short int) _ISspace); i++, c++)
                    token[i] = *c;
                token[i] = '\0';
                kreport->error = kprocess(kruntime, token);
                if (kreport->error != E_OK) {
                    delruntime(&kruntime);
                    delbuffer(&kbuffer);
                    return;
                }
            }
            repstack(kruntime->stack, kbuffer);
            printf("%s\n", kbuffer->buffer);
            repnable(kruntime->nable, kbuffer);
            printf("%s\n", kbuffer->buffer);
        }
    }
    delruntime(&kruntime);
    delbuffer(&kbuffer);
}

canonical_original_code:
void interactive(struct KReport *kreport)
{
    char line[256];
    char token[32];
    char *c;
    int i;
    struct KRuntime *kruntime;
    struct KBuffer *kbuffer;
    kruntime = newruntime();
    kbuffer = newbuffer();
    while (1) {
        printf("> ");
        if (fgets(line, 256, stdin) == ((void *)0))
            break;
        if (strcmp(line, "exit\n") == 0)
            break;
        else {
            kreport->token_id = 0;
            c = line;
            while (1) {
                while (((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _ISspace) && *c != '\n')
                    c++;
                if (*c == '\n')
                    break;
                kreport->token_id++;
                for (i = 0; !((*__ctype_b_loc ())[(int) ((*c))] & (unsigned short) _ISspace); i++, c++)
                    token[i] = *c;
                token[i] = '\0';
                kreport->error = kprocess(kruntime, token);
                if (kreport->error != E_OK) {
                    delruntime(&kruntime);
                    delbuffer(&kbuffer);
                    return;
                }
            }
            repstack(kruntime->stack, kbuffer);
            printf("%s\n", kbuffer->buffer);
            repnable(kruntime->nable, kbuffer);
            printf("%s\n", kbuffer->buffer);
        }
    }
    delruntime(&kruntime);
    delbuffer(&kbuffer);
}

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; } *

variable_types:
line
char [256]

variable_types:
token
char [32]

variable_types:
c
char *

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: struct KBuffer { unsigned long size; char *buffer; } *

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

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; }


main

canonical_name: main

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

LODWORD(v4) = 0;
v5 = (const char *)&unk_367;
v6 = 0x100000001LL;
if ( argc == 1 )
{
interactive(&v4);
}
else
{
if ( argc != 2 )
return 0;
v5 = argv[1];
run((__int64)&v4);
}
if ( !(_DWORD)v4 )
return 0;
printreport(&v4, argv);
return 1;
}

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

LODWORD(v4) = 0;
v5 = (const char *)&unk_367;
v6 = 0x100000001LL;
if ( argc == 1 )
{
func0(&v4);
}
else
{
if ( argc != 2 )
return 0;
v5 = argv[1];
func1((__int64)&v4);
}
if ( !(_DWORD)v4 )
return 0;
printreport(&v4, argv);
return 1;
}

original_code:
int
main(int argc, char *argv[])
{
    KReport kreport;
    kreport.error = E_OK;
    kreport.filename = "";
    kreport.line_id = 1;
    kreport.token_id = 1;
    if (argc == 1)
        interactive(&kreport);
    else if (argc == 2) {
        kreport.filename = argv[1];
        run(&kreport);
    }
    if (kreport.error != E_OK) {
        printreport(kreport);
        return 1;
    }
    return 0;
}

canonical_original_code:
int main(int argc, char *argv[])
{
    struct KReport kreport;
    kreport.error = E_OK;
    kreport.filename = "";
    kreport.line_id = 1;
    kreport.token_id = 1;
    if (argc == 1)
        interactive(&kreport);
    else if (argc == 2) {
        kreport.filename = argv[1];
        run(&kreport);
    }
    if (kreport.error != E_OK) {
        printreport(kreport);
        return 1;
    }
    return 0;
}

variable_types: argc int

variable_types:
argv
char *[]

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; }

return_type: int


krandom

decompiled_code:
double krandom()
{
return (double)rand() * 4.656612873077393e-10;
}

original_code:
double
krandom()
{
    return rand() / ((double) 2147483647 + 1);
}

return_type: double


trndlevel

decompiled_code:
__int64 __fastcall trndlevel(_DWORD *a1)
{
int v1; // er12
int v2; // ebx
double v3; // xmm0_8

v1 = 0;
v2 = (*a1 != 9) + *a1;
while ( 1 )
{
v3 = krandom();
if ( v1 >= v2 || v3 >= 0.5 )
break;
++v1;
}
return (unsigned int)v1;
}

canonical_decompiled_code:
__int64 __fastcall func1(_DWORD *a1)
{
int v1; // er12
int v2; // ebx
double v3; // xmm0_8

v1 = 0;
v2 = (*a1 != 9) + *a1;
while ( 1 )
{
v3 = func0();
if ( v1 >= v2 || v3 >= 0.5 )
break;
++v1;
}
return (unsigned int)v1;
}

original_code:
int
trndlevel(KNable *knable)
{
    int level = 0;
    int max;
    if (knable->level == 10 - 1)
        max = 10 - 1;
    else
        max = knable->level + 1;
    while (krandom() < 0.5 && level < max)
        level++;
    return level;
}

canonical_original_code:
int trndlevel(struct KNable *knable)
{
    int level = 0;
    int max;
    if (knable->level == 10 - 1)
        max = 10 - 1;
    else
        max = knable->level + 1;
    while (krandom() < 0.5 && level < max)
        level++;
    return level;
}

variable_types: 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; } *

variable_types: level int

variable_types: max int


delentry

decompiled_code:
void __fastcall delentry(void ***a1)
{
free(**a1);
free((*a1)[2]);
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func2(void ***a1)
{
free(**a1);
free((*a1)[2]);
free(*a1);
*a1 = 0LL;
}

original_code:
void
delentry(KEntry **kentry)
{
    free((*kentry)->name);
    free((*kentry)->next);
    free(*kentry);
    *kentry = ((void *)0);
}

canonical_original_code:
void delentry(struct KEntry **kentry)
{
    free((*kentry)->name);
    free((*kentry)->next);
    free(*kentry);
    *kentry = ((void *)0);
}

variable_types: struct KEntry { char *name; enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *value; struct KEntry **next; } **


repsizeentry

decompiled_code:
size_t __fastcall repsizeentry(__int64 a1)
{
__int64 v1; // rbp

v1 = repsizekob(*(_QWORD *)(a1 + 8));
return v1 + strlen(*(const char **)a1) + 3;
}

canonical_decompiled_code:
size_t __fastcall func3(__int64 a1)
{
__int64 v1; // rbp

v1 = repsizekob(*(_QWORD *)(a1 + 8));
return v1 + strlen(*(const char **)a1) + 3;
}

original_code:
size_t
repsizeentry(KEntry *kentry)
{
    return repsizekob(kentry->value) + strlen(kentry->name) + 3;
}

canonical_original_code:
unsigned long repsizeentry(struct KEntry *kentry)
{
    return repsizekob(kentry->value) + strlen(kentry->name) + 3;
}

variable_types: struct KEntry { char *name; enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *value; struct KEntry **next; } *

return_type: unsigned long


repentry

decompiled_code:
__int64 __fastcall repentry(__int64 a1, _BYTE *a2)
{
*a2 = 36;
strcpy(a2 + 1, *(const char **)a1);
strcpy(&a2[strlen(*(const char **)a1) + 1], ": ");
return repkob(*(_QWORD *)(a1 + 8));
}

canonical_decompiled_code:
__int64 __fastcall func4(__int64 a1, _BYTE *a2)
{
*a2 = 36;
strcpy(a2 + 1, *(const char **)a1);
strcpy(&a2[strlen(*(const char **)a1) + 1], ": ");
return repkob(*(_QWORD *)(a1 + 8));
}

original_code:
void
repentry(KEntry *kentry, char *buffer)
{
    char *brep = buffer;
    *brep = '$';
    brep++;
    strcpy(brep, kentry->name);
    brep += strlen(kentry->name);
    strcpy(brep, ": ");
    brep += 2;
    repkob(kentry->value, brep);
}

canonical_original_code:
void repentry(struct KEntry *kentry, char *buffer)
{
    char *brep = buffer;
    *brep = '$';
    brep++;
    strcpy(brep, kentry->name);
    brep += strlen(kentry->name);
    strcpy(brep, ": ");
    brep += 2;
    repkob(kentry->value, brep);
}

variable_types:
buffer
char *

variable_types:
brep
char *

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


newnable

decompiled_code:
_QWORD *newnable()
{
unsigned int v0; // eax
_QWORD *v1; // rax
_QWORD *v2; // r12

v0 = time(0LL);
srand(v0);
v1 = malloc(0x10uLL);
*(_DWORD *)v1 = 0;
v2 = v1;
v1[1] = newentry(9, (const char *)&unk_81F, 0LL);
return v2;
}

canonical_decompiled_code:
_QWORD *func5()
{
unsigned int v0; // eax
_QWORD *v1; // rax
_QWORD *v2; // r12

v0 = time(0LL);
srand(v0);
v1 = malloc(0x10uLL);
*(_DWORD *)v1 = 0;
v2 = v1;
v1[1] = newentry(9, (const char *)&unk_81F, 0LL);
return v2;
}

original_code:
KNable *
newnable()
{
    KNable *knable;
    srand(time(((void *)0)));
    knable = (KNable *) malloc(sizeof(KNable));
    knable->level = 0;
    knable->header = newentry(10 - 1, "", ((void *)0));
    return knable;
}

canonical_original_code:
struct KNable *newnable()
{
    struct KNable *knable;
    srand(time(((void *)0)));
    knable = (struct KNable *) malloc(sizeof(KNable));
    knable->level = 0;
    knable->header = newentry(10 - 1, "", ((void *)0));
    return knable;
}

return_type: 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; } *


delnable

decompiled_code:
void __fastcall delnable(void **a1)
{
__int64 v1; // rbx
void **v2; // [rsp+8h] [rbp-20h] BYREF

v1 = *((_QWORD *)*a1 + 1);
v2 = (void **)v1;
do
{
v1 = **(_QWORD **)(v1 + 16);
delentry(&v2);
v2 = (void **)v1;
}
while ( v1 );
free(*a1);
*a1 = 0LL;
}

original_code:
void
delnable(KNable **knable)
{
    KEntry *a, *b;
    a = (*knable)->header;
    do {
        b = a->next[0];
        delentry(&a);
        a = b;
    } while (a != ((void *)0));
    free(*knable);
    *knable = ((void *)0);
}

canonical_original_code:
void delnable(struct KNable **knable)
{
    struct KEntry *a; struct KEntry *b;
    a = (*knable)->header;
    do {
        b = a->next[0];
        delentry(&a);
        a = b;
    } while (a != ((void *)0));
    free(*knable);
    *knable = ((void *)0);
}

variable_types: 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; } **


repsizenable

decompiled_code:
__int64 __fastcall repsizenable(__int64 a1)
{
__int64 v1; // rbx
int v2; // ebp
__int64 v3; // r12
__int64 result; // rax

v1 = **(_QWORD **)(*(_QWORD *)(a1 + 8) + 16LL);
if ( !v1 )
goto LABEL_6;
v2 = 0;
v3 = 0LL;
do
{
++v2;
v3 += repsizeentry(v1);
v1 = **(_QWORD **)(v1 + 16);
}
while ( v1 );
if ( v2 )
result = v3 + (unsigned int)(2 * v2);
else
LABEL_6:
result = 2LL;
return result;
}

canonical_decompiled_code:
__int64 __fastcall func7(__int64 a1)
{
__int64 v1; // rbx
int v2; // ebp
__int64 v3; // r12
__int64 result; // rax

v1 = **(_QWORD **)(*(_QWORD *)(a1 + 8) + 16LL);
if ( !v1 )
goto LABEL_6;
v2 = 0;
v3 = 0LL;
do
{
++v2;
v3 += func3(v1);
v1 = **(_QWORD **)(v1 + 16);
}
while ( v1 );
if ( v2 )
result = v3 + (unsigned int)(2 * v2);
else
LABEL_6:
result = 2LL;
return result;
}

original_code:
size_t
repsizenable(KNable *knable)
{
    KEntry *kentry;
    size_t size = 0;
    unsigned int len = 0;
    kentry = knable->header->next[0];
    while (kentry != ((void *)0)) {
        size += repsizeentry(kentry);
        len++;
        kentry = kentry->next[0];
    }
    if (len == 0)
        return 2;
    return size + len * 2;
}

canonical_original_code:
unsigned long repsizenable(struct KNable *knable)
{
    struct KEntry *kentry;
    unsigned long size = 0;
    unsigned int len = 0;
    kentry = knable->header->next[0];
    while (kentry != ((void *)0)) {
        size += repsizeentry(kentry);
        len++;
        kentry = kentry->next[0];
    }
    if (len == 0)
        return 2;
    return size + len * 2;
}

variable_types:
size
unsigned long

variable_types:
len
unsigned int


tget

original_code:
int
tget(KNable *knable, char *name, Kob **value)
{
    KEntry *kentry;
    int found, i;
    kentry = knable->header;
    for (i = knable->level; i >= 0; i--) {
        while (kentry->next[i] != ((void *)0)) {
            if (strcmp(kentry->next[i]->name, name) >= 0)
                break;
            kentry = kentry->next[i];
        }
    }
    kentry = kentry->next[0];
    found = (kentry != ((void *)0));
    if (found)
        found = (strcmp(kentry->name, name) == 0);
    if (found) {
        *value = kentry->value;
        return 1;
    }
    return 0;
}

canonical_original_code:
int tget(struct KNable *knable, char *name, enum Kob **value)
{
    struct KEntry *kentry;
    int found; int i;
    kentry = knable->header;
    for (i = knable->level; i >= 0; i--) {
        while (kentry->next[i] != ((void *)0)) {
            if (strcmp(kentry->next[i]->name, name) >= 0)
                break;
            kentry = kentry->next[i];
        }
    }
    kentry = kentry->next[0];
    found = (kentry != ((void *)0));
    if (found)
        found = (strcmp(kentry->name, name) == 0);
    if (found) {
        *value = kentry->value;
        return 1;
    }
    return 0;
}

variable_types:
name
char *

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

variable_types: found int

variable_types: i int


tremove

original_code:
int
tremove(KNable *knable, char *name)
{
    KEntry *kentry;
    KEntry *update[10];
    int found, i;
    kentry = knable->header;
    for (i = knable->level; i >= 0; i--) {
        while (kentry->next[i] != ((void *)0)) {
            if (strcmp(kentry->next[i]->name, name) >= 0)
                break;
            kentry = kentry->next[i];
        }
        update[i] = kentry;
    }
    kentry = kentry->next[0];
    found = (kentry != ((void *)0));
    if (found)
        found = (strcmp(kentry->name, name) == 0);
    if (found) {
        for (i = 0; i <= knable->level; i++) {
            if (update[i]->next[i] != kentry)
                break;
            update[i]->next[i] = kentry->next[i];
        }
        delentry(&kentry);
        while (knable->level > 0 &&
               knable->header->next[knable->level] == ((void *)0))
            knable->level--;
        return 1;
    }
    return 0;
}

canonical_original_code:
int tremove(struct KNable *knable, char *name)
{
    struct KEntry *kentry;
    struct KEntry *update[10];
    int found; int i;
    kentry = knable->header;
    for (i = knable->level; i >= 0; i--) {
        while (kentry->next[i] != ((void *)0)) {
            if (strcmp(kentry->next[i]->name, name) >= 0)
                break;
            kentry = kentry->next[i];
        }
        update[i] = kentry;
    }
    kentry = kentry->next[0];
    found = (kentry != ((void *)0));
    if (found)
        found = (strcmp(kentry->name, name) == 0);
    if (found) {
        for (i = 0; i <= knable->level; i++) {
            if (update[i]->next[i] != kentry)
                break;
            update[i]->next[i] = kentry->next[i];
        }
        delentry(&kentry);
        while (knable->level > 0 &&
               knable->header->next[knable->level] == ((void *)0))
            knable->level--;
        return 1;
    }
    return 0;
}

variable_types: struct KEntry { char *name; enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *value; struct KEntry **next; } *[10]


newstack

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

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

original_code:
KStack *
newstack()
{
    return ((void *)0);
}

canonical_original_code:
struct KStack *newstack()
{
    return ((void *)0);
}

return_type: struct KStack { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *kob; struct KStack *next; } *


repsizestack

decompiled_code:
__int64 __fastcall repsizestack(_QWORD *a1)
{
__int64 i; // r12
__int64 v2; // rax
_QWORD *v3; // rbx
__int64 v4; // rax

i = 1LL;
if ( a1 )
{
v2 = repsizekob(*a1);
v3 = (_QWORD *)a1[1];
for ( i = v2; v3; i += v4 + 1 )
{
v4 = repsizekob(*v3);
v3 = (_QWORD *)v3[1];
}
}
return i;
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1)
{
__int64 i; // r12
__int64 v2; // rax
_QWORD *v3; // rbx
__int64 v4; // rax

i = 1LL;
if ( a1 )
{
v2 = repsizekob(*a1);
v3 = (_QWORD *)a1[1];
for ( i = v2; v3; i += v4 + 1 )
{
v4 = repsizekob(*v3);
v3 = (_QWORD *)v3[1];
}
}
return i;
}

original_code:
size_t
repsizestack(KStack *kstack)
{
    size_t size;
    if (kstack == ((void *)0))
        return 1;
    size = repsizekob(kstack->kob);
    kstack = kstack->next;
    while (kstack != ((void *)0)) {
        size += 1 + repsizekob(kstack->kob);
        kstack = kstack->next;
    }
    return size;
}

canonical_original_code:
unsigned long repsizestack(struct KStack *kstack)
{
    unsigned long size;
    if (kstack == ((void *)0))
        return 1;
    size = repsizekob(kstack->kob);
    kstack = kstack->next;
    while (kstack != ((void *)0)) {
        size += 1 + repsizekob(kstack->kob);
        kstack = kstack->next;
    }
    return size;
}

variable_types: struct KStack { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *kob; struct KStack *next; } *


slength

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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 8);
return result;
}

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

for ( result = 0LL; a1; result = (unsigned int)(result + 1) )
a1 = *(_QWORD *)(a1 + 8);
return result;
}

original_code:
unsigned int
slength(KStack *kstack)
{
    unsigned int length = 0;
    while (kstack != ((void *)0)) {
        length++;
        kstack = kstack->next;
    }
    return length;
}

canonical_original_code:
unsigned int slength(struct KStack *kstack)
{
    unsigned int length = 0;
    while (kstack != ((void *)0)) {
        length++;
        kstack = kstack->next;
    }
    return length;
}

variable_types:
length
unsigned int

return_type: unsigned int


spop

original_code:
Kob *
spop(KStack **kstack)
{
    KStack *poped;
    Kob* kob;
    poped = *kstack;
    *kstack = poped->next;
    kob = poped->kob;
    free(poped);
    return kob;
}

canonical_original_code:
enum Kob *spop(struct KStack **kstack)
{
    struct KStack *poped;
    enum Kob *kob;
    poped = *kstack;
    *kstack = poped->next;
    kob = poped->kob;
    free(poped);
    return kob;
}

variable_types: struct KStack { enum Kob { EMPTY=0, T_NUMBER=1, T_BEAT=2, T_BLIST=3, T_NAME=4 } *kob; struct KStack *next; } **


newblist

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

result = malloc(0x18uLL);
*result = 3LL;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

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

result = malloc(0x18uLL);
*result = 3LL;
result[1] = 0LL;
result[2] = 0LL;
return result;
}

original_code:
KBlist *
newblist()
{
    KBlist *kblist;
    kblist = (KBlist *) malloc(sizeof(KBlist));
    kblist->type = T_BLIST;
    kblist->length = 0U;
    kblist->first = kblist->last = ((void *)0);
    return kblist;
}

canonical_original_code:
struct KBlist *newblist()
{
    struct KBlist *kblist;
    kblist = (struct KBlist *) malloc(sizeof(KBlist));
    kblist->type = T_BLIST;
    kblist->length = 0U;
    kblist->first = kblist->last = ((void *)0);
    return kblist;
}

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; } *

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


newname

decompiled_code:
char *__fastcall newname(char *src)
{
char *v1; // rax
char *v2; // r12

v1 = (char *)malloc(0x24uLL);
*(_DWORD *)v1 = 4;
v2 = v1;
strncpy(v1 + 4, src, 0x20uLL);
return v2;
}

canonical_decompiled_code:
char *__fastcall func1(char *src)
{
char *v1; // rax
char *v2; // r12

v1 = (char *)malloc(0x24uLL);
*(_DWORD *)v1 = 4;
v2 = v1;
strncpy(v1 + 4, src, 0x20uLL);
return v2;
}

original_code:
KName *
newname(char *name)
{
    KName *kname;
    kname = (KName *) malloc(sizeof(KName));
    kname->type = T_NAME;
    strncpy(kname->name, name, 32);
    return kname;
}

canonical_original_code:
struct KName *newname(char *name)
{
    struct KName *kname;
    kname = (struct KName *) malloc(sizeof(KName));
    kname->type = T_NAME;
    strncpy(kname->name, name, 32);
    return kname;
}

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]; }


delnumber

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

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

original_code:
void
delnumber(KNumber **knumber)
{
    free(*knumber);
    *knumber = ((void *)0);
}

canonical_original_code:
void delnumber(struct KNumber **knumber)
{
    free(*knumber);
    *knumber = ((void *)0);
}

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

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


delbeat

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

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

original_code:
void
delbeat(KBeat **kbeat)
{
    free(*kbeat);
    *kbeat = ((void *)0);
}

canonical_original_code:
void delbeat(struct KBeat **kbeat)
{
    free(*kbeat);
    *kbeat = ((void *)0);
}

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

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


delbnode

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

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

original_code:
void
delbnode(KBnode **kbnode)
{
    free(*kbnode);
    *kbnode = ((void *)0);
}

canonical_original_code:
void delbnode(struct KBnode **kbnode)
{
    free(*kbnode);
    *kbnode = ((void *)0);
}

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


delblist

original_code:
void
delblist(KBlist **kblist)
{
    KBnode *second;
    while ((*kblist)->length > 1U) {
        second = (*kblist)->first->next;
        delbnode(&(*kblist)->first);
        (*kblist)->first = second;
        (*kblist)->length--;
    }
    delbnode(&(*kblist)->first);
    free(*kblist);
    *kblist = ((void *)0);
}

canonical_original_code:
void delblist(struct KBlist **kblist)
{
    struct KBnode *second;
    while ((*kblist)->length > 1U) {
        second = (*kblist)->first->next;
        delbnode(&(*kblist)->first);
        (*kblist)->first = second;
        (*kblist)->length--;
    }
    delbnode(&(*kblist)->first);
    free(*kblist);
    *kblist = ((void *)0);
}

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; } **


delname

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

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

original_code:
void
delname(KName **kname)
{
    free(*kname);
    *kname = ((void *)0);
}

canonical_original_code:
void delname(struct KName **kname)
{
    free(*kname);
    *kname = ((void *)0);
}

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


delkob

decompiled_code:
void __fastcall delkob(void **a1)
{
unsigned int v1; // eax

v1 = *(_DWORD *)*a1;
if ( v1 == 3 )
{
delblist(a1);
}
else if ( v1 > 3 )
{
if ( v1 == 4 )
delname(a1);
}
else if ( v1 == 1 )
{
delnumber(a1);
}
else if ( v1 == 2 )
{
delbeat(a1);
}
}

canonical_decompiled_code:
void __fastcall func7(void **a1)
{
unsigned int v1; // eax

v1 = *(_DWORD *)*a1;
if ( v1 == 3 )
{
func5(a1);
}
else if ( v1 > 3 )
{
if ( v1 == 4 )
func6(a1);
}
else if ( v1 == 1 )
{
func2(a1);
}
else if ( v1 == 2 )
{
func3(a1);
}
}

original_code:
void
delkob(Kob **kob)
{
    switch(**kob) {
        case EMPTY:
            return;
        case T_NUMBER:
            delnumber((KNumber **) kob);
            break;
        case T_BEAT:
            delbeat((KBeat **) kob);
            break;
        case T_BLIST:
            delblist((KBlist **) kob);
            break;
        case T_NAME:
            delname((KName **) kob);
            break;
    }
}

canonical_original_code:
void delkob(enum Kob **kob)
{
    switch(**kob) {
        case EMPTY:
            return;
        case T_NUMBER:
            delnumber((struct KNumber **) kob);
            break;
        case T_BEAT:
            delbeat((struct KBeat **) kob);
            break;
        case T_BLIST:
            delblist((struct KBlist **) kob);
            break;
        case T_NAME:
            delname((struct KName **) kob);
            break;
    }
}

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


newbuffer

decompiled_code:
_QWORD *newbuffer()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = malloc(0x10uLL);
*v0 = 1LL;
v1 = v0;
v0[1] = malloc(1uLL);
return v1;
}

canonical_decompiled_code:
_QWORD *func8()
{
_QWORD *v0; // rax
_QWORD *v1; // r12

v0 = malloc(0x10uLL);
*v0 = 1LL;
v1 = v0;
v0[1] = malloc(1uLL);
return v1;
}

original_code:
KBuffer *
newbuffer()
{
    KBuffer *kbuffer;
    kbuffer = (KBuffer *) malloc(sizeof(KBuffer));
    kbuffer->size = 1;
    kbuffer->buffer = (char *) malloc(sizeof(char));
    return kbuffer;
}

canonical_original_code:
struct KBuffer *newbuffer()
{
    struct KBuffer *kbuffer;
    kbuffer = (struct KBuffer *) malloc(sizeof(KBuffer));
    kbuffer->size = 1;
    kbuffer->buffer = (char *) malloc(sizeof(char));
    return kbuffer;
}

variable_types: struct KBuffer { unsigned long size; char *buffer; } *


setupbuffer

decompiled_code:
size_t __fastcall setupbuffer(__int64 a1, size_t a2)
{
size_t v2; // rax
size_t v3; // r12

v2 = *(_QWORD *)a1;
if ( a2 >= *(_QWORD *)a1 )
{
do
v2 *= 2LL;
while ( v2 <= a2 );
*(_QWORD *)a1 = v2;
}
free(*(void **)(a1 + 8));
v3 = *(_QWORD *)a1;
*(_QWORD *)(a1 + 8) = malloc(*(_QWORD *)a1);
return v3;
}

canonical_decompiled_code:
size_t __fastcall func9(__int64 a1, size_t a2)
{
size_t v2; // rax
size_t v3; // r12

v2 = *(_QWORD *)a1;
if ( a2 >= *(_QWORD *)a1 )
{
do
v2 *= 2LL;
while ( v2 <= a2 );
*(_QWORD *)a1 = v2;
}
free(*(void **)(a1 + 8));
v3 = *(_QWORD *)a1;
*(_QWORD *)(a1 + 8) = malloc(*(_QWORD *)a1);
return v3;
}

original_code:
size_t
setupbuffer(KBuffer *kbuffer, size_t size)
{
    while (size >= kbuffer->size)
        kbuffer->size *= 2;
    free(kbuffer->buffer);
    kbuffer->buffer = (char *) malloc(sizeof(char) * kbuffer->size);
    return kbuffer->size;
}

canonical_original_code:
unsigned long setupbuffer(struct KBuffer *kbuffer, unsigned long size)
{
    while (size >= kbuffer->size)
        kbuffer->size *= 2;
    free(kbuffer->buffer);
    kbuffer->buffer = (char *) malloc(sizeof(char) * kbuffer->size);
    return kbuffer->size;
}

variable_types:
size
unsigned long

user_defined_types: struct KBuffer { unsigned long size; char *buffer; }


delbuffer

decompiled_code:
void __fastcall delbuffer(void **a1)
{
free(*((void **)*a1 + 1));
free(*a1);
*a1 = 0LL;
}

canonical_decompiled_code:
void __fastcall func10(void **a1)
{
free(*((void **)*a1 + 1));
free(*a1);
*a1 = 0LL;
}

original_code:
void
delbuffer(KBuffer **kbuffer)
{
    free((*kbuffer)->buffer);
    free(*kbuffer);
    *kbuffer = ((void *)0);
}

canonical_original_code:
void delbuffer(struct KBuffer **kbuffer)
{
    free((*kbuffer)->buffer);
    free(*kbuffer);
    *kbuffer = ((void *)0);
}

variable_types: struct KBuffer { unsigned long size; char *buffer; } **


repsizenumber

original_code:
size_t
repsizenumber(KNumber *knumber)
{
    return (size_t) log10((double) knumber->value) + 1;
}

canonical_original_code:
unsigned long repsizenumber(struct KNumber *knumber)
{
    return (unsigned long) log10((double) knumber->value) + 1;
}

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


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

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;
}


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;
}


repsizekob

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

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

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

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

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 } *


repnumber

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

v3 = *(_DWORD *)(a1 + 4);
if ( v3 )
{
v4 = log10((double)v3);
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
{
result = 48;
*(_WORD *)a2 = 48;
}
return result;
}

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

v3 = *(_DWORD *)(a1 + 4);
if ( v3 )
{
v4 = log10((double)v3);
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
{
result = 48;
*(_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:
buffer
char *

variable_types:
length
unsigned long


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);
}


repkob

decompiled_code:
unsigned int __fastcall repkob(__int64 a1, _WORD *a2)
{
unsigned int result; // eax

result = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 3 )
return repblist(a1, (__int64)a2);
if ( result > 3 )
{
if ( result == 4 )
result = (unsigned int)repname(a1, a2);
}
else if ( result == 1 )
{
result = repnumber(a1, (char *)a2);
}
else if ( result == 2 )
{
result = repbeat(a1, a2);
}
return result;
}

canonical_decompiled_code:
unsigned int __fastcall func20(__int64 a1, _WORD *a2)
{
unsigned int result; // eax

result = *(_DWORD *)a1;
if ( *(_DWORD *)a1 == 3 )
return func18(a1, (__int64)a2);
if ( result > 3 )
{
if ( result == 4 )
result = (unsigned int)func19(a1, a2);
}
else if ( result == 1 )
{
result = func16(a1, (char *)a2);
}
else if ( result == 2 )
{
result = func17(a1, a2);
}
return result;
}

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


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;
}

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; } *


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; // er8
__int64 result; // rax
__int64 v6; // r12
_DWORD *v7; // rax
bool v8; // zf
__int64 v9[4]; // [rsp+8h] [rbp-20h] BYREF

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

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

v4 = slength(*a1);
result = 2LL;
if ( v4 >= a2 )
{
v6 = (int)(a2 - 1);
if ( (int)(a2 - 1) >= 0 )
{
while ( 1 )
{
while ( 1 )
{
v7 = (_DWORD *)spop(a1);
v8 = *v7 == 4;
v9[0] = (__int64)v7;
if ( v8 )
break;
*(_QWORD *)(a3 + 8 * v6--) = v7;
if ( (int)v6 < 0 )
goto LABEL_8;
}
if ( (unsigned int)tget(a1[1], v7 + 1, v9) != 1 )
break;
*(_QWORD *)(a3 + 8 * v6--) = cpykob(v9[0]);
if ( (int)v6 < 0 )
goto LABEL_8;
}
result = 3LL;
}
else
{
LABEL_8:
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 }


kinvert

decompiled_code:
__int64 __fastcall kinvert(_QWORD *a1)
{
unsigned int v1; // er12
__int64 i; // rax
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = kgetargs(a1, 1u, (__int64)v4);
if ( v1 )
return v1;
if ( *(_DWORD *)v4[0] == 3 )
{
for ( i = *(_QWORD *)(v4[0] + 8); i; i = *(_QWORD *)(i + 8) )
*(_DWORD *)i = *(_DWORD *)i == 0;
spush(a1);
return v1;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func1(_QWORD *a1)
{
unsigned int v1; // er12
__int64 i; // rax
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = func0(a1, 1u, (__int64)v4);
if ( v1 )
return v1;
if ( *(_DWORD *)v4[0] == 3 )
{
for ( i = *(_QWORD *)(v4[0] + 8); i; i = *(_QWORD *)(i + 8) )
*(_DWORD *)i = *(_DWORD *)i == 0;
spush(a1);
return v1;
}
return 1LL;
}

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

decompiled_code:
__int64 __fastcall kclear(_QWORD *a1)
{
unsigned int v1; // er12
__int64 i; // rax
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = kgetargs(a1, 1u, (__int64)v4);
if ( v1 )
return v1;
if ( *(_DWORD *)v4[0] == 3 )
{
for ( i = *(_QWORD *)(v4[0] + 8); i; i = *(_QWORD *)(i + 8) )
*(_DWORD *)i = 0;
spush(a1);
return v1;
}
return 1LL;
}

canonical_decompiled_code:
__int64 __fastcall func2(_QWORD *a1)
{
unsigned int v1; // er12
__int64 i; // rax
__int64 v4[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = func0(a1, 1u, (__int64)v4);
if ( v1 )
return v1;
if ( *(_DWORD *)v4[0] == 3 )
{
for ( i = *(_QWORD *)(v4[0] + 8); i; i = *(_QWORD *)(i + 8) )
*(_DWORD *)i = 0;
spush(a1);
return v1;
}
return 1LL;
}

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; // er12
__int64 v3; // r13
unsigned int v4; // eax
_DWORD *v5; // [rsp+0h] [rbp-28h] BYREF
__int64 v6[4]; // [rsp+8h] [rbp-20h] BYREF

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

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

v1 = func0(a1, 2u, (__int64)&v5);
if ( v1 )
return v1;
if ( *v5 != 3 || *(_DWORD *)v6[0] != 1 )
return 1;
v3 = cpyblist();
if ( *(_DWORD *)(v6[0] + 4) > 1u )
{
do
{
blist_extend(v3, v5);
v4 = *(_DWORD *)(v6[0] + 4) - 1;
*(_DWORD *)(v6[0] + 4) = v4;
}
while ( v4 > 1 );
}
spush(a1);
delblist(&v5);
delnumber(v6, v3);
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;
}


kpattern

decompiled_code:
__int64 __fastcall kpattern(_QWORD *a1)
{
unsigned int v2; // er12
__int64 v4; // rdi
__int64 v5; // rbx
__int64 v6; // r13
__int64 i; // rbx
__int64 v8; // [rsp+8h] [rbp-40h] BYREF
__int64 v9; // [rsp+10h] [rbp-38h] BYREF
__int64 v10[6]; // [rsp+18h] [rbp-30h] BYREF

v2 = kgetargs(a1, 2u, (__int64)&v9);
if ( v2 )
return v2;
if ( *(_DWORD *)v9 != 3 || *(_DWORD *)v10[0] != 3 )
return 1;
v8 = ((__int64 (*)(void))newblist)();
v4 = v8;
v5 = *(_QWORD *)(v9 + 8);
if ( v5 )
{
while ( 1 )
{
blist_insert(v4, 0LL, 0LL);
v5 = *(_QWORD *)(v5 + 8);
if ( !v5 )
break;
v4 = v8;
}
}
v6 = newblist(v4);
for ( i = *(_QWORD *)(v10[0] + 8); i; i = *(_QWORD *)(i + 8) )
{
if ( *(_DWORD *)i )
blist_extend(v6, v9);
else
blist_extend(v6, v8);
}
spush(a1);
delblist(&v8);
delblist(&v9);
delblist(v10);
return v2;
}

canonical_decompiled_code:
__int64 __fastcall func6(_QWORD *a1)
{
unsigned int v2; // er12
__int64 v4; // rdi
__int64 v5; // rbx
__int64 v6; // r13
__int64 i; // rbx
__int64 v8; // [rsp+8h] [rbp-40h] BYREF
__int64 v9; // [rsp+10h] [rbp-38h] BYREF
__int64 v10[6]; // [rsp+18h] [rbp-30h] BYREF

v2 = func0(a1, 2u, (__int64)&v9);
if ( v2 )
return v2;
if ( *(_DWORD *)v9 != 3 || *(_DWORD *)v10[0] != 3 )
return 1;
v8 = ((__int64 (*)(void))newblist)();
v4 = v8;
v5 = *(_QWORD *)(v9 + 8);
if ( v5 )
{
while ( 1 )
{
blist_insert(v4, 0LL, 0LL);
v5 = *(_QWORD *)(v5 + 8);
if ( !v5 )
break;
v4 = v8;
}
}
v6 = newblist(v4);
for ( i = *(_QWORD *)(v10[0] + 8); i; i = *(_QWORD *)(i + 8) )
{
if ( *(_DWORD *)i )
blist_extend(v6, v9);
else
blist_extend(v6, v8);
}
spush(a1);
delblist(&v8);
delblist(&v9);
delblist(v10);
return v2;
}

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; // er12
_DWORD *v2; // rbp
unsigned int v4; // eax
_DWORD *v6; // [rsp+0h] [rbp-28h] BYREF
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

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

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

v1 = func0(a1, 2u, (__int64)&v6);
if ( v1 )
return v1;
v2 = v6;
if ( *v6 != 3 || *(_DWORD *)v7[0] != 1 )
return 1;
if ( *(_DWORD *)(v7[0] + 4) )
{
do
{
v4 = blist_remove(v2, 0LL);
blist_insert(v2, (unsigned int)v2[1], v4);
}
while ( (*(_DWORD *)(v7[0] + 4))-- != 1 );
v2 = v6;
}
spush(a1);
delnumber(v7, v2);
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; // er12
_DWORD *v2; // r13
unsigned int v4; // eax
_DWORD *v6; // [rsp+0h] [rbp-28h] BYREF
__int64 v7[4]; // [rsp+8h] [rbp-20h] BYREF

v1 = kgetargs(a1, 2u, (__int64)&v6);
if ( v1 )
return v1;
v2 = v6;
if ( *v6 != 3 || *(_DWORD *)v7[0] != 1 )
return 1;
if ( *(_DWORD *)(v7[0] + 4) )
{
do
{
v4 = blist_remove(v2, 0xFFFFFFFFLL);
blist_insert(v2, 0LL, v4);
}
while ( (*(_DWORD *)(v7[0] + 4))-- != 1 );
v2 = v6;
}
spush(a1);
delnumber(v7, v2);
return 0LL;
}

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

v1 = func0(a1, 2u, (__int64)&v6);
if ( v1 )
return v1;
v2 = v6;
if ( *v6 != 3 || *(_DWORD *)v7[0] != 1 )
return 1;
if ( *(_DWORD *)(v7[0] + 4) )
{
do
{
v4 = blist_remove(v2, 0xFFFFFFFFLL);
blist_insert(v2, 0LL, v4);
}
while ( (*(_DWORD *)(v7[0] + 4))-- != 1 );
v2 = v6;
}
spush(a1);
delnumber(v7, v2);
return 0LL;
}

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; // er12
_DWORD *v2; // r13
_DWORD *v4; // rax
_DWORD *v6; // [rsp+0h] [rbp-38h] BYREF
_DWORD *v7; // [rsp+8h] [rbp-30h] BYREF
__int64 v8[5]; // [rsp+10h] [rbp-28h] BYREF

v1 = kgetargs(a1, 3u, (__int64)&v6);
if ( !v1 )
{
v2 = v6;
if ( *v6 == 3 && *v7 == 1 && (v4 = (_DWORD *)v8[0], *(_DWORD *)v8[0] == 2) )
{
if ( v7[1] )
{
while ( 1 )
{
blist_insert(v2, (unsigned int)v2[1], (unsigned int)v4[1]);
if ( v7[1]-- == 1 )
break;
v4 = (_DWORD *)v8[0];
}
v2 = v6;
}
spush(a1);
delnumber(&v7, v2);
delbeat(v8);
}
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; // er12
_DWORD *v2; // r13
_DWORD *v4; // rax
_DWORD *v6; // [rsp+0h] [rbp-38h] BYREF
_DWORD *v7; // [rsp+8h] [rbp-30h] BYREF
__int64 v8[5]; // [rsp+10h] [rbp-28h] BYREF

v1 = kgetargs(a1, 3u, (__int64)&v6);
if ( !v1 )
{
v2 = v6;
if ( *v6 == 3 && *v7 == 1 && (v4 = (_DWORD *)v8[0], *(_DWORD *)v8[0] == 2) )
{
if ( v7[1] )
{
while ( 1 )
{
blist_insert(v2, 0LL, (unsigned int)v4[1]);
if ( v7[1]-- == 1 )
break;
v4 = (_DWORD *)v8[0];
}
v2 = v6;
}
spush(a1);
delnumber(&v7, v2);
delbeat(v8);
}
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)
{
_DWORD *v1; // rax
_DWORD *v2; // rsi
bool v3; // zf
__int64 result; // rax
int v5; // er8
_DWORD *v6; // [rsp+0h] [rbp-18h] BYREF
_DWORD *v7; // [rsp+8h] [rbp-10h] BYREF

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

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

if ( (unsigned int)slength(*a1) <= 1 )
return 2LL;
v1 = *(_DWORD **)*a1;
v2 = **(_DWORD ***)(*a1 + 8LL);
v3 = *v1 == 4;
v7 = v1;
v6 = v2;
if ( v3 )
{
v5 = tget(a1[1], v1 + 1, &v7);
result = 3LL;
if ( v5 != 1 )
return result;
v2 = v6;
v7 = (_DWORD *)cpykob(v7);
}
result = 1LL;
if ( *v2 == 4 )
{
tset(a1[1], v2 + 1, v7);
*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; // er12
__int64 v3; // rsi
_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 && *(_DWORD *)v5 == 1 && *(_DWORD *)v6 == 1 && *(_DWORD *)v7[0] == 1 )
{
v3 = trackfromblist(
v4,
(unsigned int)*(char *)(v5 + 4),
(unsigned int)*(char *)(v6 + 4),
*(unsigned int *)(v7[0] + 4));
a1[2] = trackmix(a1[2], v3);
delblist(&v4);
delnumber(&v5, v3);
delnumber(&v6, v3);
delnumber(v7, v3);
}
else
{
v1 = 1;
}
}
return v1;
}

canonical_decompiled_code:
__int64 __fastcall func13(_QWORD *a1)
{
unsigned int v1; // er12
__int64 v3; // rsi
_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 && *(_DWORD *)v5 == 1 && *(_DWORD *)v6 == 1 && *(_DWORD *)v7[0] == 1 )
{
v3 = trackfromblist(
v4,
(unsigned int)*(char *)(v5 + 4),
(unsigned int)*(char *)(v6 + 4),
*(unsigned int *)(v7[0] + 4));
a1[2] = trackmix(a1[2], v3);
delblist(&v4);
delnumber(&v5, v3);
delnumber(&v6, v3);
delnumber(v7, v3);
}
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; // r12
char v2; // al
char *v3; // rbx

v1 = newblist();
v2 = *(_BYTE *)(a1 + 1);
if ( v2 != 93 )
{
v3 = (char *)(a1 + 1);
do
{
while ( v2 == 43 )
{
++v3;
blist_insert(v1, *(unsigned int *)(v1 + 4), 1LL);
v2 = *v3;
if ( *v3 == 93 )
return v1;
}
if ( v2 == 45 )
blist_insert(v1, *(unsigned int *)(v1 + 4), 0LL);
v2 = *++v3;
}
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(char *a1)
{
__int64 v1; // rbx
char *v2; // rbp
const unsigned __int16 *v3; // rax

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

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

v1 = *a1;
if ( !(_BYTE)v1 )
return 1LL;
v2 = a1;
v3 = *_ctype_b_loc();
while ( (v3[v1] & 0x800) != 0 )
{
v1 = *++v2;
if ( !(_BYTE)v1 )
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(unsigned __int8 *a1)
{
int v1; // eax
int v3; // eax

v1 = *a1;
if ( v1 == 43 && !a1[1] )
return 1LL;
v3 = v1 - 45;
if ( !v3 )
v3 = a1[1];
return v3 == 0;
}

canonical_decompiled_code:
_BOOL8 __fastcall func5(unsigned __int8 *a1)
{
int v1; // eax
int v3; // eax

v1 = *a1;
if ( v1 == 43 && !a1[1] )
return 1LL;
v3 = v1 - 45;
if ( !v3 )
v3 = a1[1];
return v3 == 0;
}

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


kisblist

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

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

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

if ( *a1 == 91 )
result = a1[strlen(a1) - 1] == 93;
else
result = 0LL;
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)
{
if ( (unsigned int)kisnumber(a1) )
return kparsenumber(a1);
if ( kisbeat((unsigned __int8 *)a1) )
return kparsebeat(a1);
if ( kisblist(a1) )
return kparseblist((__int64)a1);
if ( kisname(a1) )
return kparsename((__int64)a1);
return 0LL;
}

canonical_decompiled_code:
__int64 __fastcall func8(char *a1)
{
if ( (unsigned int)func4(a1) )
return func0(a1);
if ( func5((unsigned __int8 *)a1) )
return func1(a1);
if ( func6(a1) )
return func2((__int64)a1);
if ( func7(a1) )
return func3((__int64)a1);
return 0LL;
}

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; // r12
__int64 v1; // rax
_QWORD *result; // rax

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

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

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

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

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; }


main

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

buildDictionary(argc, argv, envp);
initCopipeStatus(v3);
while ( 1 )
{
printf("%s", (&Surface)[v3[3]]);
nextCopipeStatus(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(argc, argv, envp);
func11(v3);
while ( 1 )
{
printf("%s", (&Surface)[v3[3]]);
func12(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; }