// File: /workspace/github_cpp_makefile_star2_O2/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 $0x88, %rsp
movq %rsi, %rbx
movl %edi, %ebp
movb $0x0, 0x2(%rsp)
leaq 0xb876(%rip), %rsi      # 0x11004
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x5abe
leaq 0xb86e(%rip), %rsi      # 0x11012
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x5abe
andl $0x0, 0x4(%rsp)
xorl %r13d, %r13d
leaq 0x8(%rsp), %r14
leaq 0x68(%rsp), %r15
cmpl %ebp, %r13d
jge 0x58e0
movslq %r13d, %r12
movq (%rbx,%r12,8), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x5abe
movq %r14, %rdi
leaq 0xb836(%rip), %rsi      # 0x11020
callq 0x5af9
testb %al, %al
je 0x57f8
movb $0x1, 0x2(%rsp)
movq %r14, %rdi
leaq 0xb824(%rip), %rsi      # 0x11026
callq 0x5af9
testb %al, %al
je 0x583c
movq 0x8(%rbx,%r12,8), %rsi
movq %r15, %rdi
leaq 0x3(%rsp), %rdx
callq 0x5abe
movq %r15, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x5b06
incl %r13d
movl %eax, %edi
callq 0x5280
movq %r15, %rdi
callq 0x5150
movq %r14, %rdi
leaq 0xb7e6(%rip), %rsi      # 0x1102c
callq 0x5af9
testb %al, %al
je 0x5864
movslq %r13d, %rax
movq 0x8(%rbx,%rax,8), %rsi
leaq 0x48(%rsp), %rdi
callq 0x5530
incl %r13d
movq %r14, %rdi
leaq 0xb7cb(%rip), %rsi      # 0x11039
callq 0x5af9
testb %al, %al
je 0x588c
movslq %r13d, %rax
movq 0x8(%rbx,%rax,8), %rsi
leaq 0x28(%rsp), %rdi
callq 0x5530
incl %r13d
movq %r14, %rdi
leaq 0xb7b0(%rip), %rsi      # 0x11046
callq 0x5af9
testb %al, %al
je 0x58d0
movslq %r13d, %rax
movq 0x8(%rbx,%rax,8), %rsi
movq %r15, %rdi
leaq 0x3(%rsp), %rdx
callq 0x5abe
movq %r15, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x5b06
incl %r13d
movl %eax, 0x4(%rsp)
movq %r15, %rdi
callq 0x5150
movq %r14, %rdi
callq 0x5150
incl %r13d
jmp 0x57c5
leaq 0x8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
leaq 0x28(%rsp), %rdx
leaq 0x4(%rsp), %rcx
leaq 0x2(%rsp), %r8
callq 0x5b22
movq 0x8(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x20(%rax), %rsi
movq 0x16696(%rip), %rdi     # 0x1bfa8
callq 0xde55
movq %rax, %rdi
callq 0x5160
movq 0x166aa(%rip), %rbx     # 0x1bfd0
movq 0x8(%rsp), %rdi
movq %rbx, %rsi
callq 0x699c
jmp 0x5926
movq %rax, %rbx
cmpl $0x1, %edx
jne 0x5a63
movq %rbx, %rdi
callq 0x5130
movq 0x16658(%rip), %rdi     # 0x1bfa8
movq %rax, %rsi
callq 0x5290
movq %rax, %rdi
callq 0x5160
callq 0x5480
movq 0x1663c(%rip), %rdi     # 0x1bfa8
leaq 0xb6df(%rip), %rsi      # 0x11052
callq 0x5290
movq 0x8(%rsp), %rcx
movq 0x60(%rcx), %rcx
movl 0x44(%rcx), %esi
incl %esi
movq %rax, %rdi
callq 0x54a0
leaq 0xb6c5(%rip), %rsi      # 0x1105a
movq %rax, %rdi
callq 0x5290
movq %rax, %rdi
callq 0x5160
movq 0x8(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x20(%rax), %rdi
xorl %esi, %esi
callq 0xe4a0
movl %eax, %ebx
movq 0x8(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x20(%rax), %rdi
pushq $0x1
popq %rsi
callq 0xe4a0
xorl %esi, %esi
cmpl %eax, %ebx
setle %sil
movq 0x8(%rsp), %rax
movq 0x60(%rax), %rax
movq 0x20(%rax), %rdi
callq 0xe4a0
movl %eax, %ebx
movq 0x8(%rsp), %rax
movq 0x60(%rax), %rax
cmpl %ebx, 0x40(%rax)
jge 0x5a22
movl %ebx, 0x40(%rax)
movq 0x165a4(%rip), %rdi     # 0x1bfa8
leaq 0xb65a(%rip), %rsi      # 0x11065
callq 0x5290
movq %rax, %rdi
movl %ebx, %esi
callq 0x54a0
movq %rax, %rdi
callq 0x5160
leaq 0x10(%rsp), %rdi
callq 0x5c18
leaq 0x28(%rsp), %rdi
callq 0x5150
leaq 0x48(%rsp), %rdi
callq 0x5150
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
callq 0x5480
jmp 0x5a63
jmp 0x5a60
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x5c18
jmp 0x5a98
jmp 0x5a73
jmp 0x5a86
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x5150
jmp 0x5a89
jmp 0x5a86
jmp 0x5a95
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x5150
jmp 0x5a98
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x5150
jmp 0x5aa7
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x5150
jmp 0x5ab6
movq %rax, %rbx
movq %rbx, %rdi
callq 0x54b0