// File: /workspace/github_cpp_makefile_star2_O2/mbottini[P]CS250lab2/main.cpp
// Function: main
int main() {
    stringVector tokenVector1, tokenVector2;
    stringVector variableVector1, variableVector2;
    stringVector variableVectorUnion;
    stringVector RPNVector1, RPNVector2;
    string inputString1, inputString2;
    boolMap bmap;
    bool result1, result2;

    std::cout << "Premise: ";
    getline(std::cin, inputString1);
    std::cout << "Conclusion: ";
    getline(std::cin, inputString2);

    tokenVector1 = getTokens(inputString1);
    tokenVector2 = getTokens(inputString2);

    variableVector1 = getVariables(tokenVector1);
    variableVector2 = getVariables(tokenVector2);
    variableVectorUnion = combineVectors(variableVector1, variableVector2);

    RPNVector1 = convertRPN(tokenVector1);
    RPNVector2 = convertRPN(tokenVector2);
    
    bool validConclusion = true;

    // Set initial values of bmap. "c" and "t" never change. ComboGen
    // is initially set to make every variable "true."
    bmap["c"] = false;
    bmap["t"] = true;

    int comboGen = 1;

    for(int i = 0; i < variableVectorUnion.size(); i++) {
        comboGen *= 2;
    }

    comboGen--;

    // Print out the top part of the output table.

    int colWidth1 = inputString1.length();
    int colWidth2 = inputString2.length();

    for(stringIter i = variableVectorUnion.begin(); i !=
            variableVectorUnion.end(); ++i) {
        std::cout << *i << " ";
    }
    std::cout << "| ";

    std::cout << inputString1 << " | " << inputString2 << "\n";

    // Print the truth table values.
    while(comboGen >= 0) {
        setValues(bmap, variableVectorUnion, comboGen);

        result1 = evalRPN(RPNVector1, bmap);
        result2 = evalRPN(RPNVector2, bmap);

        for(stringIter i = variableVectorUnion.begin();
                i != variableVectorUnion.end(); ++i) {
            printBool(bmap.at(*i)); 
            std::cout << " ";
        }

        std::cout << "|";
        printSpaces(colWidth1 / 2);

        if(inputString1.length() % 2 == 1) {
            std::cout << " ";
        }

        printBool(result1);
        printSpaces(colWidth1 / 2);

        std::cout << " |";
        printSpaces(colWidth2 / 2); 

        if(inputString2.length() % 2 == 1) {
            std::cout << " ";
        }

        printBool(result2);
        printSpaces(colWidth2 / 2);

        if(result1 != result2) {
            std::cout << " Invalid!";
            validConclusion = false;
        }

        std::cout << "\n";
        comboGen--;
    }

    if(validConclusion) {
        std::cout << "Valid statement. All truth table values line up.\n";
    }

    else {
        std::cout << "Invalid statement. Invalid truth table values are "
                  << "labelled.\n";
    }

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
xorps %xmm0, %xmm0
movaps %xmm0, -0xc0(%rbp)
andq $0x0, -0xb0(%rbp)
movaps %xmm0, -0xa0(%rbp)
andq $0x0, -0x90(%rbp)
movaps %xmm0, -0x120(%rbp)
andq $0x0, -0x110(%rbp)
movaps %xmm0, -0x180(%rbp)
andq $0x0, -0x170(%rbp)
movaps %xmm0, -0x80(%rbp)
andq $0x0, -0x70(%rbp)
movaps %xmm0, -0x100(%rbp)
andq $0x0, -0xf0(%rbp)
movaps %xmm0, -0xe0(%rbp)
andq $0x0, -0xd0(%rbp)
leaq -0x150(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
xorl %ecx, %ecx
movb %cl, (%rax)
leaq -0x130(%rbp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb %cl, (%rax)
leaq -0x1a8(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq 0x6b71(%rip), %rdi      # 0x8fd0
leaq 0x3b9e(%rip), %rsi      # 0x6004
callq 0x2160
movq 0x6b6e(%rip), %rdi      # 0x8fe0
leaq -0x160(%rbp), %rsi
callq 0x2050
movq 0x6b4b(%rip), %rdi      # 0x8fd0
leaq 0x3b82(%rip), %rsi      # 0x600e
callq 0x2160
movq 0x6b48(%rip), %rdi      # 0x8fe0
leaq -0x140(%rbp), %rsi
callq 0x2050
leaq -0x60(%rbp), %rdi
leaq -0x160(%rbp), %rsi
callq 0x2981
leaq -0xc0(%rbp), %rdi
leaq -0x60(%rbp), %rbx
movq %rbx, %rsi
callq 0x3d4c
movq %rbx, %rdi
callq 0x3870
leaq -0x60(%rbp), %rdi
leaq -0x140(%rbp), %rsi
callq 0x2981
leaq -0xa0(%rbp), %rdi
movq %rbx, %rsi
callq 0x3d4c
movq %rbx, %rdi
callq 0x3870
leaq -0x60(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x2be8
leaq -0x120(%rbp), %rdi
movq %rbx, %rsi
callq 0x3d4c
movq %rbx, %rdi
callq 0x3870
leaq -0x60(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x2be8
leaq -0x180(%rbp), %rbx
leaq -0x60(%rbp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3d4c
movq %r14, %rdi
callq 0x3870
leaq -0x60(%rbp), %rdi
leaq -0x120(%rbp), %rsi
movq %rbx, %rdx
callq 0x2c9f
leaq -0x80(%rbp), %rdi
leaq -0x60(%rbp), %rbx
movq %rbx, %rsi
callq 0x3d4c
movq %rbx, %rdi
callq 0x3870
leaq -0x60(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x2d0d
leaq -0x100(%rbp), %rdi
movq %rbx, %rsi
callq 0x3d4c
movq %rbx, %rdi
callq 0x3870
leaq -0x60(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x2d0d
leaq -0xe0(%rbp), %rdi
movq %rbx, %rsi
callq 0x3d4c
movq %rbx, %rdi
callq 0x3870
leaq 0x3a50(%rip), %rsi      # 0x601b
leaq -0x60(%rbp), %rdi
leaq -0x2a(%rbp), %rdx
callq 0x2090
leaq -0x1b0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x389c
movb $0x0, (%rax)
leaq -0x60(%rbp), %rdi
callq 0x20c0
leaq 0x3ba1(%rip), %rsi      # 0x619c
leaq -0x60(%rbp), %rdi
leaq -0x2a(%rbp), %rdx
callq 0x2090
leaq -0x1b0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x389c
movb $0x1, (%rax)
leaq -0x60(%rbp), %rdi
callq 0x20c0
movq -0x80(%rbp), %r15
movq -0x78(%rbp), %rax
movq %rax, %rcx
subq %r15, %rcx
sarq $0x5, %rcx
pushq $0x1
popq %rdx
subq $0x1, %rcx
jb 0x2643
addl %edx, %edx
jmp 0x2639
movl %edx, -0x3c(%rbp)
movl -0x158(%rbp), %r14d
movl -0x138(%rbp), %ebx
movq 0x6976(%rip), %r12      # 0x8fd0
leaq 0x39ab(%rip), %r13      # 0x600c
cmpq %rax, %r15
je 0x2686
movq %r12, %rdi
movq %r15, %rsi
callq 0x2140
movq %rax, %rdi
movq %r13, %rsi
callq 0x2160
addq $0x20, %r15
movq -0x78(%rbp), %rax
jmp 0x2661
movq 0x6943(%rip), %rdi      # 0x8fd0
leaq 0x398a(%rip), %rsi      # 0x601e
callq 0x2160
movq 0x6930(%rip), %rdi      # 0x8fd0
leaq -0x160(%rbp), %rsi
callq 0x2140
leaq 0x396a(%rip), %rsi      # 0x601d
movq %rax, %rdi
callq 0x2160
leaq -0x140(%rbp), %rsi
movq %rax, %rdi
callq 0x2140
leaq 0x3a23(%rip), %rsi      # 0x60f4
movq %rax, %rdi
callq 0x2160
pushq $0x2
popq %rcx
movl %r14d, %eax
cltd
idivl %ecx
movl %eax, -0x38(%rbp)
movl %ebx, %eax
cltd
idivl %ecx
movl %eax, -0x34(%rbp)
movb $0x1, %al
movl %eax, -0x30(%rbp)
leaq -0x1b0(%rbp), %r13
movq 0x68d0(%rip), %r14      # 0x8fd0
leaq 0x3905(%rip), %r15      # 0x600c
movl -0x3c(%rbp), %edx
testl %edx, %edx
jle 0x281a
decl %edx
movq %r13, %rdi
leaq -0x80(%rbp), %rsi
movl %edx, -0x3c(%rbp)
callq 0x2f54
leaq -0x100(%rbp), %rdi
movq %r13, %rsi
callq 0x2fa0
movb %al, -0x29(%rbp)
leaq -0xe0(%rbp), %rdi
movq %r13, %rsi
callq 0x2fa0
movl %eax, %ebx
movq -0x80(%rbp), %r12
cmpq -0x78(%rbp), %r12
je 0x2774
movq %r13, %rdi
movq %r12, %rsi
callq 0x3906
movzbl (%rax), %edi
callq 0x3372
movq %r14, %rdi
movq %r15, %rsi
callq 0x2160
addq $0x20, %r12
jmp 0x274a
movq %r14, %rdi
leaq 0x38a4(%rip), %rsi      # 0x6022
callq 0x2160
movl -0x38(%rbp), %edi
callq 0x3397
testb $0x1, -0x158(%rbp)
je 0x279f
movq %r14, %rdi
movq %r15, %rsi
callq 0x2160
movzbl -0x29(%rbp), %edi
callq 0x3372
movl -0x38(%rbp), %edi
callq 0x3397
movq %r14, %rdi
leaq 0x3867(%rip), %rsi      # 0x6021
callq 0x2160
movl -0x34(%rbp), %edi
callq 0x3397
testb $0x1, -0x138(%rbp)
je 0x27db
movq %r14, %rdi
movq %r15, %rsi
callq 0x2160
movzbl %bl, %edi
callq 0x3372
movl -0x34(%rbp), %edi
callq 0x3397
cmpb %bl, -0x29(%rbp)
je 0x2806
movq %r14, %rdi
leaq 0x382a(%rip), %rsi      # 0x6024
callq 0x2160
movl $0x0, -0x30(%rbp)
movq %r14, %rdi
leaq 0x38e4(%rip), %rsi      # 0x60f4
callq 0x2160
jmp 0x2707
testb $0x1, -0x30(%rbp)
je 0x2829
leaq 0x3807(%rip), %rsi      # 0x602e
jmp 0x2846
movq 0x67a0(%rip), %rdi      # 0x8fd0
leaq 0x3829(%rip), %rsi      # 0x6060
callq 0x2160
movq %rax, %r14
leaq 0x384d(%rip), %rsi      # 0x6093
movq %r14, %rdi
callq 0x2160
leaq -0x1b0(%rbp), %rdi
callq 0x3b1a
leaq -0x140(%rbp), %rdi
callq 0x20c0
leaq -0x160(%rbp), %rdi
callq 0x20c0
leaq -0xe0(%rbp), %rdi
callq 0x3870
leaq -0x100(%rbp), %rdi
callq 0x3870
leaq -0x80(%rbp), %rdi
callq 0x3870
leaq -0x180(%rbp), %rdi
callq 0x3870
leaq -0x120(%rbp), %rdi
callq 0x3870
leaq -0xa0(%rbp), %rdi
callq 0x3870
leaq -0xc0(%rbp), %rdi
callq 0x3870
xorl %eax, %eax
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x28db
jmp 0x2901
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x20c0
jmp 0x2904
jmp 0x2901
jmp 0x2901
jmp 0x2901
jmp 0x2901
jmp 0x2901
jmp 0x2901
jmp 0x2901
jmp 0x2901
jmp 0x2901
jmp 0x2901
jmp 0x2901
jmp 0x2901
movq %rax, %rbx
leaq -0x1b0(%rbp), %rdi
callq 0x3b1a
leaq -0x140(%rbp), %rdi
callq 0x20c0
leaq -0x160(%rbp), %rdi
callq 0x20c0
leaq -0xe0(%rbp), %rdi
callq 0x3870
leaq -0x100(%rbp), %rdi
callq 0x3870
leaq -0x80(%rbp), %rdi
callq 0x3870
leaq -0x180(%rbp), %rdi
callq 0x3870
leaq -0x120(%rbp), %rdi
callq 0x3870
leaq -0xa0(%rbp), %rdi
callq 0x3870
leaq -0xc0(%rbp), %rdi
callq 0x3870
movq %rbx, %rdi
callq 0x2240