// File: /workspace/github_cpp_makefile_star2_O2/mbottini[P]CS250lab2/main.cpp
// Function: evalRPN(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&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, bool, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, bool>>> const&)
bool evalRPN(const stringVector& RPNVector, const boolMap& bmap) {
    std::stack<string> variableStack;
    string arg1, arg2;

    if(RPNVector.empty()) {
        return false;
    }

    // If it's just one variable in the statement, return the variable.
    if(RPNVector.size() == 1) {
        if(evalExpression(RPNVector[0], "", "", bmap) == "t") {
            return true;
        }

        else {
            return false;
        }
    }

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

        // Otherwise, it's an operator.
        else {
            // Unary operator takes one argument.
            if(*i == "!") {
                if(variableStack.size() > 0) {
                    arg1 = variableStack.top();
                    variableStack.pop();
                    arg2 = "";
                    // Evaluate the arguments and push the result onto the
                    // stack.
                    variableStack.push(evalExpression(arg1, arg2, *i, bmap));
                }

                else {
                    std::cout << "Invalid expression! Not enough arguments.\n";
                    return false;
                }
            }

            // Otherwise, it's a binary operator and takes two.
            else {
                if(variableStack.size() > 1) {
                    arg1 = variableStack.top();
                    variableStack.pop();
                    arg2 = variableStack.top();
                    variableStack.pop();
                    variableStack.push(evalExpression(arg2, arg1, *i, bmap));
                }

                else {
                    std::cout << "Invalid expression! Not enough arguments.\n";
                    return false;
                }
            }
        }
    }

    // We should have a single expression at this point - either c or t.

    if(variableStack.size() != 1) {
        std::cout << "Invalid expression! Too many arguments.\n";
        return false;
    }

    if(variableStack.top() == "t") {
        return true;
    }

    else {
        if(variableStack.top() != "c") {
            std::cout << "Invalid expression! It didn't simplify to t or c.\n";
        }
        return false;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rsi, -0x38(%rbp)
movq %rdi, %r15
leaq -0x90(%rbp), %rdi
callq 0x39c4
leaq -0x120(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %r12d, %r12d
movb %r12b, (%rax)
leaq -0xc0(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %r12b, (%rax)
movq (%r15), %r14
movq 0x8(%r15), %rax
cmpq %rax, %r14
je 0x32d0
movq %rax, %rcx
subq %r14, %rcx
cmpq $0x20, %rcx
jne 0x309d
leaq 0x30de(%rip), %rsi      # 0x60f5
leaq -0x110(%rbp), %rdi
leaq -0x2a(%rbp), %rdx
callq 0x2090
leaq 0x30c7(%rip), %rsi      # 0x60f5
leaq -0xf0(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x2090
leaq -0xb0(%rbp), %rdi
leaq -0x110(%rbp), %rdx
leaq -0xf0(%rbp), %rcx
movq %r14, %rsi
movq -0x38(%rbp), %r8
callq 0x3628
leaq 0x3136(%rip), %rsi      # 0x619c
leaq -0xb0(%rbp), %rbx
movq %rbx, %rdi
callq 0x3955
movl %eax, %r12d
movq %rbx, %rdi
callq 0x20c0
leaq -0xf0(%rbp), %rdi
callq 0x20c0
leaq -0x110(%rbp), %rdi
callq 0x20c0
jmp 0x32d0
leaq -0x90(%rbp), %r12
leaq -0x130(%rbp), %rbx
movq %r15, -0x40(%rbp)
cmpq %rax, %r14
je 0x3231
movq %r14, %rdi
callq 0x340f
testb %al, %al
je 0x30d4
movq %r12, %rdi
movq %r14, %rsi
callq 0x4806
jmp 0x3224
movq %rbx, %r13
movq %r14, %rdi
leaq 0x2f4b(%rip), %rsi      # 0x602c
callq 0x3955
movl %eax, %ebx
movq %r12, %r15
movq %r12, %rdi
callq 0x48ee
testb %bl, %bl
je 0x317e
testq %rax, %rax
je 0x32ba
movq %r13, %rbx
movq -0x60(%rbp), %rsi
cmpq -0x58(%rbp), %rsi
jne 0x3121
movq -0x48(%rbp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
movq %rbx, %rdi
callq 0x20e0
leaq -0xd0(%rbp), %r13
movq %r15, %r12
movq -0x40(%rbp), %r15
movq %r12, %rdi
callq 0x4798
movq %r13, %rdi
leaq 0x2fa8(%rip), %rsi      # 0x60f5
callq 0x2250
movq %r13, %rdx
leaq -0xb0(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
movq %r14, %rcx
movq -0x38(%rbp), %r8
callq 0x3628
movq %r12, %rdi
movq %r13, %rsi
callq 0x4a98
jmp 0x321c
cmpq $0x2, %rax
jb 0x32ba
movq %r13, %rbx
movq -0x60(%rbp), %rsi
cmpq -0x58(%rbp), %rsi
jne 0x31a5
movq -0x48(%rbp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
movq %rbx, %rdi
callq 0x20e0
leaq -0xd0(%rbp), %r13
movq %r15, %r12
movq -0x40(%rbp), %r15
movq %r12, %rdi
callq 0x4798
movq -0x60(%rbp), %rsi
cmpq -0x58(%rbp), %rsi
jne 0x31e1
movq -0x48(%rbp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
movq %r13, %rdi
callq 0x20e0
movq %r12, %rdi
callq 0x4798
movq %r13, %rsi
leaq -0xb0(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rdx
movq %r14, %rcx
movq -0x38(%rbp), %r8
callq 0x3628
movq %r12, %rdi
movq %r13, %rsi
callq 0x4a98
movq %r13, %rdi
callq 0x20c0
addq $0x20, %r14
movq 0x8(%r15), %rax
jmp 0x30af
leaq -0x90(%rbp), %rdi
callq 0x48ee
cmpq $0x1, %rax
jne 0x32a5
movq -0x60(%rbp), %rdi
cmpq -0x58(%rbp), %rdi
jne 0x325a
movq -0x48(%rbp), %rax
movl $0x200, %edi            # imm = 0x200
addq -0x8(%rax), %rdi
addq $-0x20, %rdi
leaq 0x2f37(%rip), %rsi      # 0x619c
callq 0x3955
movb $0x1, %r12b
testb %al, %al
jne 0x32d0
movq -0x60(%rbp), %rdi
cmpq -0x58(%rbp), %rdi
jne 0x3288
movq -0x48(%rbp), %rax
movl $0x200, %edi            # imm = 0x200
addq -0x8(%rax), %rdi
addq $-0x20, %rdi
leaq 0x2d88(%rip), %rsi      # 0x601b
callq 0x39f1
testb %al, %al
je 0x32cd
leaq 0x2ea9(%rip), %rsi      # 0x614c
jmp 0x32ac
leaq 0x2e77(%rip), %rsi      # 0x6123
movq 0x5d1d(%rip), %rdi      # 0x8fd0
callq 0x2160
jmp 0x32cd
movq 0x5d0f(%rip), %rdi      # 0x8fd0
leaq 0x2e30(%rip), %rsi      # 0x60f8
callq 0x2160
xorl %r12d, %r12d
leaq -0xd0(%rbp), %rdi
callq 0x20c0
leaq -0x130(%rbp), %rdi
callq 0x20c0
leaq -0x90(%rbp), %rdi
callq 0x3b92
movl %r12d, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3343
jmp 0x3343
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
callq 0x20c0
jmp 0x3321
movq %rax, %rbx
leaq -0x110(%rbp), %rdi
jmp 0x333a
jmp 0x3343
jmp 0x3330
jmp 0x3343
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x20c0
jmp 0x3346
jmp 0x3343
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x20c0
leaq -0x130(%rbp), %rdi
callq 0x20c0
leaq -0x90(%rbp), %rdi
callq 0x3b92
movq %rbx, %rdi
callq 0x2240