// File: /workspace/github_cpp_makefile_star2_O2/mbottini[P]CS250lab2/main.cpp
// Function: convertRPN(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>>>> const&)
stringVector convertRPN(const stringVector& tokenVector) {
    stringVector RPNVector;
    std::stack<string> operatorStack;
    int precedence;

    for(stringIter i = tokenVector.begin(); i != tokenVector.end(); ++i) {
        if(isVariable(*i)) {
            RPNVector.push_back(*i);
        }

        else if(isOperator(*i)) {
            precedence = getPrecedence(*i);

            if(precedence == -1) {
                std::cout << "Invalid operator plugged into "
                << "precedence function!\n";
                RPNVector.clear();
                return RPNVector;
            }

            while(!(operatorStack.empty()) && 
                    precedence <= getPrecedence(operatorStack.top())) {
                RPNVector.push_back(operatorStack.top());
                operatorStack.pop();
            }

            operatorStack.push(*i);
        }

        else if(isLeftParen(*i)) {
            operatorStack.push(*i);
        }

        else if(isRightParen(*i)) {
            if(operatorStack.empty()) {
                std::cout << "Parentheses mismatch!\n";
                RPNVector.clear();
                return RPNVector;
            }

            while(operatorStack.top() != "(") {
                if(operatorStack.empty()) {
                    std::cout << "Parentheses mismatch!\n";
                    RPNVector.clear();
                    return RPNVector;
                }

                RPNVector.push_back(operatorStack.top());
                operatorStack.pop();
            }

            operatorStack.pop();
        }
    }

    while(!(operatorStack.empty())) {
        RPNVector.push_back(operatorStack.top());
        operatorStack.pop();
    }

    return RPNVector;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %r12
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
leaq -0x80(%rbp), %rdi
callq 0x39c4
movq (%r12), %r13
movl $0x200, %r15d           # imm = 0x200
leaq -0x80(%rbp), %r14
movq %r12, -0x30(%rbp)
cmpq 0x8(%r12), %r13
je 0x2e9b
movq %r13, %rdi
callq 0x340f
testb %al, %al
je 0x2d71
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3966
jmp 0x2e88
movq %r13, %rdi
callq 0x343e
testb %al, %al
je 0x2ded
movq %r13, %rdi
callq 0x3590
movl %eax, %r12d
cmpl $-0x1, %eax
je 0x2ee6
movq -0x50(%rbp), %rdi
cmpq -0x70(%rbp), %rdi
je 0x2e79
cmpq -0x48(%rbp), %rdi
jne 0x2db0
movq -0x38(%rbp), %rax
movq -0x8(%rax), %rdi
addq %r15, %rdi
addq $-0x20, %rdi
callq 0x3590
cmpl %eax, %r12d
jg 0x2e79
movq -0x50(%rbp), %rsi
cmpq -0x48(%rbp), %rsi
jne 0x2dd7
movq -0x38(%rbp), %rax
movq -0x8(%rax), %rsi
addq %r15, %rsi
addq $-0x20, %rsi
movq %rbx, %rdi
callq 0x3966
movq %r14, %rdi
callq 0x4798
jmp 0x2d91
cmpq $0x1, 0x8(%r13)
jne 0x2e88
movq (%r13), %rax
movzbl (%rax), %eax
cmpl $0x28, %eax
je 0x2e79
cmpl $0x29, %eax
movq -0x30(%rbp), %r12
jne 0x2e88
movq -0x50(%rbp), %rdi
cmpq -0x70(%rbp), %rdi
je 0x2ed6
cmpq -0x48(%rbp), %rdi
jne 0x2e2c
movq -0x38(%rbp), %rax
movq -0x8(%rax), %rdi
addq %r15, %rdi
addq $-0x20, %rdi
leaq 0x32bf(%rip), %rsi      # 0x60f6
callq 0x39f1
testb %al, %al
je 0x2e91
movq -0x50(%rbp), %rsi
cmpq -0x70(%rbp), %rsi
je 0x2ed6
cmpq -0x48(%rbp), %rsi
jne 0x2e5f
movq -0x38(%rbp), %rax
movq -0x8(%rax), %rsi
addq %r15, %rsi
addq $-0x20, %rsi
movq %rbx, %rdi
callq 0x3966
movq %r14, %rdi
callq 0x4798
movq -0x50(%rbp), %rdi
jmp 0x2e1b
movq %r14, %rdi
movq %r13, %rsi
callq 0x4806
movq -0x30(%rbp), %r12
addq $0x20, %r13
jmp 0x2d4a
movq %r14, %rdi
callq 0x4798
jmp 0x2e88
movl $0x200, %r15d           # imm = 0x200
leaq -0x80(%rbp), %r14
movq -0x50(%rbp), %rsi
cmpq -0x70(%rbp), %rsi
je 0x2f10
cmpq -0x48(%rbp), %rsi
jne 0x2ec0
movq -0x38(%rbp), %rax
movq -0x8(%rax), %rsi
addq %r15, %rsi
addq $-0x20, %rsi
movq %rbx, %rdi
callq 0x3966
movq %r14, %rdi
callq 0x4798
jmp 0x2ea5
movq 0x60f3(%rip), %rdi      # 0x8fd0
leaq 0x31fb(%rip), %rsi      # 0x60df
jmp 0x2f03
movq 0x60e3(%rip), %rdi      # 0x8fd0
leaq 0x31b6(%rip), %rsi      # 0x60aa
callq 0x2160
movq %rax, %rdi
leaq 0x31c6(%rip), %rsi      # 0x60c9
callq 0x2160
movq %rbx, %rdi
callq 0x39e4
leaq -0x80(%rbp), %rdi
callq 0x3b92
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x2f38
movq %rax, %r14
jmp 0x2f44
jmp 0x2f38
jmp 0x2f38
jmp 0x2f38
movq %rax, %r14
leaq -0x80(%rbp), %rdi
callq 0x3b92
movq %rbx, %rdi
callq 0x3870
movq %r14, %rdi
callq 0x2240