// File: /workspace/github_cpp_makefile_star2_O3/disjukr[P]Tetris/Tetris.cc
// Function: Tetris::Loop()
void Tetris::Loop() {
    if (Keyboard::hit()) {
        switch(Keyboard::code()) {
        case UP: case W:
            this -> ControlPiece([this]() {
                currentPiece -> RotateCW();
            });
            break;
        case X: case Q:
            this -> ControlPiece([this]() {
                currentPiece -> RotateCCW();
            });
            break;
        case LEFT: case A:
            this -> ControlPiece([this]() {
                --(currentPiece -> x);
            });
            break;
        case RIGHT: case D:
            this -> ControlPiece([this]() {
                ++(currentPiece -> x);
            });
            break;
        case DOWN: case S:
            this -> SoftDrop();
            ++statistics.score;
            break;
        case SPACE: case F:
            this -> HardDrop();
            break;
        case C: case R:
            this -> HardDrop(false);
            break;
        case Z: case E:
            this -> HoldPiece();
            break;
        case ESC:
            this -> Exit();
            return;
        default:
            break;
        }
    }
    int frameDiff = (int) (frame - lastDrop);
    if (dropFrameInterval < frameDiff) {
        if (this -> SoftDrop(attachFrameInterval < frameDiff))
            lastDrop = frame;
    }
    if (this -> CheckGameOver()) {
        this -> Exit();
        return;
    }
    int lineCount = 0;
    for (int i = 0; i < TetrisStage::height; ++i) {
        if (this -> CheckLine(i)) {
            this -> stage.EraseLine(i);
            ++lineCount;
        }
    }
    switch (lineCount) {
    case 1: ++statistics._single; statistics.score += 100; break;
    case 2: ++statistics._double; statistics.score += 300; break;
    case 3: ++statistics._triple; statistics.score += 500; break;
    case 4: ++statistics._tetris; statistics.score += 800; break;
    }
    if (statistics.score > statistics.level * 1000)
        LevelUp();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
callq 0x7584
testb %al, %al
je 0x4063
callq 0x7590
cmpl $0x10, %eax
ja 0x4063
movl %eax, %eax
leaq 0x414b(%rip), %rcx      # 0x8018
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x88(%rbp), %rsi
movq $0x0, 0x8(%rsi)
movq %rbx, (%rsi)
leaq 0x1719(%rip), %rax      # 0x5608
movq %rax, 0x18(%rsi)
leaq 0x1724(%rip), %rax      # 0x561e
movq %rax, 0x10(%rsi)
movq %rbx, %rdi
callq 0x427a
movq -0x78(%rbp), %rax
testq %rax, %rax
je 0x4063
leaq -0x88(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x4063
leaq -0x68(%rbp), %rsi
movq $0x0, 0x8(%rsi)
movq %rbx, (%rsi)
leaq 0x1709(%rip), %rax      # 0x5648
movq %rax, 0x18(%rsi)
leaq 0x1714(%rip), %rax      # 0x565e
movq %rax, 0x10(%rsi)
movq %rbx, %rdi
callq 0x427a
movq -0x58(%rbp), %rax
testq %rax, %rax
je 0x4063
leaq -0x68(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x4063
leaq 0x38(%rbx), %rdi
movq 0x420(%rbx), %rsi
callq 0x52a4
addl %eax, %eax
addl %eax, 0x20(%rbx)
movq %rbx, %rdi
callq 0x5150
jmp 0x4063
movq %rbx, %rdi
callq 0x4382
jmp 0x4063
leaq 0x38(%rbx), %rdi
movq 0x420(%rbx), %rsi
callq 0x52a4
addl %eax, %eax
addl %eax, 0x20(%rbx)
movq %rbx, %rdi
callq 0x52e8
jmp 0x4063
leaq -0x48(%rbp), %rsi
movq $0x0, 0x8(%rsi)
movq %rbx, (%rsi)
leaq 0x16ab(%rip), %rax      # 0x5688
movq %rax, 0x18(%rsi)
leaq 0x16b4(%rip), %rax      # 0x569c
movq %rax, 0x10(%rsi)
movq %rbx, %rdi
callq 0x427a
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x4063
leaq -0x48(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x4063
leaq -0x28(%rbp), %rsi
movq $0x0, 0x8(%rsi)
movq %rbx, (%rsi)
leaq 0x16a3(%rip), %rax      # 0x56c6
movq %rax, 0x18(%rsi)
leaq 0x16ac(%rip), %rax      # 0x56da
movq %rax, 0x10(%rsi)
movq %rbx, %rdi
callq 0x427a
movq -0x18(%rbp), %rax
testq %rax, %rax
je 0x4063
leaq -0x28(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x4063
movq %rbx, %rdi
movl $0x1, %esi
callq 0x42f2
incl 0x20(%rbx)
movl 0xc(%rbx), %eax
subl 0x1c(%rbx), %eax
cmpl %eax, 0x14(%rbx)
jge 0x4089
xorl %esi, %esi
cmpl %eax, 0x18(%rbx)
setl %sil
movq %rbx, %rdi
callq 0x42f2
testb %al, %al
je 0x4089
movl 0xc(%rbx), %eax
movl %eax, 0x1c(%rbx)
cmpl $0x0, 0x60(%rbx)
je 0x40a2
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
addq $0x88, %rsp
popq %rbx
popq %rbp
retq
leaq 0x38(%rbx), %rax
xorl %ecx, %ecx
cmpq $0x9, %rcx
je 0x40c5
leaq 0x1(%rcx), %rdx
cmpl $0x0, 0x64(%rbx,%rcx,4)
movq %rdx, %rcx
je 0x40a8
decq %rdx
cmpq $0x9, %rdx
jb 0x408f
xorl %edx, %edx
xorl %ecx, %ecx
xorl %esi, %esi
cmpl $0x0, (%rax,%rsi,4)
je 0x4117
incq %rsi
cmpq $0xa, %rsi
jne 0x40cb
movq %rax, %rsi
movq %rdx, %rdi
leaq -0x1(%rdi), %r8
movq $-0x28, %r9
xorl %r10d, %r10d
cmpq $0x15, %r8
ja 0x40f8
movl (%rsi,%r9), %r10d
cmpq $0x15, %rdi
ja 0x4103
movl %r10d, 0x28(%rsi,%r9)
addq $0x4, %r9
jne 0x40eb
addq $-0x28, %rsi
testq %rdi, %rdi
movq %r8, %rdi
jg 0x40e0
incl %ecx
incq %rdx
addq $0x28, %rax
cmpq $0x16, %rdx
jne 0x40c9
decl %ecx
cmpl $0x3, %ecx
ja 0x41cb
leaq 0x3f26(%rip), %rax      # 0x805c
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
incl 0x28(%rbx)
movl 0x20(%rbx), %eax
addl $0x64, %eax
jmp 0x4169
incl 0x30(%rbx)
movl $0x1f4, %eax            # imm = 0x1F4
jmp 0x4166
incl 0x34(%rbx)
movl $0x320, %eax            # imm = 0x320
jmp 0x4166
incl 0x2c(%rbx)
movl $0x12c, %eax            # imm = 0x12C
addl 0x20(%rbx), %eax
movl %eax, 0x20(%rbx)
movl 0x24(%rbx), %ecx
imull $0x3e8, %ecx, %edx      # imm = 0x3E8
cmpl %edx, %eax
jle 0x4098
incl %ecx
movl %ecx, 0x24(%rbx)
movl 0x14(%rbx), %eax
cmpl $0x3, %eax
movl $0x2, %ecx
cmovgel %eax, %ecx
decl %ecx
movl %ecx, 0x14(%rbx)
movl 0x3b0(%rbx), %eax
leal -0x3(%rax), %ecx
movslq %ecx, %rcx
imulq $0x2aaaaaab, %rcx, %rcx # imm = 0x2AAAAAAB
movq %rcx, %rdx
shrq $0x3f, %rdx
shrq $0x20, %rcx
addl %edx, %ecx
addl %ecx, %ecx
leal (%rcx,%rcx,2), %ecx
negl %ecx
addl %ecx, %eax
incl %eax
movl %eax, 0x3b0(%rbx)
jmp 0x4098
movl 0x20(%rbx), %eax
jmp 0x416c
movq (%rbx), %rax
movq %rbx, %rdi
addq $0x88, %rsp
popq %rbx
popq %rbp
jmpq *0x10(%rax)
jmp 0x4272
jmp 0x4272
jmp 0x4272
jmp 0x4272
movq %rax, %rbx
movq -0x18(%rbp), %rax
testq %rax, %rax
je 0x426a
leaq -0x28(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x426a
jmp 0x4272
movq %rax, %rbx
movq -0x38(%rbp), %rax
testq %rax, %rax
je 0x426a
leaq -0x48(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x426a
jmp 0x4272
movq %rax, %rbx
movq -0x58(%rbp), %rax
testq %rax, %rax
je 0x426a
leaq -0x68(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x426a
jmp 0x4272
movq %rax, %rbx
movq -0x78(%rbp), %rax
testq %rax, %rax
je 0x426a
leaq -0x88(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq %rbx, %rdi
callq 0x3220
movq %rax, %rdi
callq 0x5af8