// File: /workspace/github_cpp_makefile_star2_O2/Nallantli[P]Rossa/main/rossa/node_parser/node_parser.cpp
// Function: node_parser_t::parseBinOpNode(std::vector<node_scope_t, std::allocator<node_scope_t>>*, std::shared_ptr<Node> const&)
ptr_node_t node_parser_t::parseBinOpNode(std::vector<node_scope_t> *scopes, const ptr_node_t &a)
{
	ptr_node_t current = a;
	int pastPrec = 999;

	while (currentToken.type != NULL_TOK && BINARY_OPERATORS.find(currentToken.valueString) != BINARY_OPERATORS.end())
	{
		std::string opStr = currentToken.valueString;

		/*
		if (opStr == ":=") {
			scopes->back().var_ids.push_back(ROSSA_HASH(a->getToken().valueString));
		}*/

		int prec = BINARY_OPERATORS.at(opStr);

		auto marker = currentToken;

		nextToken();

		if (auto b = parseUnitNode(scopes))
		{
			if (std::abs(prec) < std::abs(pastPrec) || (std::abs(prec) == std::abs(pastPrec) && prec > 0))
			{
				current = std::make_shared<BinOpNode>(*scopes,
													  opStr,
													  current,
													  b,
													  marker);
				pastPrec = prec;
			}
			else
			{
				ptr_node_t parent = nullptr;
				auto n = current;
				while (n->getType() == Node::type_t::BIN_OP_NODE)
				{
					auto bon = reinterpret_cast<BinOpNode *>(n.get());
					auto oldOp = bon->getOp();
					auto bon_b = bon->getB();

					if (!(std::abs(BINARY_OPERATORS.at(oldOp) < std::abs(prec) || (std::abs(BINARY_OPERATORS.at(oldOp)) == std::abs(prec) && BINARY_OPERATORS.at(oldOp) < 0))))
					{
						reinterpret_cast<BinOpNode *>(parent.get())->setB(std::make_shared<BinOpNode>(*scopes, opStr, n, b, marker));
						break;
					}
					if (bon_b->getType() != Node::type_t::BIN_OP_NODE)
					{
						bon->setB(std::make_shared<BinOpNode>(*scopes,
															  opStr,
															  bon_b,
															  b,
															  marker));
						break;
					}
					parent = n;
					n = bon_b;
				}
				pastPrec = BINARY_OPERATORS.at(reinterpret_cast<BinOpNode *>(current.get())->getOp());
			}
		}
		else
		{
			return logErrorN(_EXPECTED_RH_, currentToken);
		}
	}

	return current;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rdx, 0x18(%rsp)
movq %rsi, %r13
movq %rdi, 0x90(%rsp)
leaq 0x60(%rsp), %rdi
movq %rcx, %rsi
callq 0x2f676
leaq 0x58(%r13), %rax
movq %rax, 0x78(%rsp)
leaq 0xb0(%r13), %rbp
movl $0x3e7, %r15d           # imm = 0x3E7
leaq 0xb8(%rsp), %rbx
leaq 0x98(%rsp), %r12
movq %r13, 0x70(%rsp)
cmpl $0x0, 0xd0(%r13)
je 0x28d34
leaq 0x8e092(%rip), %rdi     # 0xb6b08
movq %rbp, %rsi
callq 0x220d0
leaq 0x8e08b(%rip), %rcx     # 0xb6b10
cmpq %rcx, %rax
je 0x28d34
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x10550
leaq 0x8e068(%rip), %rdi     # 0xb6b08
movq %rbx, %r14
movq %rbx, %rsi
callq 0x2ee74
movl (%rax), %ebx
leaq 0xd8(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0x1f71a
movq %r13, %rdi
callq 0x22e24
leaq 0x40(%rsp), %rdi
movq %r13, %rsi
movq 0x18(%rsp), %rdx
callq 0x2780a
cmpq $0x0, 0x40(%rsp)
je 0x28d6b
movq %rbp, %r13
movl %ebx, %ebp
negl %ebp
cmovsl %ebx, %ebp
movl %r15d, %eax
negl %eax
cmovsl %r15d, %eax
cmpl %eax, %ebp
jb 0x28b04
testl %ebx, %ebx
jle 0x28b41
cmpl %eax, %ebp
jne 0x28b41
movq %r12, %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
leaq 0x60(%rsp), %r15
movq %r15, %rcx
leaq 0x40(%rsp), %r8
leaq 0xd8(%rsp), %r9
callq 0x2eeb9
movq %r15, %rdi
movq %r12, %rsi
callq 0x3335e
leaq 0xa0(%rsp), %rdi
jmp 0x28cfd
xorps %xmm0, %xmm0
movaps %xmm0, 0x50(%rsp)
leaq 0x30(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x2f676
leaq 0x88(%rsp), %r15
movq 0x30(%rsp), %rdi
callq 0x4ec06
cmpl $0x4, %eax
jne 0x28cd3
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
callq 0x53a18
movq %r12, %rdi
movq %rax, %rsi
callq 0x10550
leaq 0x80(%rsp), %rdi
movq %rbx, %rsi
callq 0x53a36
leaq 0x8df66(%rip), %rdi     # 0xb6b08
movq %r12, %rsi
callq 0x2ee74
cmpl %ebp, (%rax)
jl 0x28bde
leaq 0x8df53(%rip), %rdi     # 0xb6b08
movq %r12, %rsi
callq 0x2ee74
movl (%rax), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl %ebp, %ecx
jne 0x28c27
leaq 0x8df37(%rip), %rdi     # 0xb6b08
movq %r12, %rsi
callq 0x2ee74
cmpl $0x0, (%rax)
jns 0x28c27
movq 0x80(%rsp), %rdi
callq 0x4ec06
cmpl $0x4, %eax
jne 0x28c6d
leaq 0x50(%rsp), %rdi
leaq 0x30(%rsp), %rbx
movq %rbx, %rsi
callq 0x2fc8e
movq %rbx, %rdi
leaq 0x80(%rsp), %rsi
callq 0x2fc8e
movq %r15, %rdi
callq 0x1d786
movq %r12, %rdi
callq 0x101d0
jmp 0x28b60
movq 0x50(%rsp), %rbx
movq %rsp, %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
leaq 0x30(%rsp), %rcx
leaq 0x40(%rsp), %r8
leaq 0xd8(%rsp), %r9
callq 0x2eeb9
movaps (%rsp), %xmm0
movaps %xmm0, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq %rbx, %rdi
leaq 0x20(%rsp), %rsi
callq 0x53a58
jmp 0x28caf
movq %rsp, %rdi
movq 0x18(%rsp), %rsi
movq %r14, %rdx
leaq 0x80(%rsp), %rcx
leaq 0x40(%rsp), %r8
leaq 0xd8(%rsp), %r9
callq 0x2eeb9
movaps (%rsp), %xmm0
movaps %xmm0, 0x20(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq %rbx, %rdi
leaq 0x20(%rsp), %rsi
callq 0x53a58
leaq 0x28(%rsp), %rdi
callq 0x1d786
leaq 0x8(%rsp), %rdi
callq 0x1d786
movq %r15, %rdi
callq 0x1d786
movq %r12, %rdi
callq 0x101d0
movq 0x60(%rsp), %rdi
callq 0x53a18
leaq 0x8de24(%rip), %rdi     # 0xb6b08
movq %rax, %rsi
callq 0x2ee74
movl (%rax), %ebx
leaq 0x38(%rsp), %rdi
callq 0x1d786
leaq 0x58(%rsp), %rdi
callq 0x1d786
movq %r13, %rbp
leaq 0x48(%rsp), %rdi
callq 0x1d786
leaq 0xd8(%rsp), %rdi
callq 0x1df38
movq %r14, %rdi
callq 0x101d0
movl %ebx, %r15d
movq %r14, %rbx
movq 0x70(%rsp), %r13
jmp 0x28a61
leaq 0x68(%rsp), %rdi
movaps -0x8(%rdi), %xmm0
andq $0x0, (%rdi)
movq 0x90(%rsp), %rbx
movups %xmm0, (%rbx)
andq $0x0, -0x8(%rdi)
callq 0x1d786
movq %rbx, %rax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4dc06(%rip), %rsi     # 0x76978
leaq 0x98(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x1c814
leaq 0x98(%rsp), %rdx
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rcx
callq 0x25932
jmp 0x28d9f
jmp 0x28df6
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x1d786
leaq 0x8(%rsp), %rdi
callq 0x1d786
jmp 0x28df9
jmp 0x28df6
jmp 0x28df1
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x101d0
jmp 0x28e22
jmp 0x28dd0
movq %rax, %rbx
jmp 0x28e22
jmp 0x28de5
jmp 0x28ddb
jmp 0x28de0
movq %rax, %rbx
jmp 0x28e39
movq %rax, %rbx
jmp 0x28e2c
movq %rax, %rbx
jmp 0x28e46
movq %rax, %rbx
jmp 0x28e01
jmp 0x28df1
movq %rax, %rbx
jmp 0x28e0e
movq %rax, %rbx
movq %r15, %rdi
callq 0x1d786
leaq 0x98(%rsp), %rdi
callq 0x101d0
leaq 0x38(%rsp), %rdi
callq 0x1d786
leaq 0x58(%rsp), %rdi
callq 0x1d786
leaq 0x48(%rsp), %rdi
callq 0x1d786
leaq 0xd8(%rsp), %rdi
callq 0x1df38
leaq 0xb8(%rsp), %rdi
callq 0x101d0
leaq 0x68(%rsp), %rdi
callq 0x1d786
movq %rbx, %rdi
callq 0x106f0