// File: /workspace/github_cpp_makefile_star2_O3/iamlouk[P]asbi/src/parser.cc
// Function: asbi::Parser::parse_assign()
ast::Node* Parser::parse_assign() {
	auto left = parse_logic();
	if (tokenizer.peek().type == tok::Assign) {
		tokenizer.next();
		auto right = parse_expr();

		ast::Variable* var = dynamic_cast<ast::Variable*>(left);
		if (var != nullptr)
			return new ast::AssignVariable(var, right);

		ast::Access* acs = dynamic_cast<ast::Access*>(left);
		if (acs != nullptr)
			return new ast::AssignAccess(acs, right);

		throw utils::parser_error("one can only assign to variables or dict subscripts", left);
	}

	if (tokenizer.peek().type == tok::Declare) {
		auto tok = tokenizer.next();

		auto right = parse_expr();
		auto var = dynamic_cast<ast::Variable*>(left);
		if (var != nullptr) {
			std::vector<std::pair<ast::Variable*, ast::Node*>> decls;
			decls.push_back(std::make_pair(var, right));
			while (tokenizer.peek().type == tok::Comma) {
				tokenizer.next();
				auto node = parse_logic();
				auto var = dynamic_cast<ast::Variable*>(node);
				if (var == nullptr)
					throw utils::parser_error("expected Variable", node);

				ast::Node* val = nullptr;
				if (tokenizer.peek().type == tok::Declare) {
					tokenizer.next();
					val = parse_logic();
				}

				decls.push_back(std::make_pair(var, val));
			}

			return new ast::VariableDecl(std::move(decls));
		}

		ast::List* list = dynamic_cast<ast::List*>(left);
		if (list != nullptr) {
			auto node = new ast::DestructList(std::move(list->values), right);
			list->values.clear();
			delete list;
			return node;
		}

		ast::Map* map = dynamic_cast<ast::Map*>(left);
		if (map != nullptr) {
			/*std::vector<std::pair<ast::Variable*, ast::Node*>> vars;
			for (auto [key, val]: map->values) {
				auto var = dynamic_cast<ast::Variable*>(val);
				if (var == nullptr)
					throw utils::parser_error("only variables allowed in destructuring", left);

				vars.push_back(std::make_pair(var, key));
			}
			map->values.clear();
			delete map;
			return new ast::DestructMap(std::move(vars), right);*/

			throw utils::parser_error("unimplemented!", left);
		}

		throw utils::parser_error("one can only declare variables or destruct using ':='", tok /*left*/);
	}

	return left;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %r14
callq 0x8b24
movq %rax, %rbx
movq %r14, %rdi
callq 0x69d4
movq %r14, %rdi
cmpl $0x6, %eax
jne 0x84a7
callq 0x69fe
movq %r14, %rdi
callq 0x8262
testq %rbx, %rbx
je 0x8789
movq %rax, %r14
leaq 0x1811f(%rip), %rsi     # 0x20590
leaq 0x18200(%rip), %rdx     # 0x20678
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x53f0
testq %rax, %rax
je 0x85d2
movq %rax, %r15
movl $0x18, %edi
callq 0x5380
movq %rax, %rbx
leaq 0x182c6(%rip), %rax     # 0x20768
jmp 0x860a
callq 0x69d4
cmpl $0x7, %eax
jne 0x8619
movq %r14, %rdi
callq 0x69fe
movq %rax, %r12
movq %rdx, %r13
movq %r14, %rdi
callq 0x8262
testq %rbx, %rbx
je 0x87db
movq %rax, %r15
leaq 0x180b2(%rip), %rsi     # 0x20590
leaq 0x18193(%rip), %rdx     # 0x20678
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x53f0
testq %rax, %rax
je 0x86a9
xorps %xmm0, %xmm0
movq %rsp, %rdi
movaps %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
leaq 0x18(%rsp), %rdx
movq %rax, (%rdx)
movq %r15, 0x8(%rdx)
xorl %esi, %esi
callq 0xa2f0
leaq 0x1806d(%rip), %rbx     # 0x20590
leaq 0x1814e(%rip), %r15     # 0x20678
leaq 0x18(%rsp), %r13
movq %r14, %rdi
callq 0x69d4
cmpl $0x1d, %eax
jne 0x862b
movq %r14, %rdi
callq 0x69fe
movq %r14, %rdi
callq 0x8b24
movq %rax, %r12
testq %rax, %rax
je 0x8754
movq %r12, %rdi
movq %rbx, %rsi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0x53f0
testq %rax, %rax
je 0x8754
movq %rax, %rbp
movq %r14, %rdi
callq 0x69d4
cmpl $0x7, %eax
jne 0x8597
movq %r14, %rdi
callq 0x69fe
movq %r14, %rdi
callq 0x8b24
jmp 0x8599
xorl %eax, %eax
movq %rbp, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x85c2
movups 0x18(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%rsp)
jmp 0x852f
movq %rsp, %rdi
movq %r13, %rdx
callq 0xa2f0
jmp 0x852f
leaq 0x17fb7(%rip), %rsi     # 0x20590
leaq 0x180e0(%rip), %rdx     # 0x206c0
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x53f0
testq %rax, %rax
je 0x8789
movq %rax, %r15
movl $0x18, %edi
callq 0x5380
movq %rax, %rbx
leaq 0x181a6(%rip), %rax     # 0x207b0
addq $0x10, %rax
movq %rax, (%rbx)
movq %r15, 0x8(%rbx)
movq %r14, 0x10(%rbx)
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x20, %edi
callq 0x5380
movq %rax, %rbx
movq (%rsp), %rax
leaq 0x40(%rsp), %rsi
movq %rax, (%rsi)
movups 0x8(%rsp), %xmm0
movups %xmm0, 0x8(%rsi)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
leaq 0x18384(%rip), %rax     # 0x209e8
addq $0x10, %rax
movq %rax, (%rbx)
movq %rbx, %rdi
addq $0x8, %rdi
callq 0x9fb8
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x868e
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x8619
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
jmp 0x8619
leaq 0x17ee0(%rip), %rsi     # 0x20590
leaq 0x18529(%rip), %rdx     # 0x20be0
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x53f0
testq %rax, %rax
je 0x87be
movq %rax, %r14
movl $0x28, %edi
callq 0x5380
movq %rax, %rbx
movq 0x8(%r14), %rax
leaq 0x28(%rsp), %rsi
movq %rax, (%rsi)
movq 0x10(%r14), %rax
movq %rax, 0x8(%rsi)
movq 0x18(%r14), %rax
movq %rax, 0x10(%rsi)
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%r14)
movq $0x0, 0x18(%r14)
leaq 0x1830b(%rip), %rax     # 0x20a18
addq $0x10, %rax
movq %rax, (%rbx)
leaq 0x8(%rbx), %rdi
callq 0x9eb0
movq %r15, 0x20(%rbx)
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x8738
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movq 0x8(%r14), %rax
cmpq %rax, 0x10(%r14)
je 0x8746
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq %r14, %rdi
callq *0x8(%rax)
jmp 0x8619
movl $0x48, %edi
callq 0x51b0
movq %rax, %rbx
leaq 0xefe5(%rip), %rsi      # 0x1774d
movq %rax, %rdi
movq %r12, %rdx
callq 0xaa7a
leaq 0x17dfe(%rip), %rsi     # 0x20578
leaq 0x16ff(%rip), %rdx      # 0x9e80
movq %rbx, %rdi
callq 0x55d0
movl $0x48, %edi
callq 0x51b0
movq %rax, %r15
leaq 0xef7c(%rip), %rsi      # 0x17719
movq %rax, %rdi
movq %rbx, %rdx
callq 0xaa7a
leaq 0x17dc9(%rip), %rsi     # 0x20578
leaq 0x16ca(%rip), %rdx      # 0x9e80
movq %r15, %rdi
callq 0x55d0
leaq 0x17dcb(%rip), %rsi     # 0x20590
leaq 0x1842c(%rip), %rdx     # 0x20bf8
movq %rbx, %rdi
xorl %ecx, %ecx
callq 0x53f0
testq %rax, %rax
jne 0x8813
movl $0x48, %edi
callq 0x51b0
movq %rax, %rbx
leaq 0xef7f(%rip), %rsi      # 0x1776e
movq %rax, %rdi
movq %r12, %rdx
movq %r13, %rcx
callq 0xa896
leaq 0x17d74(%rip), %rsi     # 0x20578
leaq 0x1675(%rip), %rdx      # 0x9e80
movq %rbx, %rdi
callq 0x55d0
movl $0x48, %edi
callq 0x51b0
movq %rax, %r15
leaq 0xef38(%rip), %rsi      # 0x1775f
movq %rax, %rdi
movq %rbx, %rdx
callq 0xaa7a
jmp 0x87a8
jmp 0x8892
movq %rax, %r14
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x8853
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movl $0x28, %esi
movq %rbx, %rdi
jmp 0x88cc
movq %rax, %r14
movq %rbx, %rdi
jmp 0x8898
movq %rax, %r14
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x887f
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movl $0x20, %esi
movq %rbx, %rdi
callq 0x5390
jmp 0x88bb
jmp 0x88b8
jmp 0x88b8
movq %rax, %r14
movq %r15, %rdi
callq 0x5280
jmp 0x88d1
jmp 0x88b8
jmp 0x88b8
jmp 0x88b8
jmp 0x88b8
jmp 0x88b8
jmp 0x88b8
movq %rax, %r14
movq %rbx, %rdi
callq 0x5280
jmp 0x88bb
movq %rax, %r14
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x88d1
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x5390
movq %r14, %rdi
callq 0x55e0
nop