// File: /workspace/github_cpp_makefile_star2_O1/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 %r14
pushq %rbx
subq $0x80, %rsp
movq %rdi, %rbx
callq 0x7650
testb %al, %al
je 0x4085
callq 0x765c
cmpl $0x10, %eax
ja 0x4085
movl %eax, %eax
leaq 0x4131(%rip), %rcx      # 0x8018
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorps %xmm0, %xmm0
leaq -0x90(%rbp), %rsi
movaps %xmm0, (%rsi)
movaps %xmm0, 0x10(%rsi)
movq %rbx, (%rsi)
leaq 0x1775(%rip), %rax      # 0x5680
movq %rax, 0x18(%rsi)
leaq 0x1780(%rip), %rax      # 0x5696
movq %rax, 0x10(%rsi)
movq %rbx, %rdi
callq 0x42b6
movq -0x80(%rbp), %rax
testq %rax, %rax
je 0x4085
leaq -0x90(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x4085
xorps %xmm0, %xmm0
leaq -0x70(%rbp), %rsi
movaps %xmm0, (%rsi)
movaps %xmm0, 0x10(%rsi)
movq %rbx, (%rsi)
leaq 0x1763(%rip), %rax      # 0x56c0
movq %rax, 0x18(%rsi)
leaq 0x176e(%rip), %rax      # 0x56d6
movq %rax, 0x10(%rsi)
movq %rbx, %rdi
callq 0x42b6
movq -0x60(%rbp), %rax
testq %rax, %rax
je 0x4085
leaq -0x70(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x4085
leaq 0x38(%rbx), %rdi
movq 0x420(%rbx), %rsi
callq 0x5314
addl %eax, %eax
addl %eax, 0x20(%rbx)
movq %rbx, %rdi
callq 0x51aa
jmp 0x4085
movq %rbx, %rdi
callq 0x43be
jmp 0x4085
leaq 0x38(%rbx), %rdi
movq 0x420(%rbx), %rsi
callq 0x5314
addl %eax, %eax
addl %eax, 0x20(%rbx)
movq %rbx, %rdi
callq 0x5358
jmp 0x4085
xorps %xmm0, %xmm0
leaq -0x50(%rbp), %rsi
movaps %xmm0, (%rsi)
movaps %xmm0, 0x10(%rsi)
movq %rbx, (%rsi)
leaq 0x1703(%rip), %rax      # 0x5700
movq %rax, 0x18(%rsi)
leaq 0x170c(%rip), %rax      # 0x5714
movq %rax, 0x10(%rsi)
movq %rbx, %rdi
callq 0x42b6
movq -0x40(%rbp), %rax
testq %rax, %rax
je 0x4085
leaq -0x50(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x4085
xorps %xmm0, %xmm0
leaq -0x30(%rbp), %rsi
movaps %xmm0, (%rsi)
movaps %xmm0, 0x10(%rsi)
movq %rbx, (%rsi)
leaq 0x16f9(%rip), %rax      # 0x573e
movq %rax, 0x18(%rsi)
leaq 0x1702(%rip), %rax      # 0x5752
movq %rax, 0x10(%rsi)
movq %rbx, %rdi
callq 0x42b6
movq -0x20(%rbp), %rax
testq %rax, %rax
je 0x4085
leaq -0x30(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x4085
movq %rbx, %rdi
movl $0x1, %esi
callq 0x432e
incl 0x20(%rbx)
movl 0xc(%rbx), %eax
subl 0x1c(%rbx), %eax
cmpl %eax, 0x14(%rbx)
jge 0x40ab
xorl %esi, %esi
cmpl %eax, 0x18(%rbx)
setl %sil
movq %rbx, %rdi
callq 0x432e
testb %al, %al
je 0x40ab
movl 0xc(%rbx), %eax
movl %eax, 0x1c(%rbx)
cmpl $0x0, 0x60(%rbx)
jne 0x40d1
leaq 0x38(%rbx), %rax
xorl %edx, %edx
movq %rdx, %rcx
cmpq $0x9, %rdx
je 0x40cb
leaq 0x1(%rcx), %rdx
cmpl $0x0, 0x64(%rbx,%rcx,4)
je 0x40b7
cmpq $0x9, %rcx
jae 0x40e6
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x10(%rax)
addq $0x80, %rsp
popq %rbx
popq %r14
popq %rbp
retq
leaq 0x3c(%rbx), %rdx
xorl %esi, %esi
movq %rax, %rdi
xorl %ecx, %ecx
leaq (%rsi,%rsi,4), %r8
cmpl $0x0, (%rax,%r8,8)
je 0x4159
xorl %r8d, %r8d
cmpq $0x9, %r8
je 0x411c
leaq 0x1(%r8), %r9
cmpl $0x0, (%rdx,%r8,4)
movq %r9, %r8
jne 0x40ff
decq %r9
cmpq $0x9, %r9
jb 0x4159
movq %rdi, %r8
movq %rsi, %r9
leaq -0x1(%r9), %r10
movq $-0x28, %r11
xorl %r14d, %r14d
cmpq $0x15, %r10
ja 0x413a
movl (%r8,%r11), %r14d
cmpq $0x15, %r9
ja 0x4145
movl %r14d, 0x28(%r8,%r11)
addq $0x4, %r11
jne 0x412d
addq $-0x28, %r8
testq %r9, %r9
movq %r10, %r9
jg 0x4122
incl %ecx
incq %rsi
addq $0x28, %rdx
addq $0x28, %rdi
cmpq $0x16, %rsi
jne 0x40f1
decl %ecx
cmpl $0x3, %ecx
ja 0x41aa
leaq 0x3ee4(%rip), %rax      # 0x805c
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
incl 0x28(%rbx)
movl $0x64, %eax
jmp 0x41a7
incl 0x30(%rbx)
movl $0x1f4, %eax            # imm = 0x1F4
jmp 0x41a7
incl 0x34(%rbx)
movl $0x320, %eax            # imm = 0x320
jmp 0x41a7
incl 0x2c(%rbx)
movl $0x12c, %eax            # imm = 0x12C
addl %eax, 0x20(%rbx)
movl 0x24(%rbx), %eax
imull $0x3e8, %eax, %ecx      # imm = 0x3E8
cmpl %ecx, 0x20(%rbx)
jle 0x40da
incl %eax
movl %eax, 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 0x40da
movq (%rbx), %rax
movq %rbx, %rdi
addq $0x80, %rsp
popq %rbx
popq %r14
popq %rbp
jmpq *0x10(%rax)
jmp 0x42ae
jmp 0x42ae
jmp 0x42ae
jmp 0x42ae
movq %rax, %rbx
movq -0x20(%rbp), %rax
testq %rax, %rax
je 0x42a6
leaq -0x30(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x42a6
jmp 0x42ae
movq %rax, %rbx
movq -0x40(%rbp), %rax
testq %rax, %rax
je 0x42a6
leaq -0x50(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x42a6
jmp 0x42ae
movq %rax, %rbx
movq -0x60(%rbp), %rax
testq %rax, %rax
je 0x42a6
leaq -0x70(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
jmp 0x42a6
jmp 0x42ae
movq %rax, %rbx
movq -0x80(%rbp), %rax
testq %rax, %rax
je 0x42a6
leaq -0x90(%rbp), %rdi
movq %rdi, %rsi
movl $0x3, %edx
callq *%rax
movq %rbx, %rdi
callq 0x3220
movq %rax, %rdi
callq 0x5b70