// File: /workspace/github_cpp_makefile_star2_O3/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, -0x30(%rbp)
movq %rdi, %r15
xorps %xmm0, %xmm0
leaq -0xc0(%rbp), %rdi
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
xorl %ebx, %ebx
xorl %esi, %esi
callq 0x4eb6
leaq -0xd8(%rbp), %r13
movq %r13, -0x10(%r13)
movq %rbx, -0x8(%r13)
movb %bl, (%r13)
leaq -0x60(%rbp), %r12
movq %r12, -0x10(%r12)
movq %rbx, -0x8(%r12)
movb %bl, (%r12)
movq (%r15), %r14
movq %r15, -0xc8(%rbp)
movq 0x8(%r15), %rax
cmpq %rax, %r14
je 0x38af
subq %r14, %rax
cmpq $0x20, %rax
jne 0x35cb
leaq -0x118(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x2bed(%rip), %rdx      # 0x6111
leaq -0x128(%rbp), %rdi
movq %rdx, %rsi
callq 0x44d6
leaq -0xf8(%rbp), %r12
movq %r12, -0x10(%r12)
leaq 0x2bcb(%rip), %rdx      # 0x6111
leaq -0x108(%rbp), %rdi
movq %rdx, %rsi
callq 0x44d6
leaq -0x50(%rbp), %rdi
leaq -0x128(%rbp), %rdx
leaq -0x108(%rbp), %rcx
movq %r14, %rsi
movq -0x30(%rbp), %r8
callq 0x3ccc
leaq 0x2c68(%rip), %rsi      # 0x61e2
leaq -0x50(%rbp), %r14
movq %r14, %rdi
callq 0x2060
testl %eax, %eax
sete %bl
movq (%r14), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x359c
callq 0x2120
movq -0x108(%rbp), %rdi
cmpq %r12, %rdi
je 0x35ad
callq 0x2120
movq -0x128(%rbp), %rdi
cmpq %r15, %rdi
leaq -0x60(%rbp), %r12
je 0x38af
callq 0x2120
jmp 0x38af
leaq -0xc0(%rbp), %r12
leaq -0xe8(%rbp), %rbx
leaq -0x70(%rbp), %r13
cmpq $0x1, 0x8(%r14)
jne 0x361c
movq (%r14), %rax
movq %r12, %r15
movq %r13, %r12
movq %rbx, %r13
movsbl (%rax), %ebx
movl %ebx, %edi
callq 0x21f0
cmpl $0x76, %ebx
movq %r13, %rbx
movq %r12, %r13
movq %r15, %r12
je 0x361c
testl %eax, %eax
je 0x361c
movq %r12, %rdi
movq %r14, %rsi
callq 0x50c2
jmp 0x3786
movq %r14, %rdi
leaq 0x2a22(%rip), %rsi      # 0x6048
callq 0x2060
movq -0x78(%rbp), %rcx
movq %rcx, %r9
subq -0x98(%rbp), %r9
shrq $0x3, %r9
cmpq $0x1, %rcx
adcq $-0x1, %r9
shlq $0x4, %r9
movq -0xa0(%rbp), %rdi
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
movq %rsi, %r8
subq %rdx, %r8
sarq $0x5, %r8
addq %r9, %r8
subq -0xb0(%rbp), %rdi
sarq $0x5, %rdi
testl %eax, %eax
je 0x370a
addq %rdi, %r8
cmpq $0x2, %r8
jb 0x3863
cmpq %rdx, %rsi
jne 0x369c
movq -0x8(%rcx), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
movq %rbx, %rdi
callq 0x20a0
movq %r12, %rdi
callq 0x5034
movq -0x90(%rbp), %rsi
cmpq -0x88(%rbp), %rsi
jne 0x36d0
movq -0x78(%rbp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
movq %r13, %rdi
callq 0x20a0
movq %r12, %rdi
callq 0x5034
leaq -0x50(%rbp), %r15
movq %r15, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %r14, %rcx
movq -0x30(%rbp), %r8
callq 0x3ccc
movq %r12, %rdi
movq %r15, %rsi
callq 0x535c
jmp 0x3774
addq %rdi, %r8
je 0x3863
cmpq %rdx, %rsi
jne 0x3724
movq -0x8(%rcx), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
movq %rbx, %rdi
callq 0x20a0
movq %r12, %rdi
callq 0x5034
movq -0x68(%rbp), %rdx
movq %r13, %rdi
xorl %esi, %esi
leaq 0x29c9(%rip), %rcx      # 0x6111
xorl %r8d, %r8d
callq 0x21e0
leaq -0x50(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq -0x30(%rbp), %r8
callq 0x3ccc
movq %r12, %rdi
movq %r15, %rsi
callq 0x535c
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3786
callq 0x2120
addq $0x20, %r14
movq -0xc8(%rbp), %rax
cmpq 0x8(%rax), %r14
jne 0x35dd
movq -0x78(%rbp), %rax
movq %rax, %rdx
subq -0x98(%rbp), %rdx
shrq $0x3, %rdx
cmpq $0x1, %rax
adcq $-0x1, %rdx
shlq $0x4, %rdx
movq -0xa0(%rbp), %rsi
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rcx
movq %rdi, %r8
subq %rcx, %r8
sarq $0x5, %r8
subq -0xb0(%rbp), %rsi
sarq $0x5, %rsi
addq %r8, %rsi
addq %rdx, %rsi
cmpq $0x1, %rsi
jne 0x388a
cmpq %rcx, %rdi
leaq -0xd8(%rbp), %r13
leaq -0x60(%rbp), %r12
jne 0x380c
movl $0x200, %edi            # imm = 0x200
addq -0x8(%rax), %rdi
addq $-0x20, %rdi
leaq 0x29cb(%rip), %rsi      # 0x61e2
callq 0x2060
testl %eax, %eax
je 0x38ee
movq -0x90(%rbp), %rdi
cmpq -0x88(%rbp), %rdi
jne 0x3841
movq -0x78(%rbp), %rax
movl $0x200, %edi            # imm = 0x200
addq -0x8(%rax), %rdi
addq $-0x20, %rdi
leaq 0x27eb(%rip), %rsi      # 0x6037
callq 0x2060
testl %eax, %eax
je 0x38ad
movl $0x32, %edx
leaq 0x2907(%rip), %rsi      # 0x6168
jmp 0x38a1
movq 0x5766(%rip), %rdi      # 0x8fd0
leaq 0x28a3(%rip), %rsi      # 0x6114
movl $0x2a, %edx
callq 0x2180
xorl %ebx, %ebx
leaq -0xd8(%rbp), %r13
leaq -0x60(%rbp), %r12
jmp 0x38af
movl $0x28, %edx
leaq 0x28a9(%rip), %rsi      # 0x613f
leaq -0xd8(%rbp), %r13
leaq -0x60(%rbp), %r12
movq 0x5728(%rip), %rdi      # 0x8fd0
callq 0x2180
xorl %ebx, %ebx
movq -0x70(%rbp), %rdi
cmpq %r12, %rdi
je 0x38bd
callq 0x2120
movq -0xe8(%rbp), %rdi
cmpq %r13, %rdi
je 0x38ce
callq 0x2120
leaq -0xc0(%rbp), %rdi
callq 0x4358
movl %ebx, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %bl
jmp 0x38af
jmp 0x393c
jmp 0x393c
movq %rax, %rbx
movq -0x108(%rbp), %rdi
cmpq %r12, %rdi
je 0x390f
callq 0x2120
jmp 0x390f
movq %rax, %rbx
movq -0x128(%rbp), %rdi
cmpq %r15, %rdi
jne 0x3933
jmp 0x393f
jmp 0x393c
jmp 0x3923
jmp 0x393c
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x393f
callq 0x2120
jmp 0x393f
jmp 0x393c
movq %rax, %rbx
movq -0x70(%rbp), %rdi
leaq -0x60(%rbp), %rax
cmpq %rax, %rdi
je 0x3951
callq 0x2120
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x3969
callq 0x2120
leaq -0xc0(%rbp), %rdi
callq 0x4358
movq %rbx, %rdi
callq 0x2220