// File: SethKasmann[P]clever-girl/src/state.cpp
// Function: State::givesCheck(unsigned short) const
bool State::givesCheck(Move pMove) const
{
    Square src = getSrc(pMove);
    Square dst = getDst(pMove);
    PieceType piece = onSquare(src);

    // Direct check.
    if (getCheckSquaresBB(piece) & square_bb[dst])
        return true;

    // Discovered check.
    if ((getDiscoveredChecks(mUs) & square_bb[src]) &&
        !(coplanar[src][dst] & getPieceBB<king>(mThem)))
        return true;

    if (isEnPassant(pMove))
    {
        U64 change = square_bb[src] | square_bb[dst];
        change |= mUs == white ? square_bb[dst - 8] : square_bb[dst + 8];
        return check(change, mThem);
    }
    else if (isCastle(pMove))
    {
        Square rookSquare = src > dst ? dst + 1 : dst - 1;
        return getAttackBB(rook, rookSquare, getOccupancyBB() ^ square_bb[src]) &
               getPieceBB<king>(mThem);
    }
    else if (isPromotion(pMove))
    {
        PieceType promo = getPiecePromo(pMove);
        return getAttackBB(promo, dst, getOccupancyBB() ^ square_bb[src]) &
               getPieceBB<king>(mThem);
    }
    return false;
}

// Assembly:
subq $0x78, %rsp
movw %si, %ax
movq %rdi, 0x68(%rsp)
movw %ax, 0x66(%rsp)
movq 0x68(%rsp), %rax
movq %rax, 0x40(%rsp)
movzwl 0x66(%rsp), %edi
callq 0x26810
movl %eax, 0x60(%rsp)
movzwl 0x66(%rsp), %edi
callq 0x26830
movq 0x40(%rsp), %rdi
movl %eax, 0x5c(%rsp)
movl 0x60(%rsp), %esi
callq 0x29bd0
movq 0x40(%rsp), %rdi
movl %eax, 0x58(%rsp)
movl 0x58(%rsp), %esi
callq 0x3a530
movl 0x5c(%rsp), %ecx
movl %ecx, %edx
leaq 0x11d0cc(%rip), %rcx    # 0x154b10
andq (%rcx,%rdx,8), %rax
cmpq $0x0, %rax
je 0x37a58
movb $0x1, 0x77(%rsp)
jmp 0x37cc6
movq 0x40(%rsp), %rdi
movl (%rdi), %esi
callq 0x36e50
movl 0x60(%rsp), %ecx
movl %ecx, %edx
leaq 0x11d09f(%rip), %rcx    # 0x154b10
andq (%rcx,%rdx,8), %rax
cmpq $0x0, %rax
je 0x37ac4
movq 0x40(%rsp), %rdi
movl 0x60(%rsp), %eax
movl %eax, %ecx
leaq 0x136283(%rip), %rax    # 0x16dd10
shlq $0x9, %rcx
addq %rcx, %rax
movl 0x5c(%rsp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, 0x38(%rsp)
movl 0x4(%rdi), %esi
callq 0x25510
movq %rax, %rcx
movq 0x38(%rsp), %rax
andq %rcx, %rax
cmpq $0x0, %rax
jne 0x37ac4
movb $0x1, 0x77(%rsp)
jmp 0x37cc6
movq 0x40(%rsp), %rdi
movzwl 0x66(%rsp), %esi
callq 0x35640
testb $0x1, %al
jne 0x37adc
jmp 0x37b7f
movq 0x40(%rsp), %rax
movl 0x60(%rsp), %ecx
movl %ecx, %edx
leaq 0x11d022(%rip), %rcx    # 0x154b10
movq (%rcx,%rdx,8), %rcx
movl 0x5c(%rsp), %edx
movl %edx, %esi
leaq 0x11d011(%rip), %rdx    # 0x154b10
orq (%rdx,%rsi,8), %rcx
movq %rcx, 0x50(%rsp)
cmpl $0x0, (%rax)
jne 0x37b31
movl 0x5c(%rsp), %edi
movl $0x8, %esi
callq 0x24e80
movl %eax, %eax
movl %eax, %ecx
leaq 0x11cfea(%rip), %rax    # 0x154b10
movq (%rax,%rcx,8), %rax
movq %rax, 0x30(%rsp)
jmp 0x37b53
movl 0x5c(%rsp), %edi
movl $0x8, %esi
callq 0x24e60
movl %eax, %eax
movl %eax, %ecx
leaq 0x11cfc6(%rip), %rax    # 0x154b10
movq (%rax,%rcx,8), %rax
movq %rax, 0x30(%rsp)
movq 0x40(%rsp), %rdi
movq 0x30(%rsp), %rax
orq 0x50(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rsi
movl 0x4(%rdi), %edx
callq 0x3a560
andb $0x1, %al
movb %al, 0x77(%rsp)
jmp 0x37cc6
movzwl 0x66(%rsp), %edi
callq 0x3a1d0
testb $0x1, %al
jne 0x37b92
jmp 0x37c32
movl 0x60(%rsp), %eax
cmpl 0x5c(%rsp), %eax
jbe 0x37bb0
movl 0x5c(%rsp), %edi
movl $0x1, %esi
callq 0x24e60
movl %eax, 0x2c(%rsp)
jmp 0x37bc2
movl 0x5c(%rsp), %edi
movl $0x1, %esi
callq 0x24e80
movl %eax, 0x2c(%rsp)
movq 0x40(%rsp), %rdi
movl 0x2c(%rsp), %eax
movl %eax, 0x4c(%rsp)
movl 0x4c(%rsp), %eax
movl %eax, 0x1c(%rsp)
callq 0x24bc0
movl 0x1c(%rsp), %edx
movq 0x40(%rsp), %rdi
movq %rax, %rcx
movl 0x60(%rsp), %eax
movl %eax, %esi
leaq 0x11cf1b(%rip), %rax    # 0x154b10
xorq (%rax,%rsi,8), %rcx
movl $0x3, %esi
callq 0x3a730
movq 0x40(%rsp), %rdi
movq %rax, 0x20(%rsp)
movl 0x4(%rdi), %esi
callq 0x25510
movq %rax, %rcx
movq 0x20(%rsp), %rax
andq %rcx, %rax
cmpq $0x0, %rax
setne %al
andb $0x1, %al
movb %al, 0x77(%rsp)
jmp 0x37cc6
movzwl 0x66(%rsp), %edi
callq 0x2a0c0
testb $0x1, %al
jne 0x37c42
jmp 0x37cbd
movzwl 0x66(%rsp), %edi
callq 0x268e0
movq 0x40(%rsp), %rdi
movl %eax, 0x48(%rsp)
movl 0x48(%rsp), %eax
movl %eax, 0x8(%rsp)
movl 0x5c(%rsp), %eax
movl %eax, 0xc(%rsp)
callq 0x24bc0
movl 0x8(%rsp), %esi
movl 0xc(%rsp), %edx
movq 0x40(%rsp), %rdi
movq %rax, %rcx
movl 0x60(%rsp), %eax
movl %eax, %r8d
leaq 0x11ce88(%rip), %rax    # 0x154b10
xorq (%rax,%r8,8), %rcx
callq 0x3a730
movq 0x40(%rsp), %rdi
movq %rax, 0x10(%rsp)
movl 0x4(%rdi), %esi
callq 0x25510
movq %rax, %rcx
movq 0x10(%rsp), %rax
andq %rcx, %rax
cmpq $0x0, %rax
setne %al
andb $0x1, %al
movb %al, 0x77(%rsp)
jmp 0x37cc6
jmp 0x37cbf
jmp 0x37cc1
movb $0x0, 0x77(%rsp)
movb 0x77(%rsp), %al
andb $0x1, %al
addq $0x78, %rsp
retq
nopw %cs:(%rax,%rax)