// File: Mespyr[P]bop-lisp/src/parser.cpp
// Function: tokenize(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
TokenList tokenize(std::string code) 
{
    TokenList stream;
    std::string word;
    bool string_has_started = false;
    bool in_comment = false;

    unsigned int line = 1;

    for (int i = 0; i < code.length(); i++)
    {
        char buf = code.at(i);
        if (buf == '\n') 
        {
            line++;
        }
        if (buf == ';' and !string_has_started) 
        {
            in_comment = !in_comment;
        } 
        else if(in_comment);

        else if (buf == '\'') 
        {
            word.push_back(buf);
            if(!string_has_started) 
            {
                string_has_started = true;
            } 
            else 
            {
                Token tok{line, word};
                stream.token_stream.push_back(tok);
                string_has_started = false;
                word = "";
            }
        } 
        else if (string_has_started) 
        {
            word.push_back(buf);
        }
        else if (isspace(buf)) 
        {
            if (word != "") 
            {
                Token tok{line, word};
                stream.token_stream.push_back(tok);
            }
            word = "";
        } 
        else if (buf == '(') 
        {
            if (word != "") 
            {
                Token tok{line, word};
                stream.token_stream.push_back(tok);
            }
            Token tok{line, "("};
            stream.token_stream.push_back(tok);
            word = "";
        }
        else if (buf == ')') 
        {
            if (word != "") 
            {
                Token tok{line, word};
                stream.token_stream.push_back(tok);
            }
            Token tok{line, ")"};
            stream.token_stream.push_back(tok);
            word = "";
        }
        else 
        {
            word.push_back(buf);
        }
    }

    return stream;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rsi, -0x170(%rbp)
movq %rdi, -0x168(%rbp)
movq %rdi, %rax
movq %rax, -0x160(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x11(%rbp)
callq 0x19f90
leaq -0x38(%rbp), %rdi
callq 0x3450
movb $0x0, -0x39(%rbp)
movb $0x0, -0x3a(%rbp)
movl $0x1, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x170(%rbp), %rdi
movslq -0x44(%rbp), %rax
movq %rax, -0x178(%rbp)
callq 0x3480
movq %rax, %rcx
movq -0x178(%rbp), %rax
cmpq %rcx, %rax
jae 0x19145
movq -0x170(%rbp), %rdi
movslq -0x44(%rbp), %rsi
callq 0x3550
movq %rax, -0x180(%rbp)
jmp 0x18cd6
movq -0x180(%rbp), %rax
movb (%rax), %al
movb %al, -0x45(%rbp)
movsbl -0x45(%rbp), %eax
cmpl $0xa, %eax
jne 0x18d07
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x18d07
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x1915a
movsbl -0x45(%rbp), %eax
cmpl $0x3b, %eax
jne 0x18d25
testb $0x1, -0x39(%rbp)
jne 0x18d25
movb -0x3a(%rbp), %al
xorb $-0x1, %al
andb $0x1, %al
movb %al, -0x3a(%rbp)
jmp 0x19135
testb $0x1, -0x3a(%rbp)
je 0x18d30
jmp 0x19133
movsbl -0x45(%rbp), %eax
cmpl $0x27, %eax
jne 0x18dbf
movsbl -0x45(%rbp), %esi
leaq -0x38(%rbp), %rdi
callq 0x3290
jmp 0x18d4c
testb $0x1, -0x39(%rbp)
jne 0x18d58
movb $0x1, -0x39(%rbp)
jmp 0x18dba
movl -0x40(%rbp), %eax
movl %eax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3180
jmp 0x18d6d
movq -0x168(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x19fc0
jmp 0x18d7f
movb $0x0, -0x39(%rbp)
leaq 0x32f8(%rip), %rsi      # 0x1c082
leaq -0x38(%rbp), %rdi
callq 0x3440
jmp 0x18d95
leaq -0x80(%rbp), %rdi
callq 0x15570
jmp 0x18dba
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x15570
jmp 0x1915a
jmp 0x19131
testb $0x1, -0x39(%rbp)
je 0x18dd9
movsbl -0x45(%rbp), %esi
leaq -0x38(%rbp), %rdi
callq 0x3290
jmp 0x18dd4
jmp 0x1912f
movsbl -0x45(%rbp), %edi
callq 0x3080
cmpl $0x0, %eax
je 0x18e81
leaq 0x3290(%rip), %rsi      # 0x1c082
leaq -0x38(%rbp), %rdi
callq 0x14840
movb %al, -0x181(%rbp)
jmp 0x18e03
movb -0x181(%rbp), %al
testb $0x1, %al
jne 0x18e0f
jmp 0x18e6a
movl -0x40(%rbp), %eax
movl %eax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3180
jmp 0x18e2a
movq -0x168(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x19fc0
jmp 0x18e3f
leaq -0xa8(%rbp), %rdi
callq 0x15570
jmp 0x18e6a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x15570
jmp 0x1915a
leaq 0x3211(%rip), %rsi      # 0x1c082
leaq -0x38(%rbp), %rdi
callq 0x3440
jmp 0x18e7c
jmp 0x1912d
movsbl -0x45(%rbp), %eax
cmpl $0x28, %eax
jne 0x18fd1
leaq 0x31ed(%rip), %rsi      # 0x1c082
leaq -0x38(%rbp), %rdi
callq 0x14840
movb %al, -0x182(%rbp)
jmp 0x18ea6
movb -0x182(%rbp), %al
testb $0x1, %al
jne 0x18eb2
jmp 0x18f0d
movl -0x40(%rbp), %eax
movl %eax, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3180
jmp 0x18ecd
movq -0x168(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x19fc0
jmp 0x18ee2
leaq -0xd0(%rbp), %rdi
callq 0x15570
jmp 0x18f0d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x15570
jmp 0x1915a
movl -0x40(%rbp), %eax
movl %eax, -0xf8(%rbp)
leaq -0xf0(%rbp), %rax
movq %rax, -0x198(%rbp)
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x190(%rbp)
callq 0x3520
movq -0x198(%rbp), %rdi
movq -0x190(%rbp), %rdx
leaq 0x3f15(%rip), %rsi      # 0x1ce61
callq 0x3df0
jmp 0x18f53
leaq -0xf9(%rbp), %rdi
callq 0x3370
movq -0x168(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x19fc0
jmp 0x18f74
leaq 0x3107(%rip), %rsi      # 0x1c082
leaq -0x38(%rbp), %rdi
callq 0x3440
jmp 0x18f86
leaq -0xf8(%rbp), %rdi
callq 0x15570
jmp 0x1912b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xf9(%rbp), %rdi
callq 0x3370
jmp 0x1915a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x15570
jmp 0x1915a
movsbl -0x45(%rbp), %eax
cmpl $0x29, %eax
jne 0x19118
leaq 0x309d(%rip), %rsi      # 0x1c082
leaq -0x38(%rbp), %rdi
callq 0x14840
movb %al, -0x199(%rbp)
jmp 0x18ff6
movb -0x199(%rbp), %al
testb $0x1, %al
jne 0x19002
jmp 0x1905d
movl -0x40(%rbp), %eax
movl %eax, -0x128(%rbp)
leaq -0x120(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3180
jmp 0x1901d
movq -0x168(%rbp), %rdi
leaq -0x128(%rbp), %rsi
callq 0x19fc0
jmp 0x19032
leaq -0x128(%rbp), %rdi
callq 0x15570
jmp 0x1905d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x15570
jmp 0x1915a
movl -0x40(%rbp), %eax
movl %eax, -0x150(%rbp)
leaq -0x148(%rbp), %rax
movq %rax, -0x1b0(%rbp)
leaq -0x151(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x3520
movq -0x1b0(%rbp), %rdi
movq -0x1a8(%rbp), %rdx
leaq 0x3c9c(%rip), %rsi      # 0x1cd38
callq 0x3df0
jmp 0x190a3
leaq -0x151(%rbp), %rdi
callq 0x3370
movq -0x168(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x19fc0
jmp 0x190c4
leaq 0x2fb7(%rip), %rsi      # 0x1c082
leaq -0x38(%rbp), %rdi
callq 0x3440
jmp 0x190d6
leaq -0x150(%rbp), %rdi
callq 0x15570
jmp 0x19129
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x151(%rbp), %rdi
callq 0x3370
jmp 0x1915a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x150(%rbp), %rdi
callq 0x15570
jmp 0x1915a
movsbl -0x45(%rbp), %esi
leaq -0x38(%rbp), %rdi
callq 0x3290
jmp 0x19127
jmp 0x19129
jmp 0x1912b
jmp 0x1912d
jmp 0x1912f
jmp 0x19131
jmp 0x19133
jmp 0x19135
jmp 0x19137
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x18c93
movb $0x1, -0x11(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x3210
testb $0x1, -0x11(%rbp)
jne 0x1917d
jmp 0x19171
leaq -0x38(%rbp), %rdi
callq 0x3210
movq -0x168(%rbp), %rdi
callq 0x17860
jmp 0x1918d
movq -0x168(%rbp), %rdi
callq 0x17860
movq -0x160(%rbp), %rax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x3510
nopw %cs:(%rax,%rax)