// File: /workspace/github_cpp_makefile_star2_O1/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 0xd6a8(%rip), %rsi      # 0x13004
leaq 0xd6ae(%rip), %rdx      # 0x13011
leaq 0x80(%rsp), %rdi
callq 0x5fae
leaq 0x70(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0xd692(%rip), %rsi      # 0x13012
leaq 0xd698(%rip), %rdx      # 0x1301f
leaq 0x60(%rsp), %rdi
callq 0x5fae
movl $0x0, 0x1c(%rsp)
cmpl $0x0, 0x18(%rsp)
jle 0x5c01
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 0x5f00
movq %r14, %rdi
leaq 0xd653(%rip), %rsi      # 0x13020
callq 0x50d0
testl %eax, %eax
jne 0x59db
movb $0x1, 0x16(%rsp)
movq %r14, %rdi
leaq 0xd641(%rip), %rsi      # 0x13026
callq 0x50d0
testl %eax, %eax
jne 0x5a96
movq 0x8(%rbx,%r12,8), %rsi
movq %rbp, %rdi
leaq 0x17(%rsp), %rdx
callq 0x5f00
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 0x5c77
leaq -0x80000000(%rax), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rcx
jb 0x5c83
movl (%r13), %ecx
cmpl $0x22, %ecx
je 0x5c83
testl %ecx, %ecx
jne 0x5a6b
movl %ebp, (%r13)
movl %eax, %edi
callq 0x52a0
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x5a8e
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x52e0
incl %r15d
leaq 0x20(%rsp), %rbp
movq %r14, %rdi
leaq 0xd58c(%rip), %rsi      # 0x1302c
callq 0x50d0
testl %eax, %eax
jne 0x5adc
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 0xd553(%rip), %rsi      # 0x13039
callq 0x50d0
testl %eax, %eax
jne 0x5b1c
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 0xd520(%rip), %rsi      # 0x13046
callq 0x50d0
testl %eax, %eax
jne 0x5bd7
movslq %r15d, %rax
movq 0x8(%rbx,%rax,8), %rsi
movq %rbp, %rdi
leaq 0x17(%rsp), %rdx
callq 0x5f00
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 0x5c8f
leaq -0x80000000(%rax), %rcx
movabsq $-0x100000000, %rdx     # imm = 0xFFFFFFFF00000000
cmpq %rdx, %rcx
jb 0x5c9b
movl (%r13), %ecx
cmpl $0x22, %ecx
je 0x5c9b
testl %ecx, %ecx
jne 0x5baf
movl %ebp, (%r13)
movl %eax, 0x1c(%rsp)
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x5bcf
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 0x5bf3
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x52e0
incl %r15d
cmpl 0x18(%rsp), %r15d
jl 0x59b1
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 0x603e
movq 0x40(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x20(%rax), %rsi
movq 0x16364(%rip), %rdi     # 0x1bfb0
leaq 0x90(%rsp), %r14
callq 0xf390
movq %rax, %rdi
callq 0x5170
movq 0x16368(%rip), %rbx     # 0x1bfd0
movq 0x40(%rsp), %rdi
movq %rbx, %rsi
callq 0x7060
jmp 0x5c68
leaq 0xd439(%rip), %rdi      # 0x130b7
callq 0x51e0
leaq 0xd42d(%rip), %rdi      # 0x130b7
callq 0x53f0
leaq 0xd421(%rip), %rdi      # 0x130b7
callq 0x51e0
leaq 0xd415(%rip), %rdi      # 0x130b7
callq 0x53f0
jmp 0x5e60
jmp 0x5e60
jmp 0x5e27
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x5e93
movq %rbx, %rdi
callq 0x5150
movq 0x162df(%rip), %rdi     # 0x1bfb0
movq %rax, %rsi
callq 0x52c0
movq %rax, %rdi
callq 0x5170
callq 0x54a0
movq 0x162c3(%rip), %rdi     # 0x1bfb0
leaq 0xd35e(%rip), %rsi      # 0x13052
movl $0x7, %edx
callq 0x5320
movq 0x40(%rsp), %rax
movq 0x60(%rax), %rax
movl 0x44(%rax), %esi
incl %esi
movq 0x1629d(%rip), %rdi     # 0x1bfb0
callq 0x54d0
movq %rax, %rbx
leaq 0xd338(%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 0xfbe0
movl %eax, %ebx
movq 0x40(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x20(%rax), %rdi
movl $0x1, %esi
callq 0xfbe0
xorl %esi, %esi
cmpl %eax, %ebx
setle %sil
movq 0x40(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x20(%rax), %rdi
callq 0xfbe0
movl %eax, %ebx
movq 0x40(%rsp), %rax
movq 0x60(%rax), %rax
cmpl %ebx, 0x40(%rax)
jge 0x5dbf
movl %ebx, 0x40(%rax)
movq 0x16218(%rip), %rdi     # 0x1bfb0
leaq 0xd2c6(%rip), %rsi      # 0x13065
movl $0x51, %edx
callq 0x5320
movq 0x16200(%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 0x5dd3
callq 0x5f3e
movq 0x60(%rsp), %rdi
cmpq %rbx, %rdi
je 0x5dea
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x52e0
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0x5e07
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 0x5e93
jmp 0x5e90
movq %rax, %rbx
cmpl $0x0, (%r13)
leaq 0x90(%rsp), %r14
leaq 0x70(%rsp), %r15
jne 0x5e42
movl %ebp, (%r13)
movq 0x20(%rsp), %rdi
leaq 0x30(%rsp), %rax
cmpq %rax, %rdi
je 0x5e70
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x52e0
jmp 0x5e70
movq %rax, %rbx
leaq 0x90(%rsp), %r14
leaq 0x70(%rsp), %r15
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rax
cmpq %rax, %rdi
je 0x5eb9
movq 0x50(%rsp), %rsi
incq %rsi
callq 0x52e0
jmp 0x5eb9
jmp 0x5ea9
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
leaq 0x70(%rsp), %r15
je 0x5eb9
callq 0x5f3e
jmp 0x5eb9
movq %rax, %rbx
leaq 0x90(%rsp), %r14
leaq 0x70(%rsp), %r15
movq 0x60(%rsp), %rdi
cmpq %r15, %rdi
je 0x5ed5
movq 0x70(%rsp), %rsi
incq %rsi
callq 0x52e0
jmp 0x5ed5
movq %rax, %rbx
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0x5ef7
movq 0x90(%rsp), %rsi
incq %rsi
callq 0x52e0
jmp 0x5ef7
movq %rax, %rbx
movq %rbx, %rdi
callq 0x54e0
nop