// File: /workspace/github_cpp_makefile_star2_O1/iamlouk[P]asbi/src/parser.cc
// Function: asbi::Parser::parse_final()
ast::Node* Parser::parse_final() {
	tok::Token t = tokenizer.next();
	switch (t.type) {
	case tok::Int:
		return new ast::Number(static_cast<double>(t.integer));
	case tok::Real:
		return new ast::Number(t.real);
	case tok::Bool:
		return new ast::Bool(t.integer != 0 ? true : false);
	case tok::String:{
		auto str = new ast::String(ctx->new_stringconstant(*t.str));
		delete t.str;
		return str;
	}
	case tok::Identifier:{
		auto var = new ast::Variable(ctx->new_stringconstant(*t.str));
		delete t.str;
		return var;
	}
	case tok::Nil:
		return new ast::Nil();
	case tok::Colon:{
		t = tokenizer.next();
		if (t.type != tok::Identifier)
			throw utils::parser_error("expected identifier (symbol)", t);
		auto sym = new ast::Symbol(ctx->new_stringconstant(*t.str));
		delete t.str;
		return sym;
	}
	case tok::LeftBracket:{
		if (tokenizer.peek().type == tok::RightBracket) {
			tokenizer.next();
			return parse_lambda(std::vector<ast::Node*>());
		}

		auto node = parse_expr();
		t = tokenizer.next();
		if (t.type == tok::RightBracket) {
			if (tokenizer.peek().type == tok::Arrow) {
				std::vector<ast::Node*> vec = { node };
				return parse_lambda(vec);
			}
			return node;
		}

		std::vector<ast::Node*> vec = { node };
		while (t.type == tok::Comma) {
			if (tokenizer.peek().type == tok::RightBracket) {
				t = tokenizer.next();
				break;
			}
			vec.push_back(parse_expr());
			t = tokenizer.next();
		}

		if (t.type != tok::RightBracket)
			throw utils::parser_error("expected ',' or ')' while parsing tuple", t);

		if (tokenizer.peek().type == tok::Arrow)
			return parse_lambda(std::move(vec));

		throw utils::parser_error("tuples unimplemented", t);
	}
	case tok::LeftSquareBracket:{
		if (tokenizer.peek().type == tok::Comma) {
			tokenizer.next();
			expect(tok::RightSquareBracket);
			return new ast::List(std::vector<ast::Node*>());
		}

		if (tokenizer.peek().type == tok::KeyValue) {
			tokenizer.next();
			expect(tok::RightSquareBracket);
			return new ast::Map(std::vector<std::pair<ast::Node*,ast::Node*>>());
		}

		auto node = parse_expr();
		auto token = tokenizer.next();
		if (token.type == tok::KeyValue)
			return parse_map(node);

		std::vector<ast::Node*> vec = { node };
		while (token.type == tok::Comma) {
			vec.push_back(parse_expr());
			token = tokenizer.next();
		}

		if (token.type != tok::RightSquareBracket)
			throw utils::parser_error("expected ',' or ')' while parsing list", t);

		return new ast::List(std::move(vec));
	}
	case tok::LeftCurlyBracket:
		return parse_block();
	default:
		throw utils::parser_error("unexpected token", t);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %r14
callq 0x6a44
movq %rax, %rbx
movq %rdx, %r15
movq %rdx, 0x8(%rsp)
cmpl $0x5, %ebx
ja 0x9280
movl %ebx, %eax
leaq 0xe44e(%rip), %rcx      # 0x176a0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x10, %edi
callq 0x5380
movq %rax, %rbx
movq 0x30(%r14), %rdi
movq %r15, %rsi
callq 0x10b4c
leaq 0x173cd(%rip), %rcx     # 0x20648
jmp 0x9425
leal -0x17(%rbx), %eax
cmpl $0x8, %eax
ja 0x983f
leaq 0xe425(%rip), %rcx      # 0x176b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
callq 0x6a1a
movq %r14, %rdi
cmpl $0x18, %eax
jne 0x94ad
callq 0x6a44
xorpd %xmm0, %xmm0
leaq 0x90(%rsp), %rsi
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
movq %r14, %rdi
callq 0x9af4
movq %rax, %rbx
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x97ba
movq 0xa0(%rsp), %rsi
jmp 0x97b2
movq %r14, %rdi
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x89e6
movq %r14, %rdi
callq 0x6a1a
movq %r14, %rdi
cmpl $0x1d, %eax
jne 0x9533
callq 0x6a44
movq %r14, %rdi
movl $0x1c, %esi
callq 0x810c
movl $0x20, %edi
callq 0x5380
movq %rax, %rbx
xorpd %xmm0, %xmm0
leaq 0x70(%rsp), %rsi
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
leaq 0x1774a(%rip), %rax     # 0x20aa8
addq $0x10, %rax
movq %rax, (%rbx)
leaq 0x8(%rbx), %rdi
callq 0xa00e
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x97ba
movq 0x80(%rsp), %rsi
jmp 0x97b2
movq %r14, %rdi
callq 0x6a44
movq %rax, %r12
movq %rdx, %r15
movq %rdx, 0x8(%rsp)
testl %r12d, %r12d
jne 0x9807
movl $0x10, %edi
callq 0x5380
movq %rax, %rbx
movq 0x30(%r14), %rdi
movq %r15, %rsi
callq 0x10b4c
leaq 0x17553(%rip), %rcx     # 0x20918
jmp 0x9425
movl $0x10, %edi
callq 0x5380
movq %rax, %rbx
leaq 0x174ad(%rip), %rax     # 0x20888
addq $0x10, %rax
cmpl $0x0, 0x8(%rsp)
movq %rax, (%rbx)
setne 0x8(%rbx)
jmp 0x97ba
movl $0x10, %edi
callq 0x5380
movq %rax, %rbx
movsd 0x8(%rsp), %xmm0
jmp 0x9475
movl $0x10, %edi
callq 0x5380
movq %rax, %rbx
movq 0x30(%r14), %rdi
movq %r15, %rsi
callq 0x10b4c
leaq 0x174ab(%rip), %rcx     # 0x208d0
addq $0x10, %rcx
movq %rcx, (%rbx)
movq %rax, 0x8(%rbx)
movq 0x8(%rsp), %r14
testq %r14, %r14
je 0x97ba
movq (%r14), %rdi
leaq 0x10(%r14), %rax
cmpq %rax, %rdi
je 0x9455
movq (%rax), %rsi
incq %rsi
callq 0x5390
movl $0x20, %esi
movq %r14, %rdi
jmp 0x97b5
movl $0x10, %edi
callq 0x5380
movq %rax, %rbx
cvtsi2sdl 0x8(%rsp), %xmm0
leaq 0x173c4(%rip), %rax     # 0x20840
addq $0x10, %rax
movq %rax, (%rbx)
movsd %xmm0, 0x8(%rbx)
jmp 0x97ba
movl $0x8, %edi
callq 0x5380
movq %rax, %rbx
leaq 0x17357(%rip), %rax     # 0x207f8
addq $0x10, %rax
movq %rax, (%rbx)
jmp 0x97ba
callq 0x8330
movq %rax, %rbx
movq %r14, %rdi
callq 0x6a44
movq %rax, %r15
movq %rdx, 0x8(%rsp)
cmpl $0x18, %r15d
jne 0x95a7
movq %r14, %rdi
callq 0x6a1a
cmpl $0xc, %eax
jne 0x97ba
leaq 0x30(%rsp), %rsi
movq %rbx, (%rsi)
leaq 0x10(%rsp), %rdi
leaq 0x7(%rsp), %rcx
movl $0x1, %edx
callq 0xa08e
leaq 0x38(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0xa00e
leaq 0x38(%rsp), %rsi
movq %r14, %rdi
callq 0x9af4
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x97a3
movq 0x48(%rsp), %rsi
jmp 0x9715
callq 0x6a1a
movq %r14, %rdi
cmpl $0xd, %eax
jne 0x961e
callq 0x6a44
movq %r14, %rdi
movl $0x1c, %esi
callq 0x810c
movl $0x20, %edi
callq 0x5380
movq %rax, %rbx
xorpd %xmm0, %xmm0
leaq 0x50(%rsp), %rsi
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
leaq 0x17559(%rip), %rax     # 0x20ad8
addq $0x10, %rax
movq %rax, (%rbx)
leaq 0x8(%rbx), %rdi
callq 0xa1aa
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x97ba
movq 0x60(%rsp), %rsi
jmp 0x97b2
leaq 0x30(%rsp), %rsi
movq %rbx, (%rsi)
leaq 0x10(%rsp), %rdi
leaq 0x7(%rsp), %rcx
movl $0x1, %edx
callq 0xa08e
movq 0x8(%rsp), %rbx
cmpl $0x1d, %r15d
jne 0x9730
leaq 0x10(%rsp), %r12
leaq 0x30(%rsp), %r13
movq %r14, %rdi
callq 0x6a1a
cmpl $0x18, %eax
je 0x971d
movq %r14, %rdi
callq 0x8330
movq %rax, 0x30(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0xa2f6
movq %r14, %rdi
callq 0x6a44
movq %rax, %r15
movq %rdx, %rbx
cmpl $0x1d, %r15d
je 0x95dc
jmp 0x9730
callq 0x8330
movq %rax, %r12
movq %r14, %rdi
callq 0x6a44
movq %rax, %rbp
cmpl $0xd, %ebp
jne 0x9652
movq %r14, %rdi
movq %r12, %rsi
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9dd8
leaq 0x30(%rsp), %rsi
movq %r12, (%rsi)
leaq 0x10(%rsp), %rdi
leaq 0x7(%rsp), %rcx
movl $0x1, %edx
callq 0xa08e
leaq 0x10(%rsp), %r12
leaq 0x30(%rsp), %r13
cmpl $0x1d, %ebp
jne 0x96a2
movq %r14, %rdi
callq 0x8330
movq %rax, 0x30(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0xa2f6
movq %r14, %rdi
callq 0x6a44
movq %rax, %rbp
jmp 0x9678
cmpl $0x1c, %ebp
jne 0x97cf
movl $0x20, %edi
callq 0x5380
movq %rax, %rbx
movq 0x10(%rsp), %rax
leaq 0xa8(%rsp), %rsi
movq %rax, (%rsi)
movups 0x18(%rsp), %xmm0
movups %xmm0, 0x8(%rsi)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x173bf(%rip), %rax     # 0x20aa8
addq $0x10, %rax
movq %rax, (%rbx)
movq %rbx, %rdi
addq $0x8, %rdi
callq 0xa00e
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x97a3
movq 0xb8(%rsp), %rsi
subq %rdi, %rsi
jmp 0x979e
movq %rbx, 0x8(%rsp)
movq %r14, %rdi
callq 0x6a44
movq %rax, %r15
movq %rdx, %rbx
movq %rbx, 0x8(%rsp)
cmpl $0x18, %r15d
jne 0x9877
movq %r14, %rdi
callq 0x6a1a
cmpl $0xc, %eax
jne 0x989d
movq 0x10(%rsp), %r15
movq 0x18(%rsp), %rax
leaq 0xc0(%rsp), %rsi
movq %r15, (%rsi)
movq %rax, 0x8(%rsi)
movq 0x20(%rsp), %r12
movq %r12, 0x10(%rsi)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq %r14, %rdi
callq 0x9af4
movq %rax, %rbx
testq %r15, %r15
je 0x97a3
subq %r15, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x5390
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x97ba
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movq %rbx, %rax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x48, %edi
callq 0x51b0
movq %rax, %r12
leaq 0xe040(%rip), %rsi      # 0x17823
movq %rax, %rdi
movq %rbx, %rdx
movq %r15, %rcx
callq 0xa9f6
leaq 0x16d80(%rip), %rsi     # 0x20578
leaq 0x7df(%rip), %rdx       # 0x9fde
movq %r12, %rdi
callq 0x55d0
movl $0x48, %edi
callq 0x51b0
movq %rax, %rbx
leaq 0xdfae(%rip), %rsi      # 0x177c9
movq %rax, %rdi
movq %r12, %rdx
movq %r15, %rcx
callq 0xa9f6
leaq 0x16d48(%rip), %rsi     # 0x20578
leaq 0x7a7(%rip), %rdx       # 0x9fde
movq %rbx, %rdi
callq 0x55d0
movl $0x48, %edi
callq 0x51b0
movq %rax, %r12
leaq 0xdea1(%rip), %rsi      # 0x176f4
movq %rax, %rdi
movq %rbx, %rdx
movq %r15, %rcx
callq 0xa9f6
leaq 0x16d10(%rip), %rsi     # 0x20578
leaq 0x76f(%rip), %rdx       # 0x9fde
movq %r12, %rdi
callq 0x55d0
movl $0x48, %edi
callq 0x51b0
movq %rax, %rbx
movq 0x8(%rsp), %rcx
leaq 0xdf56(%rip), %rsi      # 0x177e6
movq %rax, %rdi
movq %r15, %rdx
callq 0xa9f6
jmp 0x98c1
movl $0x48, %edi
callq 0x51b0
movq %rax, %rbx
movq 0x8(%rsp), %rcx
leaq 0xdf58(%rip), %rsi      # 0x1780e
movq %rax, %rdi
movq %r15, %rdx
callq 0xa9f6
leaq 0x16cb0(%rip), %rsi     # 0x20578
leaq 0x70f(%rip), %rdx       # 0x9fde
movq %rbx, %rdi
callq 0x55d0
jmp 0x9a02
movq %rax, %r14
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x98fc
movq 0xb8(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movl $0x20, %esi
movq %rbx, %rdi
jmp 0x994c
jmp 0x9908
movq %rax, %r14
movq %rbx, %rdi
jmp 0x99e9
movq %rax, %r14
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x9a05
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
jmp 0x994c
jmp 0x9a02
jmp 0x9960
jmp 0x9960
movq %rax, %r14
testq %r15, %r15
je 0x9a05
subq %r15, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x5390
jmp 0x9a05
jmp 0x9a02
jmp 0x9a02
movq %rax, %r14
jmp 0x9a1c
movq %rax, %r14
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x99b1
movq 0x60(%rsp), %rsi
jmp 0x99a9
movq %rax, %r14
movq %r12, %rdi
jmp 0x998a
movq %rax, %r14
movq %rbx, %rdi
callq 0x5280
jmp 0x9a1c
movq %rax, %r14
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x99b1
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movl $0x20, %esi
jmp 0x99de
movq %rax, %r14
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x9a1c
movq 0xa0(%rsp), %rsi
jmp 0x9a14
jmp 0x99d6
jmp 0x99d6
movq %rax, %r14
movl $0x10, %esi
movq %rbx, %rdi
jmp 0x9a17
movq %rax, %r14
movq %r12, %rdi
callq 0x5280
jmp 0x9a05
jmp 0x99f8
jmp 0x99f8
jmp 0x9a02
jmp 0x9a02
movq %rax, %r14
movq %rbx, 0x8(%rsp)
jmp 0x9a05
movq %rax, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x9a1c
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movq %r14, %rdi
callq 0x55e0