// File: /workspace/github_cpp_makefile_star2_O3/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, %r15
movq %rdi, %rbx
leaq 0x30(%rdi), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x9(%rdi)
movups %xmm0, (%rdi)
movq %rax, 0x20(%rdi)
xorl %r12d, %r12d
movq %r12, 0x28(%rdi)
movb %r12b, 0x30(%rdi)
leaq 0x58(%rdi), %rax
movq %rax, 0x48(%rdi)
movq %r12, 0x50(%rdi)
movb %r12b, 0x58(%rdi)
movb %r12b, 0x68(%rdi)
leaq -0x188(%rbp), %rdi
callq 0x1007e
leaq 0x20(%rbx), %rax
movq %rax, -0x30(%rbp)
leaq -0x158(%rbp), %rax
movl %r12d, -0x18(%rax)
movb %r12b, -0x14(%rax)
movq %rax, -0x10(%rax)
movq %r12, -0x8(%rax)
movb %r12b, (%rax)
movl %r12d, 0x10(%rax)
leaq -0x130(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r12, -0x8(%rax)
movb %r12b, (%rax)
movb %r12b, 0x10(%rax)
movb %r12b, 0x18(%rax)
movq 0x8(%r15), %rax
subq (%r15), %rax
leaq 0x48(%rbx), %r15
shrq $0x3, %rax
imull $0xcccccccd, %eax, %eax # imm = 0xCCCCCCCD
testl %eax, %eax
je 0x11327
leaq -0x70(%rbp), %r13
leaq -0x48(%rbp), %r12
leaq -0x90(%rbp), %r14
cmpb $0x0, -0x16c(%rbp)
jne 0x113e9
leaq -0xf0(%rbp), %rdi
leaq -0x188(%rbp), %rsi
callq 0x10a56
cmpb $0x1, -0x118(%rbp)
jne 0x1118f
movb $0x1, 0x18(%rbx)
movq -0x30(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x2150
movl -0x148(%rbp), %eax
movl %eax, 0x40(%rbx)
movq %r15, %rdi
leaq -0x140(%rbp), %rsi
callq 0x2150
movb -0x120(%rbp), %al
movb %al, 0x68(%rbx)
jmp 0x112c9
cmpl $0x1, -0xf0(%rbp)
jne 0x111e8
movb $0x1, 0x18(%rbx)
leaq -0x110(%rbp), %r14
movq %r14, %rdi
leaq 0x2d6c(%rip), %rsi      # 0x13f19
leaq -0xa0(%rbp), %rdx
callq 0xdbf3
movq %r14, %rdi
leaq 0x2d39(%rip), %rsi      # 0x13efc
callq 0x23e0
movq %r13, -0x80(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x111ff
movq %rdx, -0x80(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x70(%rbp)
jmp 0x11207
movb $0x1, %r13b
movq %rbx, %rdi
leaq -0xf0(%rbp), %rsi
callq 0x11606
jmp 0x112cc
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 -0xa8(%rbp), %eax
movl %eax, -0x60(%rbp)
movq %r12, -0x58(%rbp)
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rdx
addq %rsi, %rdx
movq %r12, %r14
leaq -0x58(%rbp), %r12
movq %r12, %rdi
callq 0x3688
movb $0x0, -0x38(%rbp)
movq -0x30(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x22d0
movl -0x60(%rbp), %eax
movl %eax, 0x40(%rbx)
movq %r15, %rdi
movq %r12, %rsi
callq 0x22d0
movb -0x38(%rbp), %al
movb %al, 0x68(%rbx)
movq -0x58(%rbp), %rdi
cmpq %r14, %rdi
movq %r14, %r12
je 0x1128b
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2240
movq -0x80(%rbp), %rdi
cmpq %r13, %rdi
leaq -0x90(%rbp), %r14
je 0x112a7
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2240
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x112c9
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x2240
xorl %r13d, %r13d
movq -0xa0(%rbp), %rdi
cmpq %r14, %rdi
je 0x112e7
movq -0x90(%rbp), %rsi
incq %rsi
callq 0x2240
movq -0xd0(%rbp), %rdi
leaq -0xc0(%rbp), %rax
cmpq %rax, %rdi
je 0x11309
movq -0xc0(%rbp), %rsi
incq %rsi
callq 0x2240
leaq -0xe8(%rbp), %rdi
callq 0xe08a
testb %r13b, %r13b
leaq -0x70(%rbp), %r13
jne 0x1112c
jmp 0x113e9
leaq -0xe0(%rbp), %rax
movq %rax, -0x10(%rax)
leaq 0x2b98(%rip), %rsi      # 0x13ed1
leaq 0x2bae(%rip), %rdx      # 0x13eee
leaq -0xf0(%rbp), %rdi
callq 0x3774
leaq -0xc8(%rbp), %r14
movl $0x0, -0x8(%r14)
leaq -0xb8(%rbp), %r12
movq %r12, -0x10(%r12)
movq $0x0, -0x8(%r12)
xorl %eax, %eax
movb %al, (%r12)
movb %al, 0x10(%r12)
leaq -0xf0(%rbp), %r13
movq -0x30(%rbp), %rdi
movq %r13, %rsi
callq 0x22d0
movl 0x20(%r13), %eax
movl %eax, 0x40(%rbx)
movq %r15, %rdi
movq %r14, %rsi
callq 0x22d0
movb 0x48(%r13), %al
movb %al, 0x68(%rbx)
movq 0x28(%r13), %rdi
cmpq %r12, %rdi
je 0x113bf
movq -0xb8(%rbp), %rsi
incq %rsi
callq 0x2240
movq -0xf0(%rbp), %rdi
leaq -0xe0(%rbp), %rax
cmpq %rax, %rdi
je 0x113e1
movq -0xe0(%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 0x1140b
movq -0x130(%rbp), %rsi
incq %rsi
callq 0x2240
movq -0x168(%rbp), %rdi
leaq -0x158(%rbp), %rax
cmpq %rax, %rdi
je 0x1142d
movq -0x158(%rbp), %rsi
incq %rsi
callq 0x2240
leaq -0x188(%rbp), %rdi
callq 0x10218
movq %rbx, %rax
addq $0x168, %rsp            # imm = 0x168
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x11498
movq %rax, %r14
jmp 0x114b8
movq %rax, %r14
movq -0x80(%rbp), %rdi
cmpq %r13, %rdi
je 0x11472
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2240
jmp 0x11472
movq %rax, %r14
movq -0x110(%rbp), %rdi
leaq -0x100(%rbp), %rax
cmpq %rax, %rdi
je 0x114a0
movq -0x100(%rbp), %rsi
incq %rsi
callq 0x2240
jmp 0x114a0
jmp 0x1149d
movq %rax, %r14
jmp 0x114ac
movq %rax, %r14
leaq -0xf0(%rbp), %rdi
callq 0xdccc
leaq -0x188(%rbp), %rdi
callq 0x1163e
movq %rbx, %rdi
callq 0xfff8
movq %r14, %rdi
callq 0x23a0