// File: 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
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0xa0(%rbp)
movq %rdi, %rax
movq %rax, -0x98(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x11(%rbp)
callq 0x4d90
leaq -0x68(%rbp), %rdi
callq 0x53f0
jmp 0x36c8
movq -0x10(%rbp), %rdi
callq 0x52a0
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5310
movq %rax, -0x88(%rbp)
leaq -0x80(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x52d0
testb $0x1, %al
jne 0x36fe
jmp 0x3a53
leaq -0x80(%rbp), %rdi
callq 0x5040
movq %rax, %rdi
callq 0x4350
testb $0x1, %al
jne 0x3715
jmp 0x375f
leaq -0x80(%rbp), %rdi
callq 0x5040
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
callq 0x51a0
jmp 0x372f
jmp 0x3a43
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
jmp 0x3ae1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x5500
jmp 0x3ae1
leaq -0x80(%rbp), %rdi
callq 0x5040
movq %rax, %rdi
callq 0x43c0
movb %al, -0xa1(%rbp)
jmp 0x3778
movb -0xa1(%rbp), %al
testb $0x1, %al
jne 0x3787
jmp 0x38cc
leaq -0x80(%rbp), %rdi
callq 0x5040
movq %rax, %rdi
callq 0x4850
movl %eax, -0xa8(%rbp)
jmp 0x37a0
movl -0xa8(%rbp), %eax
movl %eax, -0x78(%rbp)
cmpl $-0x1, -0x78(%rbp)
jne 0x37ff
movq 0xe81a(%rip), %rdi      # 0x11fd0
leaq 0x88fd(%rip), %rsi      # 0xc0ba
callq 0x2190
movq %rax, -0xb0(%rbp)
jmp 0x37cb
movq -0xb0(%rbp), %rdi
leaq 0x8900(%rip), %rsi      # 0xc0d9
callq 0x2190
jmp 0x37e0
movq -0xa0(%rbp), %rdi
callq 0x5420
movb $0x1, -0x11(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x3ab6
jmp 0x3801
leaq -0x68(%rbp), %rdi
callq 0x5440
movb %al, -0xb1(%rbp)
jmp 0x3812
movb -0xb1(%rbp), %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xb2(%rbp)
jne 0x386d
jmp 0x3827
movl -0x78(%rbp), %eax
movl %eax, -0xc4(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x5460
movq %rax, -0xc0(%rbp)
jmp 0x3842
movq -0xc0(%rbp), %rdi
callq 0x4850
movl %eax, -0xc8(%rbp)
jmp 0x3856
movl -0xc4(%rbp), %eax
movl -0xc8(%rbp), %ecx
cmpl %ecx, %eax
setle %al
movb %al, -0xb2(%rbp)
movb -0xb2(%rbp), %al
testb $0x1, %al
jne 0x3879
jmp 0x38b0
leaq -0x68(%rbp), %rdi
callq 0x5460
movq %rax, -0xd0(%rbp)
jmp 0x388b
movq -0xd0(%rbp), %rsi
movq -0xa0(%rbp), %rdi
callq 0x51a0
jmp 0x38a0
leaq -0x68(%rbp), %rdi
callq 0x5480
jmp 0x38ab
jmp 0x3801
leaq -0x80(%rbp), %rdi
callq 0x5040
movq %rax, %rsi
leaq -0x68(%rbp), %rdi
callq 0x54a0
jmp 0x38c7
jmp 0x3a41
leaq -0x80(%rbp), %rdi
callq 0x5040
movq %rax, %rdi
callq 0x47b0
testb $0x1, %al
jne 0x38e3
jmp 0x38ff
leaq -0x80(%rbp), %rdi
callq 0x5040
movq %rax, %rsi
leaq -0x68(%rbp), %rdi
callq 0x54a0
jmp 0x38fa
jmp 0x3a3f
leaq -0x80(%rbp), %rdi
callq 0x5040
movq %rax, %rdi
callq 0x4800
testb $0x1, %al
jne 0x3919
jmp 0x3a3d
leaq -0x68(%rbp), %rdi
callq 0x5440
movb %al, -0xd1(%rbp)
jmp 0x392a
movb -0xd1(%rbp), %al
testb $0x1, %al
jne 0x3936
jmp 0x396a
movq 0xe693(%rip), %rdi      # 0x11fd0
leaq 0x87ab(%rip), %rsi      # 0xc0ef
callq 0x2190
jmp 0x394b
movq -0xa0(%rbp), %rdi
callq 0x5420
movb $0x1, -0x11(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x3ab6
jmp 0x396c
leaq -0x68(%rbp), %rdi
callq 0x5460
movq %rax, -0xe0(%rbp)
jmp 0x397e
movq -0xe0(%rbp), %rdi
leaq 0x877a(%rip), %rsi      # 0xc106
callq 0x54d0
movb %al, -0xe1(%rbp)
jmp 0x3999
movb -0xe1(%rbp), %al
testb $0x1, %al
jne 0x39a8
jmp 0x3a30
leaq -0x68(%rbp), %rdi
callq 0x5440
movb %al, -0xe2(%rbp)
jmp 0x39b9
movb -0xe2(%rbp), %al
testb $0x1, %al
jne 0x39c5
jmp 0x39f9
movq 0xe604(%rip), %rdi      # 0x11fd0
leaq 0x871c(%rip), %rsi      # 0xc0ef
callq 0x2190
jmp 0x39da
movq -0xa0(%rbp), %rdi
callq 0x5420
movb $0x1, -0x11(%rbp)
movl $0x1, -0x8c(%rbp)
jmp 0x3ab6
leaq -0x68(%rbp), %rdi
callq 0x5460
movq %rax, -0xf0(%rbp)
jmp 0x3a0b
movq -0xf0(%rbp), %rsi
movq -0xa0(%rbp), %rdi
callq 0x51a0
jmp 0x3a20
leaq -0x68(%rbp), %rdi
callq 0x5480
jmp 0x3a2b
jmp 0x396c
leaq -0x68(%rbp), %rdi
callq 0x5480
jmp 0x3a3b
jmp 0x3a3d
jmp 0x3a3f
jmp 0x3a41
jmp 0x3a43
jmp 0x3a45
leaq -0x80(%rbp), %rdi
callq 0x5060
jmp 0x36d5
jmp 0x3a55
leaq -0x68(%rbp), %rdi
callq 0x5440
movb %al, -0xf1(%rbp)
jmp 0x3a66
movb -0xf1(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x3a74
jmp 0x3aa8
leaq -0x68(%rbp), %rdi
callq 0x5460
movq %rax, -0x100(%rbp)
jmp 0x3a86
movq -0x100(%rbp), %rsi
movq -0xa0(%rbp), %rdi
callq 0x51a0
jmp 0x3a9b
leaq -0x68(%rbp), %rdi
callq 0x5480
jmp 0x3aa6
jmp 0x3a55
movb $0x1, -0x11(%rbp)
movl $0x1, -0x8c(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x5500
testb $0x1, -0x11(%rbp)
jne 0x3ad1
movq -0xa0(%rbp), %rdi
callq 0x4e00
movq -0x98(%rbp), %rax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0xa0(%rbp), %rdi
callq 0x4e00
movq -0x70(%rbp), %rdi
callq 0x22c0
nopw %cs:(%rax,%rax)