// File: MatthewZMD[P]TetrisDual/main.cc
// Function: main
int main(int argc, char* argv[]) {
    // True for text-only display, false showing both text and graphics
    bool textOnly = false;
    // Filenames for 2 players
    std::string fileName1 = "sequence1.txt", fileName2 = "sequence2.txt";
    // Starting level, default to 0
    int startLevel = 0;
    // Configure initial arguments
    for(int i = 0; i < argc; ++i){
        std::string arg = argv[i];
        if(arg == "-text"){
            textOnly = true;
        }
        if(arg == "-seed"){
            // Configure seed for RNG
            srand(std::stoi(argv[++i]));
        }
        if(arg == "-scriptfile1"){
            fileName1 = argv[++i];
        }
        if(arg == "-scriptfile2"){
            fileName2 = argv[++i];
        }
        if(arg == "-startlevel"){
            startLevel = std::stoi(argv[++i]);
        }
    }

    std::shared_ptr<Interface> i = std::make_shared<Interface>(fileName1, fileName2, startLevel, textOnly);

    std::cout << *(i->g->display) << std::endl;

    while(true){
        try{
            // Read command
            i->cmdInterface(std::cin);
        } catch (const char* s){
            // Game Over
            std::cout << s << std::endl;
            break;
        }
    }
    // Game finished
    std::cout << "Player " << i->g->playerTurn + 1 << " has lost!" << std::endl;
    int thisHi = i->g->display->getScore(0) > i->g->display->getScore(1) ? i->g->display->getScore(0) : i->g->display->getScore(1);
    if(i->g->hiScore < thisHi){
        i->g->hiScore = thisHi;
        std::cout << "Congratulations! You have achieved the most useless high score you can ever get: " << thisHi << std::endl;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1d0, %rsp            # imm = 0x1D0
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb $0x0, -0x11(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x6640
movq -0x120(%rbp), %rdx
leaq 0x26619(%rip), %rsi     # 0x2d004
leaq -0x38(%rbp), %rdi
callq 0x7180
jmp 0x69f6
leaq -0x39(%rbp), %rdi
callq 0x63c0
leaq -0x71(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x6640
movq -0x128(%rbp), %rdx
leaq 0x265f5(%rip), %rsi     # 0x2d012
leaq -0x70(%rbp), %rdi
callq 0x7180
jmp 0x6a28
leaq -0x71(%rbp), %rdi
callq 0x63c0
movl $0x0, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x6db8
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x138(%rbp)
leaq -0xa1(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x6640
movq -0x138(%rbp), %rsi
movq -0x130(%rbp), %rdx
leaq -0xa0(%rbp), %rdi
callq 0x7180
jmp 0x6a8d
leaq -0xa1(%rbp), %rdi
callq 0x63c0
leaq 0x26580(%rip), %rsi     # 0x2d020
leaq -0xa0(%rbp), %rdi
callq 0x7230
movb %al, -0x139(%rbp)
jmp 0x6ab4
movb -0x139(%rbp), %al
testb $0x1, %al
jne 0x6ac0
jmp 0x6b28
movb $0x1, -0x11(%rbp)
jmp 0x6b28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x39(%rbp), %rdi
callq 0x63c0
jmp 0x7169
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x71(%rbp), %rdi
callq 0x63c0
jmp 0x7160
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xa1(%rbp), %rdi
callq 0x63c0
jmp 0x7157
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x6da7
leaq 0x264f7(%rip), %rsi     # 0x2d026
leaq -0xa0(%rbp), %rdi
callq 0x7230
movb %al, -0x13a(%rbp)
jmp 0x6b43
movb -0x13a(%rbp), %al
testb $0x1, %al
jne 0x6b52
jmp 0x6c15
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl %ecx, %edx
incl %edx
movl %edx, -0x7c(%rbp)
movq 0x8(%rax,%rcx,8), %rax
movq %rax, -0x150(%rbp)
leaq -0xc9(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x6640
movq -0x150(%rbp), %rsi
movq -0x148(%rbp), %rdx
leaq -0xc8(%rbp), %rdi
callq 0x7180
jmp 0x6b9c
xorl %eax, %eax
movl %eax, %esi
leaq -0xc8(%rbp), %rdi
movl $0xa, %edx
callq 0x7260
movl %eax, -0x154(%rbp)
jmp 0x6bb9
movl -0x154(%rbp), %edi
callq 0x6340
leaq -0xc8(%rbp), %rdi
callq 0x6230
leaq -0xc9(%rbp), %rdi
callq 0x63c0
jmp 0x6c15
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x6c04
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x6230
leaq -0xc9(%rbp), %rdi
callq 0x63c0
jmp 0x6da7
leaq 0x26410(%rip), %rsi     # 0x2d02c
leaq -0xa0(%rbp), %rdi
callq 0x7230
movb %al, -0x155(%rbp)
jmp 0x6c30
movb -0x155(%rbp), %al
testb $0x1, %al
jne 0x6c3c
jmp 0x6c5d
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl %ecx, %edx
incl %edx
movl %edx, -0x7c(%rbp)
movq 0x8(%rax,%rcx,8), %rsi
leaq -0x38(%rbp), %rdi
callq 0x64d0
jmp 0x6c5b
jmp 0x6c5d
leaq 0x263d5(%rip), %rsi     # 0x2d039
leaq -0xa0(%rbp), %rdi
callq 0x7230
movb %al, -0x156(%rbp)
jmp 0x6c78
movb -0x156(%rbp), %al
testb $0x1, %al
jne 0x6c84
jmp 0x6ca5
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl %ecx, %edx
incl %edx
movl %edx, -0x7c(%rbp)
movq 0x8(%rax,%rcx,8), %rsi
leaq -0x70(%rbp), %rdi
callq 0x64d0
jmp 0x6ca3
jmp 0x6ca5
leaq 0x2639a(%rip), %rsi     # 0x2d046
leaq -0xa0(%rbp), %rdi
callq 0x7230
movb %al, -0x157(%rbp)
jmp 0x6cc0
movb -0x157(%rbp), %al
testb $0x1, %al
jne 0x6ccf
jmp 0x6d8d
movq -0x10(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl %ecx, %edx
incl %edx
movl %edx, -0x7c(%rbp)
movq 0x8(%rax,%rcx,8), %rax
movq %rax, -0x168(%rbp)
leaq -0xf1(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x6640
movq -0x168(%rbp), %rsi
movq -0x160(%rbp), %rdx
leaq -0xf0(%rbp), %rdi
callq 0x7180
jmp 0x6d19
xorl %eax, %eax
movl %eax, %esi
leaq -0xf0(%rbp), %rdi
movl $0xa, %edx
callq 0x7260
movl %eax, -0x16c(%rbp)
jmp 0x6d36
movl -0x16c(%rbp), %eax
movl %eax, -0x78(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x6230
leaq -0xf1(%rbp), %rdi
callq 0x63c0
jmp 0x6d8d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x6d7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x6230
leaq -0xf1(%rbp), %rdi
callq 0x63c0
jmp 0x6da7
leaq -0xa0(%rbp), %rdi
callq 0x6230
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x6a3f
leaq -0xa0(%rbp), %rdi
callq 0x6230
jmp 0x7157
leaq -0x108(%rbp), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x70(%rbp), %rdx
leaq -0x78(%rbp), %rcx
leaq -0x11(%rbp), %r8
callq 0x72a0
jmp 0x6dd6
leaq -0x108(%rbp), %rdi
callq 0x7330
movq %rax, %rdi
addq $0x60, %rdi
callq 0x7350
movq %rax, %rdi
addq $0x20, %rdi
callq 0x7370
movq %rax, %rsi
movq 0x3d1a4(%rip), %rdi     # 0x43fa8
callq 0x25e90
movq %rax, -0x178(%rbp)
jmp 0x6e12
movq -0x178(%rbp), %rdi
movq 0x3d160(%rip), %rsi     # 0x43f80
callq 0x63a0
jmp 0x6e27
jmp 0x6e29
jmp 0x6e2b
leaq -0x108(%rbp), %rdi
callq 0x7330
movq %rax, %rdi
movq 0x3d18f(%rip), %rsi     # 0x43fd0
callq 0x9e40
jmp 0x6e48
jmp 0x6ee9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x7157
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x714b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movl $0x1, %ecx
cmpl %ecx, %eax
jne 0x714b
movq -0x48(%rbp), %rdi
callq 0x6160
movq %rax, -0x110(%rbp)
movq -0x110(%rbp), %rsi
movq 0x3d0ff(%rip), %rdi     # 0x43fa8
callq 0x6350
movq %rax, -0x180(%rbp)
jmp 0x6eb7
movq -0x180(%rbp), %rdi
movq 0x3d0bb(%rip), %rsi     # 0x43f80
callq 0x63a0
jmp 0x6ecc
callq 0x65e0
jmp 0x6eee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
callq 0x65e0
jmp 0x714b
jmp 0x6e29
movq 0x3d0b3(%rip), %rdi     # 0x43fa8
leaq 0x26156(%rip), %rsi     # 0x2d052
callq 0x6350
movq %rax, -0x188(%rbp)
jmp 0x6f0a
leaq -0x108(%rbp), %rdi
callq 0x7330
movq %rax, %rdi
addq $0x60, %rdi
callq 0x7350
movq -0x188(%rbp), %rdi
movl 0x44(%rax), %esi
incl %esi
callq 0x6620
movq %rax, -0x190(%rbp)
jmp 0x6f3c
movq -0x190(%rbp), %rdi
leaq 0x26110(%rip), %rsi     # 0x2d05a
callq 0x6350
movq %rax, -0x198(%rbp)
jmp 0x6f58
movq -0x198(%rbp), %rdi
movq 0x3d01a(%rip), %rsi     # 0x43f80
callq 0x63a0
jmp 0x6f6d
leaq -0x108(%rbp), %rdi
callq 0x7330
movq %rax, %rdi
addq $0x60, %rdi
callq 0x7350
movq %rax, %rdi
addq $0x20, %rdi
callq 0x73a0
movq %rax, %rdi
xorl %esi, %esi
callq 0x269b0
movl %eax, -0x19c(%rbp)
jmp 0x6fa3
leaq -0x108(%rbp), %rdi
callq 0x7330
movq %rax, %rdi
addq $0x60, %rdi
callq 0x7350
movq %rax, %rdi
addq $0x20, %rdi
callq 0x73a0
movq %rax, %rdi
movl $0x1, %esi
callq 0x269b0
movl %eax, -0x1a0(%rbp)
jmp 0x6fdc
movl -0x19c(%rbp), %eax
movl -0x1a0(%rbp), %ecx
cmpl %ecx, %eax
jle 0x7030
leaq -0x108(%rbp), %rdi
callq 0x7330
movq %rax, %rdi
addq $0x60, %rdi
callq 0x7350
movq %rax, %rdi
addq $0x20, %rdi
callq 0x73a0
movq %rax, %rdi
xorl %esi, %esi
callq 0x269b0
movl %eax, -0x1a4(%rbp)
jmp 0x7022
movl -0x1a4(%rbp), %eax
movl %eax, -0x1a8(%rbp)
jmp 0x7077
leaq -0x108(%rbp), %rdi
callq 0x7330
movq %rax, %rdi
addq $0x60, %rdi
callq 0x7350
movq %rax, %rdi
addq $0x20, %rdi
callq 0x73a0
movq %rax, %rdi
movl $0x1, %esi
callq 0x269b0
movl %eax, -0x1ac(%rbp)
jmp 0x7069
movl -0x1ac(%rbp), %eax
movl %eax, -0x1a8(%rbp)
jmp 0x7077
movl -0x1a8(%rbp), %eax
movl %eax, -0x114(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x7330
movq %rax, %rdi
addq $0x60, %rdi
callq 0x7350
movl 0x40(%rax), %eax
cmpl -0x114(%rbp), %eax
jge 0x7121
movl -0x114(%rbp), %eax
movl %eax, -0x1bc(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x7330
movq %rax, %rdi
addq $0x60, %rdi
callq 0x7350
movl -0x1bc(%rbp), %ecx
movl %ecx, 0x40(%rax)
movq 0x3cece(%rip), %rdi     # 0x43fa8
leaq 0x25f84(%rip), %rsi     # 0x2d065
callq 0x6350
movq %rax, -0x1b8(%rbp)
jmp 0x70ef
movq -0x1b8(%rbp), %rdi
movl -0x114(%rbp), %esi
callq 0x6620
movq %rax, -0x1c8(%rbp)
jmp 0x710a
movq -0x1c8(%rbp), %rdi
movq 0x3ce68(%rip), %rsi     # 0x43f80
callq 0x63a0
jmp 0x711f
jmp 0x7121
leaq -0x108(%rbp), %rdi
callq 0x73c0
leaq -0x70(%rbp), %rdi
callq 0x6230
leaq -0x38(%rbp), %rdi
callq 0x6230
movl -0x4(%rbp), %eax
addq $0x1d0, %rsp            # imm = 0x1D0
popq %rbp
retq
leaq -0x108(%rbp), %rdi
callq 0x73c0
leaq -0x70(%rbp), %rdi
callq 0x6230
leaq -0x38(%rbp), %rdi
callq 0x6230
movq -0x48(%rbp), %rdi
callq 0x6630
nopw %cs:(%rax,%rax)
nopl (%rax)