// File: /workspace/github_cpp_makefile_star2_O1/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 -0xa0(%rbp), %rdi
movaps %xmm0, 0x40(%rdi)
movaps %xmm0, 0x30(%rdi)
movaps %xmm0, 0x20(%rdi)
movaps %xmm0, 0x10(%rdi)
movaps %xmm0, (%rdi)
xorl %r12d, %r12d
xorl %esi, %esi
callq 0x4ee4
leaq -0xd8(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r12, -0x8(%rax)
movb %r12b, (%rax)
leaq -0xb0(%rbp), %rax
movq %rax, -0x10(%rax)
movq %r12, -0x8(%rax)
movb %r12b, (%rax)
movq (%r15), %r14
movq 0x8(%r15), %rax
cmpq %rax, %r14
je 0x3894
subq %r14, %rax
cmpq $0x20, %rax
jne 0x35a1
leaq -0x118(%rbp), %r15
movq %r15, -0x10(%r15)
leaq 0x2c13(%rip), %rdx      # 0x6111
leaq -0x128(%rbp), %rdi
movq %rdx, %rsi
callq 0x44e2
leaq -0xf8(%rbp), %r13
movq %r13, -0x10(%r13)
leaq 0x2bf2(%rip), %rdx      # 0x6111
leaq -0x108(%rbp), %rdi
movq %rdx, %rsi
callq 0x44e2
leaq -0x50(%rbp), %rdi
leaq -0x128(%rbp), %rdx
leaq -0x108(%rbp), %rcx
movq %r14, %rsi
movq -0x30(%rbp), %r8
callq 0x3cf4
leaq 0x2c8f(%rip), %rsi      # 0x61e2
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
callq 0x2060
testl %eax, %eax
sete %r12b
movq (%rbx), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3576
callq 0x2120
movq -0x108(%rbp), %rdi
cmpq %r13, %rdi
je 0x3587
callq 0x2120
movq -0x128(%rbp), %rdi
cmpq %r15, %rdi
je 0x3894
callq 0x2120
jmp 0x3894
cmpq 0x8(%r15), %r14
je 0x37b8
leaq -0xa0(%rbp), %r12
leaq -0xe8(%rbp), %r13
movq %r15, -0xc8(%rbp)
cmpq $0x1, 0x8(%r14)
jne 0x35fd
movq (%r14), %rax
movq %r13, %rbx
movsbl (%rax), %r13d
movl %r13d, %edi
callq 0x21f0
cmpl $0x76, %r13d
movq %rbx, %r13
movq -0xc8(%rbp), %r15
je 0x35fd
testl %eax, %eax
je 0x35fd
movq %r12, %rdi
movq %r14, %rsi
callq 0x50f0
jmp 0x37aa
movq %r14, %rdi
leaq 0x2a41(%rip), %rsi      # 0x6048
callq 0x2060
testl %eax, %eax
je 0x36e4
movq -0x58(%rbp), %rax
movq %rax, %rdx
subq -0x78(%rbp), %rdx
shrq $0x3, %rdx
cmpq $0x1, %rax
adcq $-0x1, %rdx
shlq $0x4, %rdx
movq -0x80(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rcx
movq %rsi, %r8
subq %rcx, %r8
sarq $0x5, %r8
subq -0x90(%rbp), %rdi
sarq $0x5, %rdi
addq %r8, %rdi
addq %rdx, %rdi
cmpq $0x2, %rdi
jb 0x3879
cmpq %rcx, %rsi
jne 0x3671
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
movq %r13, %rdi
callq 0x20a0
movq %r12, %rdi
callq 0x5062
movq -0x70(%rbp), %rsi
cmpq -0x68(%rbp), %rsi
jne 0x369f
movq -0x58(%rbp), %rax
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
leaq -0xc0(%rbp), %rdi
callq 0x20a0
movq %r12, %rdi
callq 0x5062
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
leaq -0xc0(%rbp), %rsi
movq %r13, %rdx
movq %r14, %rcx
movq -0x30(%rbp), %r8
callq 0x3cf4
movq %r12, %rdi
movq %rbx, %rsi
callq 0x538a
jmp 0x3798
movq -0x58(%rbp), %rax
movq %rax, %rdx
subq -0x78(%rbp), %rdx
shrq $0x3, %rdx
cmpq $0x1, %rax
adcq $-0x1, %rdx
shlq $0x4, %rdx
movq -0x80(%rbp), %rdi
movq -0x70(%rbp), %rsi
movq -0x68(%rbp), %rcx
movq %rsi, %r8
subq %rcx, %r8
sarq $0x5, %r8
addq %rdx, %r8
subq -0x90(%rbp), %rdi
sarq $0x5, %rdi
addq %r8, %rdi
je 0x3879
cmpq %rcx, %rsi
jne 0x373d
movq -0x8(%rax), %rsi
movl $0x200, %eax            # imm = 0x200
addq %rax, %rsi
addq $-0x20, %rsi
movq %r13, %rdi
callq 0x20a0
movq %r12, %rdi
callq 0x5062
movq -0xb8(%rbp), %rdx
leaq -0xc0(%rbp), %rdi
xorl %esi, %esi
leaq 0x29a9(%rip), %rcx      # 0x6111
xorl %r8d, %r8d
callq 0x21e0
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
leaq -0xc0(%rbp), %rdx
movq %r14, %rcx
movq -0x30(%rbp), %r8
callq 0x3cf4
movq %r12, %rdi
movq %rbx, %rsi
callq 0x538a
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x37aa
callq 0x2120
addq $0x20, %r14
cmpq 0x8(%r15), %r14
jne 0x35c0
movq -0x58(%rbp), %rax
movq %rax, %rdx
subq -0x78(%rbp), %rdx
shrq $0x3, %rdx
cmpq $0x1, %rax
adcq $-0x1, %rdx
shlq $0x4, %rdx
movq -0x80(%rbp), %rsi
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rcx
movq %rdi, %r8
subq %rcx, %r8
sarq $0x5, %r8
subq -0x90(%rbp), %rsi
sarq $0x5, %rsi
addq %r8, %rsi
addq %rdx, %rsi
cmpq $0x1, %rsi
jne 0x385f
cmpq %rcx, %rdi
jne 0x380e
movl $0x200, %edi            # imm = 0x200
addq -0x8(%rax), %rdi
addq $-0x20, %rdi
leaq 0x29c9(%rip), %rsi      # 0x61e2
callq 0x2060
testl %eax, %eax
je 0x38e5
movq -0x70(%rbp), %rdi
cmpq -0x68(%rbp), %rdi
jne 0x383d
movq -0x58(%rbp), %rax
movl $0x200, %edi            # imm = 0x200
addq -0x8(%rax), %rdi
addq $-0x20, %rdi
leaq 0x27ef(%rip), %rsi      # 0x6037
callq 0x2060
testl %eax, %eax
je 0x3891
movl $0x32, %edx
leaq 0x290b(%rip), %rsi      # 0x6168
jmp 0x386b
movl $0x28, %edx
leaq 0x28d4(%rip), %rsi      # 0x613f
movq 0x575e(%rip), %rdi      # 0x8fd0
callq 0x2180
jmp 0x3891
movq 0x5750(%rip), %rdi      # 0x8fd0
leaq 0x288d(%rip), %rsi      # 0x6114
movl $0x2a, %edx
callq 0x2180
xorl %r12d, %r12d
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x38ac
callq 0x2120
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x38c4
callq 0x2120
leaq -0xa0(%rbp), %rdi
callq 0x4376
movl %r12d, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %r12b
jmp 0x3894
jmp 0x3934
jmp 0x3934
movq %rax, %rbx
movq -0x108(%rbp), %rdi
cmpq %r13, %rdi
je 0x3907
callq 0x2120
jmp 0x3907
movq %rax, %rbx
movq -0x128(%rbp), %rdi
cmpq %r15, %rdi
jne 0x392b
jmp 0x3937
jmp 0x3934
jmp 0x391b
jmp 0x3934
movq %rax, %rbx
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x3937
callq 0x2120
jmp 0x3937
jmp 0x3934
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
leaq -0xb0(%rbp), %rax
cmpq %rax, %rdi
je 0x394f
callq 0x2120
movq -0xe8(%rbp), %rdi
leaq -0xd8(%rbp), %rax
cmpq %rax, %rdi
je 0x3967
callq 0x2120
leaq -0xa0(%rbp), %rdi
callq 0x4376
movq %rbx, %rdi
callq 0x2220