// File: menhits[P]phplus/src/Parser.cpp
// Function: findExpressionSplit(std::vector<std::shared_ptr<TokenData>, std::allocator<std::shared_ptr<TokenData>>> const&, int, int)
int findExpressionSplit(const vector<Token>& tokens, int left, int right)
{
	int minPrece=-1;
	int indexOfMin=-1;
	
	for (int i=left; i<=right; i++)
	{
		//cout << "looking at " << tokens[i]->getText() << endl;
		/*if (tokens[i]->getOp())
		{
			//cout << "precedence: " << tokens[i]->getOp()->getPrecedence()
		}
		*/
		
		if (ops->isOpenBrac(tokens[i]->getOp()))
		{
			int j=skipBrace(tokens, i);
			
			i=j; // i is now the close brace, and after it is incremented it will be the token after that
		}
		else if (tokens[i]->getOp() && (minPrece<0 || tokens[i]->getOp()->getPrecedence()<minPrece))
		{
			minPrece=tokens[i]->getOp()->getPrecedence();
			indexOfMin=i;
			
			// this ensures that if the precedence is divisable by 2, the same precedence again will replace this one as the min
			// it is my way of making even precedences be right associative and odd ones be left associative
			if (minPrece%2)
			{
				minPrece++;
			}
		}
	}
	
	if (indexOfMin<0)
	{
		throw PhplusError(FUNC+" could not find operator to split expression", INTERNAL_ERROR, tokens[left]);
	}
	
	return indexOfMin;
}

// Assembly:
subq $0x118, %rsp            # imm = 0x118
movq %rdi, 0x110(%rsp)
movl %esi, 0x10c(%rsp)
movl %edx, 0x108(%rsp)
movl $0xffffffff, 0x104(%rsp) # imm = 0xFFFFFFFF
movl $0xffffffff, 0x100(%rsp) # imm = 0xFFFFFFFF
movl 0x10c(%rsp), %eax
movl %eax, 0xfc(%rsp)
movl 0xfc(%rsp), %eax
cmpl 0x108(%rsp), %eax
jg 0x44252
leaq 0xd445c(%rip), %rax     # 0x1183b8
movq (%rax), %rax
movq %rax, 0x30(%rsp)
movq 0x110(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0x48650
movq %rax, %rdi
callq 0x1bb70
movq %rax, %rsi
leaq 0xe8(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x1bc10
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0xf780
movb %al, 0x46(%rsp)
jmp 0x43fab
leaq 0xe8(%rsp), %rdi
callq 0xf9a0
movb 0x46(%rsp), %al
testb $0x1, %al
jne 0x43fc2
jmp 0x44016
movq 0x110(%rsp), %rdi
movl 0xfc(%rsp), %esi
callq 0x43610
movl %eax, 0xd8(%rsp)
movl 0xd8(%rsp), %eax
movl %eax, 0xfc(%rsp)
jmp 0x4423a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
leaq 0xe8(%rsp), %rdi
callq 0xf9a0
jmp 0x443aa
movq 0x110(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0x48650
movq %rax, %rdi
callq 0x1bb70
movq %rax, %rsi
leaq 0xc8(%rsp), %rdi
callq 0x1bc10
leaq 0xc8(%rsp), %rdi
callq 0x1bef0
movb %al, %cl
movb $0x0, 0xb7(%rsp)
xorl %eax, %eax
testb $0x1, %cl
movb %al, 0x2f(%rsp)
jne 0x44067
jmp 0x440e3
movb $0x1, %al
cmpl $0x0, 0x104(%rsp)
movb %al, 0x2e(%rsp)
jl 0x440db
movq 0x110(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0x48650
movq %rax, %rdi
callq 0x1bb70
movq %rax, %rsi
leaq 0xb8(%rsp), %rdi
callq 0x1bc10
jmp 0x440a6
movb $0x1, 0xb7(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0xf9f0
movq %rax, %rdi
callq 0x48670
movl %eax, 0x28(%rsp)
jmp 0x440c9
movl 0x28(%rsp), %eax
cmpl 0x104(%rsp), %eax
setl %al
movb %al, 0x2e(%rsp)
movb 0x2e(%rsp), %al
movb %al, 0x2f(%rsp)
movb 0x2f(%rsp), %al
movb %al, 0x27(%rsp)
testb $0x1, 0xb7(%rsp)
jne 0x440f7
jmp 0x44104
leaq 0xb8(%rsp), %rdi
callq 0xf9a0
leaq 0xc8(%rsp), %rdi
callq 0xf9a0
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0x4411e
jmp 0x44238
movq 0x110(%rsp), %rdi
movslq 0xfc(%rsp), %rsi
callq 0x48650
movq %rax, %rdi
callq 0x1bb70
movq %rax, %rsi
leaq 0xa0(%rsp), %rdi
movq %rdi, 0x18(%rsp)
callq 0x1bc10
movq 0x18(%rsp), %rdi
callq 0xf9f0
movq %rax, %rdi
callq 0x48670
movl %eax, 0x20(%rsp)
jmp 0x44168
movl 0x20(%rsp), %eax
movl %eax, 0x104(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0xf9a0
movl 0xfc(%rsp), %eax
movl %eax, 0x100(%rsp)
movl 0x104(%rsp), %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x44236
movl 0x104(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x104(%rsp)
jmp 0x44236
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
jmp 0x441fe
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
testb $0x1, 0xb7(%rsp)
jne 0x441ef
jmp 0x441fc
leaq 0xb8(%rsp), %rdi
callq 0xf9a0
jmp 0x441fe
leaq 0xc8(%rsp), %rdi
callq 0xf9a0
jmp 0x443aa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0xf9a0
jmp 0x443aa
jmp 0x44238
jmp 0x4423a
jmp 0x4423c
movl 0xfc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xfc(%rsp)
jmp 0x43f41
cmpl $0x0, 0x100(%rsp)
jge 0x4439b
movb $0x1, 0x47(%rsp)
movl $0x38, %edi
callq 0xb1f0
movq %rax, 0x8(%rsp)
leaq 0x5f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0xb690
movq 0x10(%rsp), %rdx
leaq 0x8e283(%rip), %rsi     # 0xd2512
leaq 0x60(%rsp), %rdi
callq 0xb4c0
jmp 0x4429b
leaq 0x8e284(%rip), %rdx     # 0xd2526
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0xfa60
jmp 0x442b6
movq 0x110(%rsp), %rdi
movslq 0x10c(%rsp), %rsi
callq 0x48650
movq %rax, %rsi
leaq 0x48(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x1bc90
movq 0x8(%rsp), %rdi
movq (%rsp), %rcx
leaq 0x80(%rsp), %rsi
movl $0x3, %edx
callq 0x35600
jmp 0x442f9
movq 0x8(%rsp), %rdi
movb $0x0, 0x47(%rsp)
leaq 0xd12be(%rip), %rsi     # 0x1155c8
leaq -0x29ca1(%rip), %rdx    # 0x1a670
callq 0xb640
jmp 0x443b7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
jmp 0x4437c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
jmp 0x44372
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xe0(%rsp)
movl %eax, 0xdc(%rsp)
leaq 0x48(%rsp), %rdi
callq 0xfc00
leaq 0x80(%rsp), %rdi
callq 0xb6e8
leaq 0x60(%rsp), %rdi
callq 0xb6e8
leaq 0x5f(%rsp), %rdi
callq 0xb3f0
testb $0x1, 0x47(%rsp)
jne 0x4438f
jmp 0x44399
movq 0x8(%rsp), %rdi
callq 0xb2d0
jmp 0x443aa
movl 0x100(%rsp), %eax
addq $0x118, %rsp            # imm = 0x118
retq
movq 0xe0(%rsp), %rdi
callq 0xb680
nopw (%rax,%rax)