// File: /workspace/github_cpp_makefile_star2_O2/havluj[P]spreadsheet/src/CExpressionParser.cpp
// Function: CExpressionParser::InfixToRPN(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>&)
bool CExpressionParser::InfixToRPN(std::vector<std::string>& inputs) {
    std::list<std::string> infix;
    Tokenize(infix, " ");

    typedef std::list<std::string>::const_iterator tok_iter;
    std::stack<std::string> stack;
    std::queue<std::string> outputQueue;

    bool success = true;

    // For each token
    for (tok_iter it = infix.begin(); it != infix.end(); it++) {
	  // Read a token.
	  std::string token = *it;

	  // If the token is a number, then add it to the output queue.
	  if (IsNumber(token) || IsFloat(token) || IsPi(token) || IsE(token)) {
		outputQueue.push(token);
	  }// If the token is a function token, then push it onto the stack.
	  else if (IsFunction(token)) {
		stack.push(token);
	  } else if (IsComma(token)) {
		// Until token at the top of stack is left parenthesis, pop operators 
		// off the stack onto the output queue.             
		std::string stackToken = stack.top();

		while (stackToken != "(") {
		    outputQueue.push(stackToken);
		    stack.pop();
		    stackToken = stack.top();
		}

		if (stackToken == "(") {
		    success = true;
		} else {
		    success = false;
		}
	  }// If the token (o1) is an operator, then:
	  else if (IsOperator(token)) {
		// While there is operator token, o2, at the top of the stack, and:
		// either o1 is left-associative and its precedence is equal to that of o2,
		// or o1 has precedence less than that of o2
		while (!stack.empty() && IsOperator(stack.top()) &&
			  ((OpLeftAssoc(token) && OpPrecedence(token) == OpPrecedence(stack.top())) ||
			  (OpPrecedence(token) < OpPrecedence(stack.top())))) {
		    // Pop o2 off the stack, onto the output queue
		    std::string stackToken = stack.top();
		    stack.pop();
		    outputQueue.push(stackToken);
		}

		// Push o1 onto the stack
		stack.push(token);

	  }// If the token is a left parenthesis, then push it onto the stack.
	  else if (token == "(") {
		// Push token to top of the stack  
		stack.push(token);
	  }// If the token is a right parenthesis:
	  else if (token == ")") {
		// Until the token at the top of the stack is a left parenthesis, pop operators 
		// off the stack onto the output queue.
		while (!stack.empty() && stack.top() != "(") {
		    // Add to end of list  
		    outputQueue.push(stack.top());
		    stack.pop();
		}

		// If stack runs out without finding a left parenthesis, 
		// there are mismatched parentheses
		if (!stack.empty()) {
		    std::string stackToken = stack.top();

		    // Mismatched parentheses
		    if (stackToken != "(") {
			  success = false;
		    }
		} else {
		    return false;
		}

		// Pop left parenthesis from the stack, but not onto output queue.
		stack.pop();

		// If token at top of stack is function token, pop it onto output queue
		if (!stack.empty()) {
		    std::string stackToken = stack.top();
		    if (IsFunction(stackToken)) {
			  outputQueue.push(stackToken);
			  stack.pop();
		    }
		}
	  }
    }

    // While there are still operator tokens in the stack:
    while (!stack.empty()) {
	  // Pop the operator onto the output queue
	  outputQueue.push(stack.top());
	  stack.pop();
    }

    while (!outputQueue.empty()) {
	  std::string token = outputQueue.front();
	  inputs.push_back(token);
	  outputQueue.pop();
    }

    return success;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, %rbx
movq %rdi, %r15
leaq 0x60(%rsp), %rax
movq %rax, 0x8(%rax)
movq %rax, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x2970(%rip), %rsi      # 0xd853
leaq 0x10(%rsp), %rdi
leaq 0xb8(%rsp), %rdx
callq 0x5138
leaq 0x60(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %r15, %rdi
callq 0x9ddc
leaq 0x10(%rsp), %rdi
callq 0x4150
leaq 0x10(%rsp), %rdi
callq 0xb5e6
leaq 0xb8(%rsp), %r12
movq %r12, %rdi
callq 0xb624
movb $0x1, %al
movl %eax, 0xc(%rsp)
leaq 0x98(%rsp), %r13
leaq 0x78(%rsp), %rbp
leaq 0x60(%rsp), %r14
movq (%r14), %r14
leaq 0x60(%rsp), %rax
cmpq %rax, %r14
je 0xb360
leaq 0x10(%r14), %rsi
movq %r13, %rdi
callq 0x4440
movq %r13, %rdi
callq 0x9c9f
movq %r12, %rdi
testb %al, %al
jne 0xafad
movq %r13, %rdi
callq 0x9c2a
movq %r12, %rdi
testb %al, %al
jne 0xafad
movq %r13, %rdi
callq 0x9a55
movq %r12, %rdi
testb %al, %al
jne 0xafad
movq %r13, %rdi
callq 0x9aa7
movq %r12, %rdi
testb %al, %al
jne 0xafad
movq %r13, %rdi
callq 0x9af9
leaq 0x10(%rsp), %rdi
testb %al, %al
je 0xafce
movb $0x1, %r15b
movq %r13, %rsi
callq 0xbb84
movq %r13, %rdi
callq 0x4150
testb %r15b, %r15b
jne 0xaf43
jmp 0xb31b
movq %r13, %rdi
callq 0x9a07
testb %al, %al
je 0xb061
movq 0x40(%rsp), %rsi
cmpq 0x48(%rsp), %rsi
jne 0xaffb
movq 0x58(%rsp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
movq %rbp, %rdi
callq 0x4440
leaq 0x10(%rsp), %r15
movq %rbp, %rdi
leaq 0x1fee(%rip), %rsi      # 0xd004
callq 0xb63f
testb %al, %al
je 0xb179
movq %r12, %rdi
movq %rbp, %rsi
callq 0xbb84
movq %r15, %rdi
callq 0xbe2e
movq 0x40(%rsp), %rsi
cmpq 0x48(%rsp), %rsi
jne 0xb053
movq 0x58(%rsp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
movq %rbp, %rdi
callq 0x41b0
jmp 0xb00c
movq %r13, %rdi
callq 0x9980
testb %al, %al
je 0xb19c
leaq 0x10(%rsp), %r15
movq 0x40(%rsp), %rdi
cmpq 0x20(%rsp), %rdi
je 0xb243
cmpq 0x48(%rsp), %rdi
jne 0xb09e
movq 0x58(%rsp), %rax
movq -0x8(%rax), %rdi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rdi
addq $-0x20, %rdi
callq 0x9980
testb %al, %al
je 0xb243
movq %r13, %rdi
callq 0x98ee
testb %al, %al
je 0xb0f1
movq %r13, %rdi
callq 0x984f
movl %eax, %r15d
movq 0x40(%rsp), %rdi
cmpq 0x48(%rsp), %rdi
jne 0xb0e3
movq 0x58(%rsp), %rax
movq -0x8(%rax), %rdi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rdi
addq $-0x20, %rdi
callq 0x984f
cmpl %eax, %r15d
je 0xb12b
movq %r13, %rdi
callq 0x984f
movl %eax, %r15d
movq 0x40(%rsp), %rdi
cmpq 0x48(%rsp), %rdi
jne 0xb119
movq 0x58(%rsp), %rax
movq -0x8(%rax), %rdi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rdi
addq $-0x20, %rdi
callq 0x984f
cmpl %eax, %r15d
jae 0xb24b
movq 0x40(%rsp), %rsi
cmpq 0x48(%rsp), %rsi
jne 0xb148
movq 0x58(%rsp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
movq %rbp, %rdi
callq 0x4440
leaq 0x10(%rsp), %r15
movq %r15, %rdi
callq 0xbe2e
movq %r12, %rdi
movq %rbp, %rsi
callq 0xbb84
movq %rbp, %rdi
callq 0x4150
jmp 0xb076
movq %rbp, %rdi
leaq 0x1e81(%rip), %rsi      # 0xd004
callq 0xb473
movl %eax, 0xc(%rsp)
movq %rbp, %rdi
callq 0x4150
movb $0x1, %r15b
jmp 0xafb8
movq %r13, %rdi
leaq 0x1e5e(%rip), %rsi      # 0xd004
callq 0xb473
leaq 0x10(%rsp), %rdi
testb %al, %al
jne 0xafad
movq %r13, %rdi
leaq 0x2764(%rip), %rsi      # 0xd926
callq 0xb473
movb $0x1, %r15b
testb %al, %al
je 0xafb8
movq 0x40(%rsp), %rdi
cmpq 0x20(%rsp), %rdi
je 0xb313
cmpq 0x48(%rsp), %rdi
jne 0xb1fa
movq 0x58(%rsp), %rax
movq -0x8(%rax), %rdi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rdi
addq $-0x20, %rdi
leaq 0x1dff(%rip), %rsi      # 0xd004
callq 0xb63f
movq 0x40(%rsp), %rsi
testb %al, %al
je 0xb255
cmpq 0x48(%rsp), %rsi
jne 0xb22b
movq 0x58(%rsp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
movq %r12, %rdi
callq 0xbb84
leaq 0x10(%rsp), %rdi
callq 0xbe2e
jmp 0xb1d2
movq %r15, %rdi
jmp 0xafad
leaq 0x10(%rsp), %rdi
jmp 0xafad
cmpq 0x20(%rsp), %rsi
je 0xb313
cmpq 0x48(%rsp), %rsi
jne 0xb278
movq 0x58(%rsp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
movq %rbp, %rdi
callq 0x4440
movq %rbp, %rdi
leaq 0x1d76(%rip), %rsi      # 0xd004
callq 0xb63f
xorb $0x1, %al
movl 0xc(%rsp), %ecx
andb %al, %cl
movl %ecx, 0xc(%rsp)
movq %rbp, %rdi
callq 0x4150
leaq 0x10(%rsp), %rdi
callq 0xbe2e
movq 0x40(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0xafb8
cmpq 0x48(%rsp), %rsi
jne 0xb2d9
movq 0x58(%rsp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
movq %rbp, %rdi
callq 0x4440
movq %rbp, %rdi
callq 0x9af9
testb %al, %al
je 0xb306
movq %r12, %rdi
movq %rbp, %rsi
callq 0xbb84
leaq 0x10(%rsp), %rdi
callq 0xbe2e
movq %rbp, %rdi
callq 0x4150
jmp 0xafb8
xorl %r15d, %r15d
jmp 0xafb8
leaq 0x60(%rsp), %rax
cmpq %rax, %r14
je 0xb360
xorl %ebp, %ebp
leaq 0xb8(%rsp), %rdi
callq 0xb6a2
leaq 0x10(%rsp), %rdi
callq 0xb6a2
leaq 0x60(%rsp), %rdi
callq 0xb7ce
andb $0x1, %bpl
movl %ebp, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x200, %r12d           # imm = 0x200
leaq 0xb8(%rsp), %r14
leaq 0x10(%rsp), %r15
movq 0x40(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0xb3a8
cmpq 0x48(%rsp), %rsi
jne 0xb392
movq 0x58(%rsp), %rax
movq -0x8(%rax), %rsi
addq %r12, %rsi
addq $-0x20, %rsi
movq %r14, %rdi
callq 0xbb84
movq %r15, %rdi
callq 0xbe2e
jmp 0xb373
leaq 0x98(%rsp), %r14
leaq 0xb8(%rsp), %r15
movl 0xc(%rsp), %ebp
movq 0xc8(%rsp), %rsi
cmpq %rsi, 0xe8(%rsp)
je 0xb327
movq %r14, %rdi
callq 0x4440
movq %rbx, %rdi
movq %r14, %rsi
callq 0xb64a
movq %r15, %rdi
callq 0xc248
movq %r14, %rdi
callq 0x4150
jmp 0xb3bc
jmp 0xb43a
jmp 0xb420
jmp 0xb43a
jmp 0xb43a
jmp 0xb43a
movq %rax, %rbx
jmp 0xb457
jmp 0xb417
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4150
jmp 0xb461
movq %rax, %rbx
jmp 0xb461
jmp 0xb420
jmp 0xb43a
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x4150
jmp 0xb43d
jmp 0xb435
jmp 0xb435
jmp 0xb43a
movq %rax, %rbx
jmp 0xb44a
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x4150
leaq 0xb8(%rsp), %rdi
callq 0xb6a2
leaq 0x10(%rsp), %rdi
callq 0xb6a2
leaq 0x60(%rsp), %rdi
callq 0xb7ce
movq %rbx, %rdi
callq 0x4590