// File: /workspace/github_cpp_makefile_star2_O1/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 $0x178, %rsp            # imm = 0x178
movq %rdx, 0x58(%rsp)
movq %rsi, %r14
movq %rdi, 0xe0(%rsp)
movq (%rcx), %rax
movq %rax, 0x48(%rsp)
movq 0x8(%rcx), %rax
movq %rax, 0x50(%rsp)
testq %rax, %rax
je 0x2e282
movq 0x88d1c(%rip), %rcx     # 0xb6f90
cmpb $0x0, (%rcx)
je 0x2e27e
incl 0x8(%rax)
jmp 0x2e282
lock
incl 0x8(%rax)
cmpl $0x0, 0xd0(%r14)
je 0x2e80b
leaq 0x58(%r14), %rax
movq %rax, 0xd8(%rsp)
leaq 0xb0(%r14), %rax
movq %rax, 0xf0(%rsp)
leaq 0x80(%rsp), %rbp
leaq 0xa0(%r14), %rax
movq %rax, 0xe8(%rsp)
leaq 0x160(%rsp), %r13
movl $0x3e7, 0xc(%rsp)       # imm = 0x3E7
leaq 0x70(%rsp), %r15
leaq 0x8981a(%rip), %rdi     # 0xb7af8
movq 0xf0(%rsp), %rsi
callq 0x243ce
leaq 0x8980e(%rip), %rcx     # 0xb7b00
cmpq %rcx, %rax
je 0x2e80b
movq %rbp, 0x70(%rsp)
movq 0xb0(%r14), %rsi
movq 0xb8(%r14), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x1e014
leaq 0x897d8(%rip), %rdi     # 0xb7af8
movq %r15, %rbx
movq %r15, %rsi
callq 0x374ca
movq %r13, %r15
movl (%rax), %r13d
leaq 0xf8(%rsp), %rdi
movq 0xd8(%rsp), %rsi
callq 0x1e698
leaq 0x130(%rsp), %rax
movq %rax, 0x120(%rsp)
movq 0x80(%r14), %rsi
movq 0x88(%r14), %rdx
addq %rsi, %rdx
leaq 0x120(%rsp), %r12
movq %r12, %rdi
callq 0x1e014
movq 0xe8(%rsp), %rax
movups (%rax), %xmm0
movups %xmm0, 0x20(%r12)
movq %r15, 0x150(%rsp)
movq 0xb0(%r14), %rsi
movq 0xb8(%r14), %rdx
addq %rsi, %rdx
leaq 0x150(%rsp), %rdi
callq 0x1e014
movl 0xd0(%r14), %eax
movl %eax, 0x170(%rsp)
movq %r14, %rdi
callq 0x2565a
leaq 0xc8(%rsp), %rdi
movq %r14, %rsi
movq 0x58(%rsp), %rdx
callq 0x2c656
cmpq $0x0, 0xc8(%rsp)
je 0x2e841
movl %r13d, %r15d
negl %r15d
cmovsl %r13d, %r15d
movl 0xc(%rsp), %ecx
movl %ecx, %eax
negl %eax
cmovsl %ecx, %eax
cmpl %eax, %r15d
jb 0x2e414
testl %r13d, %r13d
jle 0x2e52d
cmpl %eax, %r15d
jne 0x2e52d
movq $0x0, 0x20(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
movq 0x58(%rsp), %rcx
movq %rbx, %r8
leaq 0x48(%rsp), %r9
leaq 0xf8(%rsp), %rax
pushq %rax
leaq 0xd0(%rsp), %rax
pushq %rax
callq 0x3a9a6
addq $0x10, %rsp
movaps 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x20(%rsp)
movq 0x50(%rsp), %rdi
movups %xmm0, 0x48(%rsp)
testq %rdi, %rdi
leaq 0x80(%rsp), %rbp
je 0x2e480
callq 0x1e6ee
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2e48f
callq 0x1e6ee
movl %r13d, 0xc(%rsp)
movq %rbx, %r15
leaq 0x160(%rsp), %r13
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x2e4b1
callq 0x1e6ee
movq 0x150(%rsp), %rdi
cmpq %r13, %rdi
je 0x2e4ce
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x103d0
movq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rax
cmpq %rax, %rdi
je 0x2e4f3
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x103d0
leaq 0xf8(%rsp), %rdi
callq 0x1d736
movq 0x70(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2e51a
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x103d0
cmpl $0x0, 0xd0(%r14)
jne 0x2e2d7
jmp 0x2e80b
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movq 0x48(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x60(%rsp)
movq %rax, 0x68(%rsp)
testq %rax, %rax
leaq 0x30(%rsp), %r13
je 0x2e56b
movq 0x88a33(%rip), %rcx     # 0xb6f90
cmpb $0x0, (%rcx)
je 0x2e567
incl 0x8(%rax)
jmp 0x2e56b
lock
incl 0x8(%rax)
movq 0x60(%rsp), %rdi
callq 0x59cd8
cmpl $0x4, %eax
jne 0x2e7af
movq 0x60(%rsp), %rbp
movq %rbp, %rdi
callq 0x60646
movq %r13, 0x20(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x20(%rsp), %rdi
callq 0x1e014
leaq 0xb8(%rsp), %rdi
movq %rbp, %rsi
callq 0x60680
leaq 0x8953d(%rip), %rdi     # 0xb7af8
leaq 0x20(%rsp), %rsi
callq 0x374ca
cmpl %r15d, (%rax)
jge 0x2e627
movq 0xb8(%rsp), %rdi
callq 0x59cd8
cmpl $0x4, %eax
jne 0x2e6f2
movq 0x60(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0x68(%rsp), %rbp
movq %rbp, %rsi
callq 0x37c6e
movq 0xb8(%rsp), %rax
movq %rax, 0x60(%rsp)
movq %rbp, %rdi
leaq 0xc0(%rsp), %rsi
callq 0x37c6e
movb $0x1, %bpl
jmp 0x2e77d
leaq 0x894ca(%rip), %rdi     # 0xb7af8
leaq 0x20(%rsp), %rsi
callq 0x374ca
movl (%rax), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl %r15d, %ecx
jne 0x2e660
leaq 0x894ab(%rip), %rdi     # 0xb7af8
leaq 0x20(%rsp), %rsi
callq 0x374ca
cmpl $0x0, (%rax)
js 0x2e5ca
movq 0xa0(%rsp), %rbp
movq $0x0, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0xb(%rsp), %rdx
movq 0x58(%rsp), %rcx
movq %rbx, %r8
leaq 0x60(%rsp), %r9
leaq 0xf8(%rsp), %rax
pushq %rax
leaq 0xd0(%rsp), %rax
pushq %rax
callq 0x3a9a6
addq $0x10, %rsp
movups 0x10(%rsp), %xmm0
movups %xmm0, 0x90(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movq %rbp, %rdi
leaq 0x90(%rsp), %rsi
callq 0x606cc
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x2e6df
callq 0x1e6ee
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x2e77b
jmp 0x2e776
movq $0x0, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0xb(%rsp), %rdx
movq 0x58(%rsp), %rcx
movq %rbx, %r8
leaq 0xb8(%rsp), %r9
leaq 0xf8(%rsp), %rax
pushq %rax
leaq 0xd0(%rsp), %rax
pushq %rax
callq 0x3a9a6
addq $0x10, %rsp
movups 0x10(%rsp), %xmm0
movups %xmm0, 0x90(%rsp)
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rsp)
movq %rbp, %rdi
leaq 0x90(%rsp), %rsi
callq 0x606cc
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x2e76c
callq 0x1e6ee
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x2e77b
callq 0x1e6ee
xorl %ebp, %ebp
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x2e78f
callq 0x1e6ee
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x2e7a6
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x103d0
testb %bpl, %bpl
jne 0x2e56b
movq 0x48(%rsp), %rdi
callq 0x60646
leaq 0x89338(%rip), %rdi     # 0xb7af8
movq %rax, %rsi
callq 0x374ca
movl (%rax), %eax
movl %eax, 0xc(%rsp)
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
leaq 0x80(%rsp), %rbp
leaq 0x160(%rsp), %r13
je 0x2e7ed
callq 0x1e6ee
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
movq %rbx, %r15
je 0x2e49f
callq 0x1e6ee
jmp 0x2e49f
movq 0x48(%rsp), %rcx
movq 0xe0(%rsp), %rax
movq %rcx, (%rax)
xorl %edx, %edx
movq %rdx, 0x8(%rax)
movq 0x50(%rsp), %rcx
movq %rdx, 0x50(%rsp)
movq %rcx, 0x8(%rax)
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
movq %rax, (%rdi)
leaq 0x560e2(%rip), %rsi     # 0x84937
leaq 0x560f9(%rip), %rdx     # 0x84955
callq 0x1e7ca
leaq 0x20(%rsp), %rdx
movq %r14, %rsi
movq 0xd8(%rsp), %rcx
callq 0x29894
jmp 0x2e983
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x2e8a1
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x103d0
jmp 0x2e8a1
jmp 0x2e89e
movq %rax, %rbx
leaq 0x80(%rsp), %r15
jmp 0x2e9e5
jmp 0x2e911
jmp 0x2e8de
movq %rax, %rbx
movq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rax
cmpq %rax, %rdi
je 0x2e8ec
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x103d0
jmp 0x2e8ec
jmp 0x2e906
movq %rax, %rbx
movq %rbp, %r15
jmp 0x2ea04
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x1d736
leaq 0x80(%rsp), %r15
jmp 0x2ea04
movq %rax, %rbx
movq %rbp, %r15
jmp 0x2e9f7
movq %rax, %rbx
jmp 0x2ea1e
jmp 0x2e962
movq %rax, %rbx
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x2e930
callq 0x1e6ee
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x2e965
jmp 0x2e95b
movq %rax, %rbx
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x2e951
callq 0x1e6ee
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x2e965
callq 0x1e6ee
jmp 0x2e965
movq %rax, %rbx
leaq 0x80(%rsp), %r15
leaq 0x30(%rsp), %r13
jmp 0x2e99b
movq %rax, %rbx
leaq 0x80(%rsp), %r15
jmp 0x2e9ad
jmp 0x2e983
movq %rax, %rbx
leaq 0x80(%rsp), %r15
jmp 0x2e9c4
movq %rax, %rbx
leaq 0x80(%rsp), %r15
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x2e9ad
callq 0x1e6ee
movq 0x20(%rsp), %rdi
cmpq %r13, %rdi
je 0x2e9c4
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x103d0
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x2e9d3
callq 0x1e6ee
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x2e9e5
callq 0x1e6ee
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x2e9f7
callq 0x1e6ee
leaq 0xf8(%rsp), %rdi
callq 0x211f6
movq 0x70(%rsp), %rdi
cmpq %r15, %rdi
je 0x2ea1e
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x103d0
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x2ea2d
callq 0x1e6ee
movq %rbx, %rdi
callq 0x106f0
nop