// File: /workspace/github_cpp_makefile_star2_O3/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, 0x78(%rsp)
movq %rsi, %rbx
movq %rdi, 0xe0(%rsp)
movq (%rcx), %rax
movq %rax, 0x60(%rsp)
movq 0x8(%rcx), %rax
movq %rax, 0x68(%rsp)
testq %rax, %rax
je 0x2ded2
movq 0x870cc(%rip), %rcx     # 0xb4f90
cmpb $0x0, (%rcx)
je 0x2dece
incl 0x8(%rax)
jmp 0x2ded2
lock
incl 0x8(%rax)
cmpl $0x0, 0xd0(%rbx)
je 0x2e44e
leaq 0x58(%rbx), %rax
movq %rax, 0xd8(%rsp)
leaq 0xb0(%rbx), %rax
movq %rax, 0xf0(%rsp)
leaq 0xa0(%rbx), %rax
movq %rax, 0xe8(%rsp)
leaq 0x160(%rsp), %r12
movl $0x3e7, %ebp            # imm = 0x3E7
leaq 0x40(%rsp), %r13
leaq 0x87bd6(%rip), %rdi     # 0xb5af8
movq 0xf0(%rsp), %rsi
callq 0x241f8
leaq 0x87bca(%rip), %rcx     # 0xb5b00
cmpq %rcx, %rax
je 0x2e44e
leaq 0x50(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xb0(%rbx), %rsi
movq 0xb8(%rbx), %rdx
addq %rsi, %rdx
movq %r13, %rdi
callq 0x1ded4
leaq 0x87b8f(%rip), %rdi     # 0xb5af8
movq %r13, %r14
movq %r13, %rsi
callq 0x36fba
movq %r12, %r13
movl (%rax), %r15d
leaq 0xf8(%rsp), %rdi
movq 0xd8(%rsp), %rsi
callq 0x1e566
leaq 0x130(%rsp), %rax
movq %rax, 0x120(%rsp)
movq 0x80(%rbx), %rsi
movq 0x88(%rbx), %rdx
addq %rsi, %rdx
leaq 0x120(%rsp), %r12
movq %r12, %rdi
callq 0x1ded4
movq 0xe8(%rsp), %rax
movups (%rax), %xmm0
movups %xmm0, 0x20(%r12)
movq %r13, %r12
movq %r13, 0x150(%rsp)
movq 0xb0(%rbx), %rsi
movq 0xb8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x150(%rsp), %rdi
callq 0x1ded4
movl 0xd0(%rbx), %eax
movl %eax, 0x170(%rsp)
movq %rbx, %rdi
callq 0x2549e
leaq 0xc8(%rsp), %rdi
movq %rbx, %rsi
movq 0x78(%rsp), %rdx
callq 0x2c34e
cmpq $0x0, 0xc8(%rsp)
je 0x2e470
movl %r15d, %r13d
negl %r13d
cmovsl %r15d, %r13d
movl %ebp, %eax
negl %eax
cmovsl %ebp, %eax
cmpl %eax, %r13d
jb 0x2e05b
testl %r15d, %r15d
jle 0x2e163
cmpl %eax, %r13d
jne 0x2e163
movq $0x0, 0x20(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rsi
leaq 0xa0(%rsp), %rdx
movq 0x78(%rsp), %rcx
movq %r14, %r8
leaq 0x60(%rsp), %r9
leaq 0xf8(%rsp), %rax
pushq %rax
leaq 0xd0(%rsp), %rax
pushq %rax
callq 0x3a3fa
addq $0x10, %rsp
movaps 0x20(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x20(%rsp)
movq 0x68(%rsp), %rdi
movaps %xmm0, 0x60(%rsp)
testq %rdi, %rdi
leaq 0x50(%rsp), %rbp
je 0x2e0d3
callq 0x1e5bc
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2e0d3
callq 0x1e5bc
movq %r14, %r13
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x2e0e8
callq 0x1e5bc
movq 0x150(%rsp), %rdi
cmpq %r12, %rdi
je 0x2e105
movq 0x160(%rsp), %rsi
incq %rsi
callq 0x103d0
movq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rax
cmpq %rax, %rdi
je 0x2e12a
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x103d0
leaq 0xf8(%rsp), %rdi
callq 0x1d5ee
movq 0x40(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2e14e
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x103d0
cmpl $0x0, 0xd0(%rbx)
movl %r15d, %ebp
jne 0x2df1b
jmp 0x2e44e
xorps %xmm0, %xmm0
movaps %xmm0, 0xa0(%rsp)
movq 0x60(%rsp), %rcx
movq 0x68(%rsp), %rax
movq %rcx, 0x80(%rsp)
movq %rax, 0x88(%rsp)
testq %rax, %rax
leaq 0x30(%rsp), %r15
je 0x2e1a7
movq 0x86df7(%rip), %rcx     # 0xb4f90
cmpb $0x0, (%rcx)
je 0x2e1a3
incl 0x8(%rax)
jmp 0x2e1a7
lock
incl 0x8(%rax)
movq 0x80(%rsp), %rdi
callq 0x59438
cmpl $0x4, %eax
jne 0x2e3fd
movq 0x80(%rsp), %rbp
movq %rbp, %rdi
callq 0x5fb1c
movq %r15, 0x20(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x20(%rsp), %rdi
callq 0x1ded4
leaq 0xb8(%rsp), %rdi
movq %rbp, %rsi
callq 0x5fb56
leaq 0x878fb(%rip), %rdi     # 0xb5af8
leaq 0x20(%rsp), %rsi
callq 0x36fba
cmpl %r13d, (%rax)
jge 0x2e272
movq 0xb8(%rsp), %rdi
callq 0x59438
cmpl $0x4, %eax
jne 0x2e340
movq 0x80(%rsp), %rax
movq %rax, 0xa0(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0x88(%rsp), %rbp
movq %rbp, %rsi
callq 0x3775e
movq 0xb8(%rsp), %rax
movq %rax, 0x80(%rsp)
movq %rbp, %rdi
leaq 0xc0(%rsp), %rsi
callq 0x3775e
movb $0x1, %bpl
jmp 0x2e3cb
leaq 0x8787f(%rip), %rdi     # 0xb5af8
leaq 0x20(%rsp), %rsi
callq 0x36fba
movl (%rax), %eax
movl %eax, %ecx
negl %ecx
cmovsl %eax, %ecx
cmpl %r13d, %ecx
jne 0x2e2ab
leaq 0x87860(%rip), %rdi     # 0xb5af8
leaq 0x20(%rsp), %rsi
callq 0x36fba
cmpl $0x0, (%rax)
js 0x2e20c
movq 0xa0(%rsp), %rbp
movq $0x0, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0xf(%rsp), %rdx
movq 0x78(%rsp), %rcx
movq %r14, %r8
leaq 0x80(%rsp), %r9
leaq 0xf8(%rsp), %rax
pushq %rax
leaq 0xd0(%rsp), %rax
pushq %rax
callq 0x3a3fa
addq $0x10, %rsp
movaps 0x10(%rsp), %xmm0
movaps %xmm0, 0x90(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq %rbp, %rdi
leaq 0x90(%rsp), %rsi
callq 0x5fba2
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x2e32d
callq 0x1e5bc
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x2e3c9
jmp 0x2e3c4
movq $0x0, 0x10(%rsp)
leaq 0x18(%rsp), %rdi
leaq 0x10(%rsp), %rsi
leaq 0xf(%rsp), %rdx
movq 0x78(%rsp), %rcx
movq %r14, %r8
leaq 0xb8(%rsp), %r9
leaq 0xf8(%rsp), %rax
pushq %rax
leaq 0xd0(%rsp), %rax
pushq %rax
callq 0x3a3fa
addq $0x10, %rsp
movaps 0x10(%rsp), %xmm0
movaps %xmm0, 0x90(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq %rbp, %rdi
leaq 0x90(%rsp), %rsi
callq 0x5fba2
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x2e3ba
callq 0x1e5bc
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x2e3c9
callq 0x1e5bc
xorl %ebp, %ebp
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x2e3dd
callq 0x1e5bc
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x2e3f4
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x103d0
testb %bpl, %bpl
jne 0x2e1a7
movq 0x60(%rsp), %rdi
callq 0x5fb1c
leaq 0x876ea(%rip), %rdi     # 0xb5af8
movq %rax, %rsi
callq 0x36fba
movl (%rax), %r15d
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
leaq 0x50(%rsp), %rbp
je 0x2e430
callq 0x1e5bc
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
movq %r14, %r13
je 0x2e0d6
callq 0x1e5bc
jmp 0x2e0d6
movaps 0x60(%rsp), %xmm0
movq 0xe0(%rsp), %rax
movups %xmm0, (%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 0x554d3(%rip), %rsi     # 0x83957
leaq 0x554ea(%rip), %rdx     # 0x83975
callq 0x1e698
leaq 0x20(%rsp), %rdx
movq %rbx, %rsi
movq 0xd8(%rsp), %rcx
callq 0x29658
jmp 0x2e5a2
movq %rax, %rbx
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x2e4d0
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x103d0
jmp 0x2e4d0
jmp 0x2e4cd
movq %rax, %rbx
leaq 0x50(%rsp), %r13
jmp 0x2e601
jmp 0x2e536
jmp 0x2e50a
movq %rax, %rbx
movq 0x120(%rsp), %rdi
leaq 0x130(%rsp), %rax
cmpq %rax, %rdi
je 0x2e512
movq 0x130(%rsp), %rsi
incq %rsi
callq 0x103d0
jmp 0x2e512
jmp 0x2e529
movq %rax, %rbx
jmp 0x2e51f
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0x1d5ee
leaq 0x50(%rsp), %r13
jmp 0x2e620
movq %rax, %rbx
leaq 0x50(%rsp), %r13
jmp 0x2e613
movq %rax, %rbx
jmp 0x2e637
jmp 0x2e587
movq %rax, %rbx
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x2e555
callq 0x1e5bc
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x2e58a
jmp 0x2e580
movq %rax, %rbx
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x2e576
callq 0x1e5bc
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x2e58a
callq 0x1e5bc
jmp 0x2e58a
movq %rax, %rbx
leaq 0x50(%rsp), %r13
leaq 0x30(%rsp), %r15
jmp 0x2e5b4
movq %rax, %rbx
leaq 0x50(%rsp), %r13
jmp 0x2e5c6
jmp 0x2e5a2
movq %rax, %rbx
leaq 0x50(%rsp), %r13
jmp 0x2e5dd
movq %rax, %rbx
leaq 0x50(%rsp), %r13
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x2e5c6
callq 0x1e5bc
movq 0x20(%rsp), %rdi
cmpq %r15, %rdi
je 0x2e5dd
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x103d0
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x2e5ef
callq 0x1e5bc
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x2e601
callq 0x1e5bc
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x2e613
callq 0x1e5bc
leaq 0xf8(%rsp), %rdi
callq 0x2108a
movq 0x40(%rsp), %rdi
cmpq %r13, %rdi
je 0x2e637
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x103d0
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x2e646
callq 0x1e5bc
movq %rbx, %rdi
callq 0x106f0