// File: 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
subq $0x320, %rsp            # imm = 0x320
movl $0x0, -0x4(%rbp)
leaq -0x20(%rbp), %rdi
callq 0x4d90
leaq -0x38(%rbp), %rdi
callq 0x4d90
leaq -0x50(%rbp), %rdi
callq 0x4d90
leaq -0x68(%rbp), %rdi
callq 0x4d90
leaq -0x80(%rbp), %rdi
callq 0x4d90
leaq -0x98(%rbp), %rdi
callq 0x4d90
leaq -0xb0(%rbp), %rdi
callq 0x4d90
leaq -0xd0(%rbp), %rdi
callq 0x2240
leaq -0xf0(%rbp), %rdi
callq 0x2240
leaq -0x120(%rbp), %rdi
callq 0x4db0
movq 0xfb2e(%rip), %rdi      # 0x11fd0
leaq 0x9b6b(%rip), %rsi      # 0xc014
callq 0x2190
jmp 0x24b0
movq 0xfb29(%rip), %rdi      # 0x11fe0
leaq -0xd0(%rbp), %rsi
callq 0x2060
jmp 0x24c5
movq 0xfb04(%rip), %rdi      # 0x11fd0
leaq 0x9b4b(%rip), %rsi      # 0xc01e
callq 0x2190
jmp 0x24da
movq 0xfaff(%rip), %rdi      # 0x11fe0
leaq -0xf0(%rbp), %rsi
callq 0x2060
jmp 0x24ef
leaq -0x150(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x2d70
jmp 0x2504
leaq -0x20(%rbp), %rdi
leaq -0x150(%rbp), %rsi
movq %rsi, -0x280(%rbp)
callq 0x4dd0
movq -0x280(%rbp), %rdi
callq 0x4e00
leaq -0x168(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x2d70
jmp 0x253c
leaq -0x38(%rbp), %rdi
leaq -0x168(%rbp), %rsi
movq %rsi, -0x288(%rbp)
callq 0x4dd0
movq -0x288(%rbp), %rdi
callq 0x4e00
leaq -0x180(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x3330
jmp 0x2571
leaq -0x50(%rbp), %rdi
leaq -0x180(%rbp), %rsi
movq %rsi, -0x290(%rbp)
callq 0x4dd0
movq -0x290(%rbp), %rdi
callq 0x4e00
leaq -0x198(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3330
jmp 0x25a6
leaq -0x68(%rbp), %rdi
movq %rdi, -0x298(%rbp)
leaq -0x198(%rbp), %rsi
movq %rsi, -0x2a0(%rbp)
callq 0x4dd0
movq -0x2a0(%rbp), %rdi
callq 0x4e00
movq -0x298(%rbp), %rdx
leaq -0x1b0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3530
jmp 0x25e9
leaq -0x80(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
movq %rsi, -0x2a8(%rbp)
callq 0x4dd0
movq -0x2a8(%rbp), %rdi
callq 0x4e00
leaq -0x1c8(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x3690
jmp 0x261e
leaq -0x98(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
movq %rsi, -0x2b0(%rbp)
callq 0x4dd0
movq -0x2b0(%rbp), %rdi
callq 0x4e00
leaq -0x1e0(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x3690
jmp 0x2656
leaq -0xb0(%rbp), %rdi
leaq -0x1e0(%rbp), %rsi
movq %rsi, -0x2c0(%rbp)
callq 0x4dd0
movq -0x2c0(%rbp), %rdi
callq 0x4e00
movb $0x1, -0x1e1(%rbp)
leaq -0x209(%rbp), %rdi
movq %rdi, -0x2b8(%rbp)
callq 0x22d0
movq -0x2b8(%rbp), %rdx
leaq 0x9987(%rip), %rsi      # 0xc02b
leaq -0x208(%rbp), %rdi
callq 0x2230
jmp 0x26b2
leaq -0x120(%rbp), %rdi
leaq -0x208(%rbp), %rsi
callq 0x4e60
movq %rax, -0x2c8(%rbp)
jmp 0x26ce
movq -0x2c8(%rbp), %rax
movb $0x0, (%rax)
leaq -0x208(%rbp), %rdi
callq 0x2100
leaq -0x209(%rbp), %rdi
callq 0x21d0
leaq -0x231(%rbp), %rdi
movq %rdi, -0x2d0(%rbp)
callq 0x22d0
movq -0x2d0(%rbp), %rdx
leaq 0x9a9b(%rip), %rsi      # 0xc1ac
leaq -0x230(%rbp), %rdi
callq 0x2230
jmp 0x271f
leaq -0x120(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x4e60
movq %rax, -0x2d8(%rbp)
jmp 0x273b
movq -0x2d8(%rbp), %rax
movb $0x1, (%rax)
leaq -0x230(%rbp), %rdi
callq 0x2100
leaq -0x231(%rbp), %rdi
callq 0x21d0
movl $0x1, -0x238(%rbp)
movl $0x0, -0x23c(%rbp)
movslq -0x23c(%rbp), %rax
movq %rax, -0x2e0(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x4f40
movq %rax, %rcx
movq -0x2e0(%rbp), %rax
cmpq %rcx, %rax
jae 0x2857
movl -0x238(%rbp), %eax
shll %eax
movl %eax, -0x238(%rbp)
movl -0x23c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x23c(%rbp)
jmp 0x2771
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
jmp 0x2cef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
jmp 0x2803
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
leaq -0x208(%rbp), %rdi
callq 0x2100
leaq -0x209(%rbp), %rdi
callq 0x21d0
jmp 0x2cef
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
jmp 0x2846
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x130(%rbp)
movl %eax, -0x134(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x2100
leaq -0x231(%rbp), %rdi
callq 0x21d0
jmp 0x2cef
movl -0x238(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x238(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x2270
movl %eax, -0x240(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x2270
movl %eax, -0x244(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x4f60
movq %rax, -0x258(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x258(%rbp), %rsi
callq 0x4f90
leaq -0x80(%rbp), %rdi
callq 0x5010
movq %rax, -0x260(%rbp)
leaq -0x250(%rbp), %rdi
leaq -0x260(%rbp), %rsi
callq 0x4fd0
testb $0x1, %al
jne 0x28d6
jmp 0x291f
leaq -0x250(%rbp), %rdi
callq 0x5040
movq %rax, %rsi
movq 0xf6e4(%rip), %rdi      # 0x11fd0
callq 0x2170
movq %rax, -0x2e8(%rbp)
jmp 0x28fa
movq -0x2e8(%rbp), %rdi
leaq 0x9714(%rip), %rsi      # 0xc01c
callq 0x2190
jmp 0x290f
jmp 0x2911
leaq -0x250(%rbp), %rdi
callq 0x5060
jmp 0x28ad
movq 0xf6aa(%rip), %rdi      # 0x11fd0
leaq 0x9701(%rip), %rsi      # 0xc02e
callq 0x2190
jmp 0x2934
movq 0xf695(%rip), %rdi      # 0x11fd0
leaq -0xd0(%rbp), %rsi
callq 0x2170
movq %rax, -0x2f0(%rbp)
jmp 0x2950
movq -0x2f0(%rbp), %rdi
leaq 0x96cf(%rip), %rsi      # 0xc02d
callq 0x2190
movq %rax, -0x2f8(%rbp)
jmp 0x296c
movq -0x2f8(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x2170
movq %rax, -0x300(%rbp)
jmp 0x2988
movq -0x300(%rbp), %rdi
leaq 0x976e(%rip), %rsi      # 0xc104
callq 0x2190
jmp 0x299d
jmp 0x299f
cmpl $0x0, -0x238(%rbp)
jl 0x2c20
movl -0x238(%rbp), %edx
leaq -0x120(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x3b00
jmp 0x29c4
leaq -0x98(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x3bc0
movb %al, -0x301(%rbp)
jmp 0x29df
movb -0x301(%rbp), %al
andb $0x1, %al
movb %al, -0x121(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x3bc0
movb %al, -0x302(%rbp)
jmp 0x2a08
movb -0x302(%rbp), %al
andb $0x1, %al
movb %al, -0x122(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x4f60
movq %rax, -0x270(%rbp)
leaq -0x268(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x4f90
leaq -0x80(%rbp), %rdi
callq 0x5010
movq %rax, -0x278(%rbp)
leaq -0x268(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x4fd0
testb $0x1, %al
jne 0x2a62
jmp 0x2ac2
leaq -0x268(%rbp), %rdi
callq 0x5040
movq %rax, %rsi
leaq -0x120(%rbp), %rdi
callq 0x5080
movq %rax, -0x310(%rbp)
jmp 0x2a86
movq -0x310(%rbp), %rax
movzbl (%rax), %edi
andl $0x1, %edi
callq 0x4230
jmp 0x2a9a
movq 0xf52f(%rip), %rdi      # 0x11fd0
leaq 0x9574(%rip), %rsi      # 0xc01c
callq 0x2190
jmp 0x2aaf
jmp 0x2ab1
leaq -0x268(%rbp), %rdi
callq 0x5060
jmp 0x2a39
movq 0xf507(%rip), %rdi      # 0x11fd0
leaq 0x9562(%rip), %rsi      # 0xc032
callq 0x2190
jmp 0x2ad7
movl -0x240(%rbp), %edi
movl %edi, %eax
shrl $0x1f, %eax
addl %eax, %edi
sarl %edi
callq 0x4280
jmp 0x2aed
leaq -0xd0(%rbp), %rdi
callq 0x2270
andq $0x1, %rax
cmpq $0x1, %rax
jne 0x2b1a
movq 0xf4c6(%rip), %rdi      # 0x11fd0
leaq 0x950b(%rip), %rsi      # 0xc01c
callq 0x2190
jmp 0x2b18
jmp 0x2b1a
movzbl -0x121(%rbp), %edi
andl $0x1, %edi
callq 0x4230
jmp 0x2b2b
movl -0x240(%rbp), %edi
movl %edi, %eax
shrl $0x1f, %eax
addl %eax, %edi
sarl %edi
callq 0x4280
jmp 0x2b41
movq 0xf488(%rip), %rdi      # 0x11fd0
leaq 0x94e2(%rip), %rsi      # 0xc031
callq 0x2190
jmp 0x2b56
movl -0x244(%rbp), %edi
movl %edi, %eax
shrl $0x1f, %eax
addl %eax, %edi
sarl %edi
callq 0x4280
jmp 0x2b6c
leaq -0xf0(%rbp), %rdi
callq 0x2270
andq $0x1, %rax
cmpq $0x1, %rax
jne 0x2b99
movq 0xf447(%rip), %rdi      # 0x11fd0
leaq 0x948c(%rip), %rsi      # 0xc01c
callq 0x2190
jmp 0x2b97
jmp 0x2b99
movzbl -0x122(%rbp), %edi
andl $0x1, %edi
callq 0x4230
jmp 0x2baa
movl -0x244(%rbp), %edi
movl %edi, %eax
shrl $0x1f, %eax
addl %eax, %edi
sarl %edi
callq 0x4280
jmp 0x2bc0
movb -0x121(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movb -0x122(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0x2bf7
movq 0xf3ee(%rip), %rdi      # 0x11fd0
leaq 0x944b(%rip), %rsi      # 0xc034
callq 0x2190
jmp 0x2bf0
movb $0x0, -0x1e1(%rbp)
movq 0xf3d2(%rip), %rdi      # 0x11fd0
leaq 0x94ff(%rip), %rsi      # 0xc104
callq 0x2190
jmp 0x2c0c
movl -0x238(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x238(%rbp)
jmp 0x299f
testb $0x1, -0x1e1(%rbp)
je 0x2c40
movq 0xf3a0(%rip), %rdi      # 0x11fd0
leaq 0x9407(%rip), %rsi      # 0xc03e
callq 0x2190
jmp 0x2c3e
jmp 0x2c73
movq 0xf389(%rip), %rdi      # 0x11fd0
leaq 0x9422(%rip), %rsi      # 0xc070
callq 0x2190
movq %rax, -0x318(%rbp)
jmp 0x2c5c
movq -0x318(%rbp), %rdi
leaq 0x9439(%rip), %rsi      # 0xc0a3
callq 0x2190
jmp 0x2c71
jmp 0x2c73
movl $0x0, -0x4(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x5120
leaq -0xf0(%rbp), %rdi
callq 0x2100
leaq -0xd0(%rbp), %rdi
callq 0x2100
leaq -0xb0(%rbp), %rdi
callq 0x4e00
leaq -0x98(%rbp), %rdi
callq 0x4e00
leaq -0x80(%rbp), %rdi
callq 0x4e00
leaq -0x68(%rbp), %rdi
callq 0x4e00
leaq -0x50(%rbp), %rdi
callq 0x4e00
leaq -0x38(%rbp), %rdi
callq 0x4e00
leaq -0x20(%rbp), %rdi
callq 0x4e00
movl -0x4(%rbp), %eax
addq $0x320, %rsp            # imm = 0x320
popq %rbp
retq
leaq -0x120(%rbp), %rdi
callq 0x5120
leaq -0xf0(%rbp), %rdi
callq 0x2100
leaq -0xd0(%rbp), %rdi
callq 0x2100
leaq -0xb0(%rbp), %rdi
callq 0x4e00
leaq -0x98(%rbp), %rdi
callq 0x4e00
leaq -0x80(%rbp), %rdi
callq 0x4e00
leaq -0x68(%rbp), %rdi
callq 0x4e00
leaq -0x50(%rbp), %rdi
callq 0x4e00
leaq -0x38(%rbp), %rdi
callq 0x4e00
leaq -0x20(%rbp), %rdi
callq 0x4e00
movq -0x130(%rbp), %rdi
callq 0x22c0
nopw %cs:(%rax,%rax)