// File: /workspace/github_cpp_makefile_star2_O1/Mespyr[P]bop-lisp/src/parser.cpp
// Function: parse(TokenList)
AST parse(TokenList tokens) 
{
    AST ast;
    Reader reader{tokens};

    if ((int) tokens.token_stream.size() == 0) 
    {
        ast.error = ParsingError{"Unexpected EOF while parsing."};
        ast.error.empty_stream = true;
        ast.error_found = true;
        return ast;
    }

    while(!reader.eof) 
    {
        Node node = read_next(reader);
        if (reader.error_found) 
        {
            ast.error_found = true;
            ast.error = reader.error;
            break;
        } 
        else if (node.type == ATOM) 
        {
            ast.error_found = true;
            ast.error = ParsingError{"Unexpected '" + node.atom.token.value + "' token found while parsing.", node.atom.token};
            break;
        }
        ast.nodes.push_back(node);
    }
    return ast;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x30(%rdi), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x9(%rdi)
movups %xmm0, (%rdi)
movq %rax, 0x20(%rdi)
xorl %r15d, %r15d
movq %r15, 0x28(%rdi)
movb %r15b, 0x30(%rdi)
leaq 0x58(%rdi), %rax
movq %rax, 0x48(%rdi)
movq %r15, 0x50(%rdi)
movb %r15b, 0x58(%rdi)
movb %r15b, 0x68(%rdi)
leaq -0x188(%rbp), %rdi
callq 0x100c4
leaq -0x158(%rbp), %rax
movl %r15d, -0x18(%rax)
movb %r15b, -0x14(%rax)
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
movl %r15d, 0x10(%rax)
leaq -0x130(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r15, -0x8(%rax)
movb %r15b, (%rax)
movb %r15b, 0x10(%rax)
movb %r15b, 0x18(%rax)
movq 0x8(%r14), %rax
subq (%r14), %rax
leaq 0x20(%rbx), %rcx
movq %rcx, -0x30(%rbp)
shrq $0x3, %rax
imull $0xcccccccd, %eax, %eax # imm = 0xCCCCCCCD
testl %eax, %eax
je 0x11301
leaq -0x70(%rbp), %r13
leaq -0x48(%rbp), %r15
leaq 0x48(%rbx), %r12
leaq -0x140(%rbp), %r14
cmpb $0x0, -0x16c(%rbp)
jne 0x113bd
leaq -0x110(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x10a58
cmpb $0x1, -0x118(%rbp)
jne 0x11162
movb $0x1, 0x18(%rbx)
movq -0x30(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x2150
movl -0x148(%rbp), %eax
movl %eax, 0x40(%rbx)
movq %r12, %rdi
movq %r14, %rsi
callq 0x2150
movb -0x120(%rbp), %al
movb %al, 0x68(%rbx)
jmp 0x1129c
cmpl $0x1, -0x110(%rbp)
jne 0x111bb
movb $0x1, 0x18(%rbx)
leaq -0xa0(%rbp), %r14
movq %r14, %rdi
leaq 0x2d99(%rip), %rsi      # 0x13f19
leaq -0xc0(%rbp), %rdx
callq 0xdc6d
movq %r14, %rdi
leaq 0x2d66(%rip), %rsi      # 0x13efc
callq 0x23e0
movq %r13, -0x80(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x111d2
movq %rdx, -0x80(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x70(%rbp)
jmp 0x111da
movb $0x1, %r13b
movq %rbx, %rdi
leaq -0x110(%rbp), %rsi
callq 0x115da
jmp 0x1129f
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
movq %rdx, -0x78(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl -0xc8(%rbp), %eax
movl %eax, -0x60(%rbp)
movq %r15, -0x58(%rbp)
movq -0xc0(%rbp), %rsi
movq -0xb8(%rbp), %rdx
addq %rsi, %rdx
movq %r15, %r14
leaq -0x58(%rbp), %r15
movq %r15, %rdi
callq 0x367e
movb $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x22d0
movl -0x60(%rbp), %eax
movl %eax, 0x40(%rbx)
movq %r12, %rdi
movq %r15, %rsi
callq 0x22d0
movb -0x38(%rbp), %al
movb %al, 0x68(%rbx)
movq -0x58(%rbp), %rdi
cmpq %r14, %rdi
movq %r14, %r15
je 0x1125e
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2240
movq -0x80(%rbp), %rdi
cmpq %r13, %rdi
leaq -0x140(%rbp), %r14
je 0x1127a
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2240
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x1129c
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2240
xorl %r13d, %r13d
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x112c1
movq -0xb0(%rbp), %rsi
incq %rsi
callq 0x2240
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x112e3
movq -0xe0(%rbp), %rsi
incq %rsi
callq 0x2240
leaq -0x108(%rbp), %rdi
callq 0xe0cc
testb %r13b, %r13b
leaq -0x70(%rbp), %r13
jne 0x11103
jmp 0x113bd
leaq -0x100(%rbp), %r14
movq %r14, -0x10(%r14)
leaq 0x2bbe(%rip), %rsi      # 0x13ed1
leaq 0x2bd4(%rip), %rdx      # 0x13eee
leaq -0x110(%rbp), %rdi
callq 0x3766
leaq -0xe8(%rbp), %r15
movl $0x0, -0x8(%r15)
leaq -0xd8(%rbp), %r13
movq %r13, -0x10(%r13)
movq $0x0, -0x8(%r13)
xorl %eax, %eax
movb %al, (%r13)
movb %al, 0x10(%r13)
leaq -0x110(%rbp), %r12
movq -0x30(%rbp), %rdi
movq %r12, %rsi
callq 0x22d0
movl 0x20(%r12), %eax
movl %eax, 0x40(%rbx)
leaq 0x48(%rbx), %rdi
movq %r15, %rsi
callq 0x22d0
movb 0x48(%r12), %al
movb %al, 0x68(%rbx)
movq 0x28(%r12), %rdi
cmpq %r13, %rdi
je 0x1139a
movq -0xd8(%rbp), %rsi
incq %rsi
callq 0x2240
movq -0x110(%rbp), %rdi
cmpq %r14, %rdi
je 0x113b5
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x2240
movb $0x1, %al
movb %al, 0x68(%rbx)
movb %al, 0x18(%rbx)
movq -0x140(%rbp), %rdi
leaq -0x130(%rbp), %rax
cmpq %rax, %rdi
je 0x113df
movq -0x130(%rbp), %rsi
incq %rsi
callq 0x2240
movq -0x168(%rbp), %rdi
leaq -0x158(%rbp), %rax
cmpq %rax, %rdi
je 0x11401
movq -0x158(%rbp), %rsi
incq %rsi
callq 0x2240
leaq -0x188(%rbp), %rdi
callq 0x1025e
movq %rbx, %rax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1146c
movq %rax, %r14
jmp 0x1148c
movq %rax, %r14
movq -0x80(%rbp), %rdi
cmpq %r13, %rdi
je 0x11446
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2240
jmp 0x11446
movq %rax, %r14
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x11474
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2240
jmp 0x11474
jmp 0x11471
movq %rax, %r14
jmp 0x11480
movq %rax, %r14
leaq -0x110(%rbp), %rdi
callq 0xdd46
leaq -0x188(%rbp), %rdi
callq 0x11612
movq %rbx, %rdi
callq 0x1003e
movq %r14, %rdi
callq 0x23a0