// File: /workspace/github_cpp_makefile_star2_O3/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 0x69fe
movq %rax, %rbx
movq %rdx, %r15
cmpl $0x5, %ebx
ja 0x9184
movq %rdx, %r12
movl %ebx, %eax
leaq 0xe54a(%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 0x10a4c
leaq 0x174c9(%rip), %rcx     # 0x20648
jmp 0x933c
leal -0x17(%rbx), %eax
cmpl $0x8, %eax
ja 0x9734
leaq 0xe521(%rip), %rcx      # 0x176b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
callq 0x69d4
movq %r14, %rdi
cmpl $0x18, %eax
jne 0x93b6
callq 0x69fe
xorpd %xmm0, %xmm0
leaq 0xa0(%rsp), %rsi
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
movq %r14, %rdi
callq 0x99ba
movq %rax, %rbx
jmp 0x96af
movq %r14, %rdi
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x88da
movq %r14, %rdi
callq 0x69d4
movq %r14, %rdi
cmpl $0x1d, %eax
jne 0x943a
callq 0x69fe
movq %r14, %rdi
movl $0x1c, %esi
callq 0x8044
movl $0x20, %edi
callq 0x5380
movq %rax, %rbx
xorpd %xmm0, %xmm0
leaq 0x70(%rsp), %rsi
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
leaq 0x1785f(%rip), %rax     # 0x20aa8
addq $0x10, %rax
movq %rax, (%rbx)
leaq 0x8(%rbx), %rdi
callq 0x9eb0
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x96af
movq 0x80(%rsp), %rsi
jmp 0x96a7
movq %r14, %rdi
callq 0x69fe
movq %rax, %r12
movq %rdx, %r15
testl %r12d, %r12d
jne 0x96fc
movl $0x10, %edi
callq 0x5380
movq %rax, %rbx
movq 0x30(%r14), %rdi
movq %r15, %rsi
callq 0x10a4c
leaq 0x1766d(%rip), %rcx     # 0x20918
addq $0x10, %rcx
movq %rcx, (%rbx)
movq %rax, 0x8(%rbx)
movq (%r15), %rdi
movq %r15, %rax
addq $0x10, %rax
cmpq %rax, %rdi
je 0x935f
movq (%rax), %rsi
jmp 0x9357
movl $0x10, %edi
callq 0x5380
movq %rax, %rbx
leaq 0x175a3(%rip), %rax     # 0x20888
addq $0x10, %rax
testl %r12d, %r12d
movq %rax, (%rbx)
setne 0x8(%rbx)
jmp 0x96af
movl $0x10, %edi
callq 0x5380
movq %rax, %rbx
leaq 0x17534(%rip), %rax     # 0x20840
addq $0x10, %rax
movq %rax, (%rbx)
movq %r15, 0x8(%rbx)
jmp 0x96af
movl $0x10, %edi
callq 0x5380
movq %rax, %rbx
movq 0x30(%r14), %rdi
movq %r15, %rsi
callq 0x10a4c
leaq 0x17594(%rip), %rcx     # 0x208d0
addq $0x10, %rcx
movq %rcx, (%rbx)
movq %rax, 0x8(%rbx)
movq (%r15), %rdi
addq $0x10, %r12
cmpq %r12, %rdi
je 0x935f
movq (%r12), %rsi
incq %rsi
callq 0x5390
movl $0x20, %esi
movq %r15, %rdi
jmp 0x96aa
movl $0x10, %edi
callq 0x5380
movq %rax, %rbx
cvtsi2sd %r12d, %xmm0
leaq 0x174bb(%rip), %rax     # 0x20840
addq $0x10, %rax
movq %rax, (%rbx)
movsd %xmm0, 0x8(%rbx)
jmp 0x96af
movl $0x8, %edi
callq 0x5380
movq %rax, %rbx
leaq 0x1744e(%rip), %rax     # 0x207f8
addq $0x10, %rax
movq %rax, (%rbx)
jmp 0x96af
callq 0x8262
movq %rax, %rbx
movq %r14, %rdi
callq 0x69fe
movq %rax, %r15
movl %r15d, %r13d
cmpq $0x18, %r13
jne 0x94ae
movq %r14, %rdi
callq 0x69d4
cmpl $0xc, %eax
jne 0x96af
leaq 0x30(%rsp), %rsi
movq %rbx, (%rsi)
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rcx
movl $0x1, %edx
callq 0x9f30
leaq 0x38(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x9eb0
leaq 0x38(%rsp), %rsi
movq %r14, %rdi
callq 0x99ba
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x9698
movq 0x48(%rsp), %rsi
jmp 0x9617
callq 0x69d4
movq %r14, %rdi
cmpl $0xd, %eax
jne 0x9520
callq 0x69fe
movq %r14, %rdi
movl $0x1c, %esi
callq 0x8044
movl $0x20, %edi
callq 0x5380
movq %rax, %rbx
xorpd %xmm0, %xmm0
leaq 0x50(%rsp), %rsi
movapd %xmm0, (%rsi)
movq $0x0, 0x10(%rsi)
leaq 0x17652(%rip), %rax     # 0x20ad8
addq $0x10, %rax
movq %rax, (%rbx)
leaq 0x8(%rbx), %rdi
callq 0xa04c
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x96af
movq 0x60(%rsp), %rsi
jmp 0x96a7
movq %rdx, %r12
leaq 0x30(%rsp), %rsi
movq %rbx, (%rsi)
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rcx
movl $0x1, %edx
callq 0x9f30
cmpl $0x1d, %r13d
jne 0x962a
leaq 0x10(%rsp), %rbx
leaq 0x30(%rsp), %r13
movq %r14, %rdi
callq 0x69d4
cmpl $0x18, %eax
je 0x961c
movq %r14, %rdi
callq 0x8262
movq %rax, 0x30(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xa198
movq %r14, %rdi
callq 0x69fe
movq %rax, %r15
cmpl $0x1d, %r15d
je 0x94e1
jmp 0x9627
callq 0x8262
movq %rax, %r12
movq %r14, %rdi
callq 0x69fe
movq %rax, %rbp
cmpl $0xd, %ebp
jne 0x9554
movq %r14, %rdi
movq %r12, %rsi
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x9c98
leaq 0x30(%rsp), %rsi
movq %r12, (%rsi)
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rcx
movl $0x1, %edx
callq 0x9f30
leaq 0x10(%rsp), %r12
leaq 0x30(%rsp), %r13
cmpl $0x1d, %ebp
jne 0x95a4
movq %r14, %rdi
callq 0x8262
movq %rax, 0x30(%rsp)
movq %r12, %rdi
movq %r13, %rsi
callq 0xa198
movq %r14, %rdi
callq 0x69fe
movq %rax, %rbp
jmp 0x957a
cmpl $0x1c, %ebp
jne 0x96c4
movl $0x20, %edi
callq 0x5380
movq %rax, %rbx
movq 0x10(%rsp), %rax
leaq 0x88(%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 0x174bd(%rip), %rax     # 0x20aa8
addq $0x10, %rax
movq %rax, (%rbx)
movq %rbx, %rdi
addq $0x8, %rdi
callq 0x9eb0
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x9698
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
jmp 0x9693
movq %r14, %rdi
callq 0x69fe
movq %rax, %r15
movq %rdx, %r12
cmpl $0x18, %r15d
jne 0x976c
movq %r14, %rdi
callq 0x69d4
cmpl $0xc, %eax
jne 0x9790
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 0x99ba
movq %rax, %rbx
testq %r15, %r15
je 0x9698
subq %r15, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x5390
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x96af
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 0xe14b(%rip), %rsi      # 0x17823
movq %rax, %rdi
movq %rbx, %rdx
movq %r15, %rcx
callq 0xa896
leaq 0x16e8b(%rip), %rsi     # 0x20578
leaq 0x78c(%rip), %rdx       # 0x9e80
movq %r12, %rdi
callq 0x55d0
movl $0x48, %edi
callq 0x51b0
movq %rax, %rbx
leaq 0xe0b9(%rip), %rsi      # 0x177c9
movq %rax, %rdi
movq %r12, %rdx
movq %r15, %rcx
callq 0xa896
leaq 0x16e53(%rip), %rsi     # 0x20578
leaq 0x754(%rip), %rdx       # 0x9e80
movq %rbx, %rdi
callq 0x55d0
movl $0x48, %edi
callq 0x51b0
movq %rax, %r12
leaq 0xdfac(%rip), %rsi      # 0x176f4
movq %rax, %rdi
movq %rbx, %rdx
movq %r15, %rcx
callq 0xa896
leaq 0x16e1b(%rip), %rsi     # 0x20578
leaq 0x71c(%rip), %rdx       # 0x9e80
movq %r12, %rdi
callq 0x55d0
movl $0x48, %edi
callq 0x51b0
movq %rax, %rbx
leaq 0xe066(%rip), %rsi      # 0x177e6
movq %rax, %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0xa896
jmp 0x97b2
movl $0x48, %edi
callq 0x51b0
movq %rax, %rbx
leaq 0xe06a(%rip), %rsi      # 0x1780e
movq %rax, %rdi
movq %r15, %rdx
movq %r12, %rcx
callq 0xa896
leaq 0x16dbf(%rip), %rsi     # 0x20578
leaq 0x6c0(%rip), %rdx       # 0x9e80
movq %rbx, %rdi
callq 0x55d0
jmp 0x98c8
movq %rax, %r14
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x97ed
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movl $0x20, %esi
movq %rbx, %rdi
jmp 0x983d
jmp 0x97f9
movq %rax, %r14
movq %rbx, %rdi
jmp 0x98b7
movq %rax, %r14
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x98cb
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
jmp 0x983d
jmp 0x98c8
jmp 0x984b
jmp 0x984b
movq %rax, %r14
testq %r15, %r15
je 0x98cb
subq %r15, %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x5390
jmp 0x98cb
jmp 0x98c8
jmp 0x98c8
movq %rax, %r14
jmp 0x98e2
movq %rax, %r14
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x9899
movq 0x60(%rsp), %rsi
jmp 0x9891
movq %rax, %r14
movq %r12, %rdi
jmp 0x9875
movq %rax, %r14
movq %rbx, %rdi
callq 0x5280
jmp 0x98e2
movq %rax, %r14
movq 0x70(%rsp), %rdi
testq %rdi, %rdi
je 0x9899
movq 0x80(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movl $0x20, %esi
jmp 0x98ac
jmp 0x98a4
jmp 0x98a4
movq %rax, %r14
movl $0x10, %esi
movq %rbx, %rdi
jmp 0x98dd
movq %rax, %r14
movq %r12, %rdi
callq 0x5280
jmp 0x98cb
jmp 0x98c8
jmp 0x98c8
jmp 0x98c8
jmp 0x98c8
jmp 0x98c8
movq %rax, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x98e2
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movq %r14, %rdi
callq 0x55e0