// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %rsi, %r14
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
leaq -0x80(%rbp), %rdi
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
xorl %esi, %esi
callq 0x4ee4
movq (%r14), %r12
movq %r14, -0x88(%rbp)
cmpq 0x8(%r14), %r12
je 0x3347
movl $0x200, %r14d           # imm = 0x200
leaq -0x80(%rbp), %r13
cmpq $0x1, 0x8(%r12)
jne 0x3210
movq (%r12), %rax
movsbl (%rax), %r15d
movl %r15d, %edi
callq 0x21f0
cmpl $0x76, %r15d
je 0x3210
testl %eax, %eax
je 0x3210
movq %rbx, %rdi
movq %r12, %rsi
callq 0x40d6
jmp 0x32a3
movq %r12, %rdi
callq 0x3a52
testb %al, %al
je 0x3284
movq %r12, %rdi
callq 0x3c4e
cmpl $-0x1, %eax
je 0x3399
movl %eax, %r15d
movq -0x50(%rbp), %rdi
cmpq -0x70(%rbp), %rdi
je 0x3298
cmpq -0x48(%rbp), %rdi
jne 0x324b
movq -0x38(%rbp), %rax
movq -0x8(%rax), %rdi
addq %r14, %rdi
addq $-0x20, %rdi
callq 0x3c4e
cmpl %eax, %r15d
jg 0x3298
movq -0x50(%rbp), %rsi
cmpq -0x48(%rbp), %rsi
jne 0x326e
movq -0x38(%rbp), %rax
movq -0x8(%rax), %rsi
addq %r14, %rsi
addq $-0x20, %rsi
movq %rbx, %rdi
callq 0x40d6
movq %r13, %rdi
callq 0x5062
jmp 0x3230
movq 0x8(%r12), %rax
cmpq $0x1, %rax
jne 0x32a3
movq (%r12), %rcx
cmpb $0x28, (%rcx)
jne 0x32bd
movq %r13, %rdi
movq %r12, %rsi
callq 0x50f0
addq $0x20, %r12
movq -0x88(%rbp), %rax
cmpq 0x8(%rax), %r12
jne 0x31de
jmp 0x3347
cmpq $0x1, %rax
jne 0x32a3
movq (%r12), %rax
cmpb $0x29, (%rax)
jne 0x32a3
movq -0x50(%rbp), %rax
movl $0x16, %r15d
cmpq -0x70(%rbp), %rax
je 0x3390
movq -0x50(%rbp), %rdi
cmpq -0x48(%rbp), %rdi
jne 0x32f5
movq -0x38(%rbp), %rax
movq -0x8(%rax), %rdi
addq %r14, %rdi
addq $-0x20, %rdi
leaq 0x2e12(%rip), %rsi      # 0x6112
callq 0x2060
testl %eax, %eax
je 0x333a
movq -0x50(%rbp), %rsi
cmpq -0x70(%rbp), %rsi
je 0x3390
cmpq -0x48(%rbp), %rsi
jne 0x3324
movq -0x38(%rbp), %rax
movq -0x8(%rax), %rsi
addq %r14, %rsi
addq $-0x20, %rsi
movq %rbx, %rdi
callq 0x40d6
movq %r13, %rdi
callq 0x5062
jmp 0x32e0
movq %r13, %rdi
callq 0x5062
jmp 0x32a3
movq -0x50(%rbp), %rsi
cmpq -0x70(%rbp), %rsi
je 0x33d5
movl $0x200, %r15d           # imm = 0x200
leaq -0x80(%rbp), %r14
cmpq -0x48(%rbp), %rsi
jne 0x3370
movq -0x38(%rbp), %rax
movq -0x8(%rax), %rsi
addq %r15, %rsi
addq $-0x20, %rsi
movq %rbx, %rdi
callq 0x40d6
movq %r14, %rdi
callq 0x5062
movq -0x50(%rbp), %rsi
cmpq -0x70(%rbp), %rsi
jne 0x335f
jmp 0x33d5
leaq 0x2d64(%rip), %rsi      # 0x60fb
jmp 0x33be
movq 0x5c30(%rip), %rdi      # 0x8fd0
leaq 0x2d1f(%rip), %rsi      # 0x60c6
movl $0x1e, %edx
callq 0x2180
movl $0x15, %r15d
leaq 0x2d27(%rip), %rsi      # 0x60e5
movq 0x5c0b(%rip), %rdi      # 0x8fd0
movq %r15, %rdx
callq 0x2180
movq %rbx, %rdi
callq 0x4122
leaq -0x80(%rbp), %rdi
callq 0x4376
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x33fd
movq %rax, %r14
jmp 0x3409
jmp 0x33fd
jmp 0x33fd
jmp 0x33fd
movq %rax, %r14
leaq -0x80(%rbp), %rdi
callq 0x4376
movq %rbx, %rdi
callq 0x3faa
movq %r14, %rdi
callq 0x2220