// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movq %rsi, %rbx
movl %edi, 0x18(%rsp)
movb $0x0, 0x16(%rsp)
leaq 0x90(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xd688(%rip), %rsi      # 0x13004
leaq 0xd68e(%rip), %rdx      # 0x13011
leaq 0x80(%rsp), %rdi
callq 0x5fce
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0xd672(%rip), %rsi      # 0x13012
leaq 0xd678(%rip), %rdx      # 0x1301f
leaq 0x60(%rsp), %rdi
callq 0x5fce
movl $0x0, 0x1c(%rsp)
cmpl $0x0, 0x18(%rsp)
jle 0x5c21
xorl %r15d, %r15d
leaq 0x40(%rsp), %r14
leaq 0x20(%rsp), %rbp
movslq %r15d, %r12
movq (%rbx,%r12,8), %rsi
movq %r14, %rdi
movq %rbp, %rdx
callq 0x5f20
movq %r14, %rdi
leaq 0xd633(%rip), %rsi      # 0x13020
callq 0x50d0
testl %eax, %eax
jne 0x59fb
movb $0x1, 0x16(%rsp)
movq %r14, %rdi
leaq 0xd621(%rip), %rsi      # 0x13026
callq 0x50d0
testl %eax, %eax
jne 0x5ab6
movq 0x8(%rbx,%r12,8), %rsi
movq %rbp, %rdi
leaq 0x17(%rsp), %rdx
callq 0x5f20
movq 0x20(%rsp), %r12
callq 0x5050
movq %rax, %r13
movl (%rax), %ebp
movl $0x0, (%rax)
movq %r12, %rdi
leaq 0xa0(%rsp), %rsi
movl $0xa, %edx
callq 0x53d0
cmpq %r12, 0xa0(%rsp)
je 0x5c97
leaq -0x80000000(%rax), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rcx
jb 0x5ca3
movl (%r13), %ecx
cmpl $0x22, %ecx
je 0x5ca3
testl %ecx, %ecx
jne 0x5a8b
movl %ebp, (%r13)
movl %eax, %edi
callq 0x52a0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x5aae
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x52e0
incl %r15d
leaq 0x20(%rsp), %rbp
movq %r14, %rdi
leaq 0xd56c(%rip), %rsi      # 0x1302c
callq 0x50d0
testl %eax, %eax
jne 0x5afc
movslq %r15d, %rax
movq 0x8(%rbx,%rax,8), %r12
movq 0x88(%rsp), %r13
movq %r12, %rdi
callq 0x5160
leaq 0x80(%rsp), %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r12, %rcx
movq %rax, %r8
callq 0x5440
incl %r15d
movq %r14, %rdi
leaq 0xd533(%rip), %rsi      # 0x13039
callq 0x50d0
testl %eax, %eax
jne 0x5b3c
movslq %r15d, %rax
movq 0x8(%rbx,%rax,8), %r12
movq 0x68(%rsp), %r13
movq %r12, %rdi
callq 0x5160
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
movq %r13, %rdx
movq %r12, %rcx
movq %rax, %r8
callq 0x5440
incl %r15d
movq %r14, %rdi
leaq 0xd500(%rip), %rsi      # 0x13046
callq 0x50d0
testl %eax, %eax
jne 0x5bf7
movslq %r15d, %rax
movq 0x8(%rbx,%rax,8), %rsi
movq %rbp, %rdi
leaq 0x17(%rsp), %rdx
callq 0x5f20
movq 0x20(%rsp), %r12
callq 0x5050
movq %rax, %r13
movl (%rax), %ebp
movl $0x0, (%rax)
movq %r12, %rdi
leaq 0xa0(%rsp), %rsi
movl $0xa, %edx
callq 0x53d0
cmpq %r12, 0xa0(%rsp)
je 0x5caf
leaq -0x80000000(%rax), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rcx
jb 0x5cbb
movl (%r13), %ecx
cmpl $0x22, %ecx
je 0x5cbb
testl %ecx, %ecx
jne 0x5bcf
movl %ebp, (%r13)
movl %eax, 0x1c(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x5bef
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x52e0
incl %r15d
leaq 0x20(%rsp), %rbp
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x5c13
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x52e0
incl %r15d
cmpl 0x18(%rsp), %r15d
jl 0x59d1
leaq 0x48(%rsp), %rdi
movq $0x0, -0x8(%rdi)
leaq 0x16(%rsp), %rax
movq %rax, (%rsp)
leaq 0x40(%rsp), %rsi
leaq 0x20(%rsp), %rdx
leaq 0x80(%rsp), %rcx
leaq 0x60(%rsp), %r8
leaq 0x1c(%rsp), %r9
callq 0x6064
movq 0x40(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x20(%rax), %rsi
movq 0x16344(%rip), %rdi     # 0x1bfb0
leaq 0x90(%rsp), %r14
callq 0xf0e4
movq %rax, %rdi
callq 0x5170
movq 0x16348(%rip), %rbx     # 0x1bfd0
movq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0x708a
jmp 0x5c88
leaq 0xd419(%rip), %rdi      # 0x130b7
callq 0x51e0
leaq 0xd40d(%rip), %rdi      # 0x130b7
callq 0x53f0
leaq 0xd401(%rip), %rdi      # 0x130b7
callq 0x51e0
leaq 0xd3f5(%rip), %rdi      # 0x130b7
callq 0x53f0
jmp 0x5e80
jmp 0x5e80
jmp 0x5e47
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x5eb3
movq %rbx, %rdi
callq 0x5150
movq 0x162bf(%rip), %rdi     # 0x1bfb0
movq %rax, %rsi
callq 0x52c0
movq %rax, %rdi
callq 0x5170
callq 0x54a0
movq 0x162a3(%rip), %rdi     # 0x1bfb0
leaq 0xd33e(%rip), %rsi      # 0x13052
movl $0x7, %edx
callq 0x5320
movq 0x40(%rsp), %rax
movq 0x60(%rax), %rax
movl 0x44(%rax), %esi
incl %esi
movq 0x1627d(%rip), %rdi     # 0x1bfb0
callq 0x54d0
movq %rax, %rbx
leaq 0xd318(%rip), %rsi      # 0x1305a
movl $0xa, %edx
movq %rax, %rdi
callq 0x5320
movq %rbx, %rdi
callq 0x5170
movq 0x40(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x20(%rax), %rdi
xorl %esi, %esi
callq 0xf9c4
movl %eax, %ebx
movq 0x40(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x20(%rax), %rdi
movl $0x1, %esi
callq 0xf9c4
xorl %esi, %esi
cmpl %eax, %ebx
setle %sil
movq 0x40(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x20(%rax), %rdi
callq 0xf9c4
movl %eax, %ebx
movq 0x40(%rsp), %rax
movq 0x60(%rax), %rax
cmpl %ebx, 0x40(%rax)
jge 0x5ddf
movl %ebx, 0x40(%rax)
movq 0x161f8(%rip), %rdi     # 0x1bfb0
leaq 0xd2a6(%rip), %rsi      # 0x13065
movl $0x51, %edx
callq 0x5320
movq 0x161e0(%rip), %rdi     # 0x1bfb0
movl %ebx, %esi
callq 0x54d0
movq %rax, %rdi
callq 0x5170
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
leaq 0x70(%rsp), %rbx
je 0x5df3
callq 0x5f5e
movq 0x60(%rsp), %rdi
cmpq %rbx, %rdi
je 0x5e0a
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x52e0
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0x5e27
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x52e0
xorl %eax, %eax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
callq 0x54a0
jmp 0x5eb3
jmp 0x5eb0
movq %rax, %rbx
cmpl $0x0, (%r13)
leaq 0x90(%rsp), %r14
leaq 0x70(%rsp), %r15
jne 0x5e62
movl %ebp, (%r13)
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x5e90
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x52e0
jmp 0x5e90
movq %rax, %rbx
leaq 0x90(%rsp), %r14
leaq 0x70(%rsp), %r15
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x5ed9
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x52e0
jmp 0x5ed9
jmp 0x5ec9
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
leaq 0x70(%rsp), %r15
je 0x5ed9
callq 0x5f5e
jmp 0x5ed9
movq %rax, %rbx
leaq 0x90(%rsp), %r14
leaq 0x70(%rsp), %r15
movq 0x60(%rsp), %rdi
cmpq %r15, %rdi
je 0x5ef5
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x52e0
jmp 0x5ef5
movq %rax, %rbx
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0x5f17
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x52e0
jmp 0x5f17
movq %rax, %rbx
movq %rbx, %rdi
callq 0x54e0
nop