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

// -------------------------------------------------------------------------- //
//                                                                            //
// Check if the piece is pinned. If so, confirm it is moving along it's       //
// pin ray.                                                                   //
//                                                                            //
// -------------------------------------------------------------------------- //
    if (square_bb[src] & mPinned[mUs]
        && !(coplanar[src][dst] & getPieceBB<king>(mUs)))
        return false;

// -------------------------------------------------------------------------- //
//                                                                            //
// Check for en-passant. Remove both the attacking pawn and the captured      //
// pawn from the occupancy and see if the king is left in check. This avoids  //
// the rare scenario where both pawns are pinned to the king by a slider.     //
//                                                                            //
// -------------------------------------------------------------------------- //
    if (onSquare(src) == pawn && square_bb[dst] & mEnPassant)
    {
        U64 change = mUs == white ? square_bb[src] | square_bb[dst - 8]
                                  : square_bb[src] | square_bb[dst + 8];
        if (check(change))
            return false;
    }

// -------------------------------------------------------------------------- //
//                                                                            //
// Check for king non-castling king moves. See if the king is left in check   //
// after the move is made. Since castling moves are a more difficult case     //
// only legal castling moves are generated.                                   //
//                                                                            //
// -------------------------------------------------------------------------- //
    if (onSquare(src) == king && !isCastle(pMove))
    {
        U64 change = square_bb[src];
        if (isAttacked(dst, mUs, change))
            return false;
    }

    assert(dst != getKingSquare(mThem));
    assert((square_bb[dst] & mOccupancy[mUs]) == 0);

    return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %ebp
movq %rdi, %rbx
movl %esi, %r14d
shrl $0x6, %r14d
andl $0x3f, %r14d
movl %esi, %r15d
andl $0x3f, %r15d
leaq 0x113a98(%rip), %r12    # 0x126a80
movq (%r12,%r15,8), %rsi
movl (%rdi), %eax
movl %r14d, %ecx
testq %rsi, 0x68(%rdi,%rax,8)
je 0x13017
movl %r15d, %edx
shll $0x9, %edx
addq 0xff63(%rip), %rdx      # 0x22f68
imulq $0x30, %rax, %rdi
movq 0x2b0(%rbx,%rdi), %rdi
testq %rdi, (%rdx,%rcx,8)
je 0x13070
movl 0x188(%rbx,%r15,4), %edx
testl %edx, %edx
je 0x13044
testw %bp, %bp
js 0x13074
cmpl $0x5, %edx
jne 0x13074
movq (%r12,%r15,8), %rcx
movl (%rbx), %edx
movq %rbx, %rdi
movl %r14d, %esi
callq 0x14086
testb %al, %al
jne 0x13070
jmp 0x13074
movq 0x30(%rbx), %rdx
testq %rdx, (%r12,%rcx,8)
je 0x13074
xorl %ecx, %ecx
testq %rax, %rax
setne %cl
shll $0x4, %ecx
leal (%rcx,%r14), %eax
addl $-0x8, %eax
orq (%r12,%rax,8), %rsi
movq %rbx, %rdi
callq 0x13fce
testb %al, %al
je 0x1307f
xorl %eax, %eax
jmp 0x13076
movb $0x1, %al
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movl 0x188(%rbx,%r15,4), %edx
jmp 0x13023
nop