// File: /workspace/github_cpp_makefile_star2_O2/niekh1234[P]nnchesslib/board.cpp
// Function: nnchesslib::ChessBoard::updateCastlingRights()
void ChessBoard::updateCastlingRights()
{
    // if the rooks have moved:
    bool whiteQSRook = BitBoard(boardinfo.whitePieces.board & boardinfo.rooks.board).get(A1);
    bool whiteKSRook = BitBoard(boardinfo.whitePieces.board & boardinfo.rooks.board).get(H1);
    bool blackQSRook = BitBoard(boardinfo.blackPieces.board & boardinfo.rooks.board).get(A8);
    bool blackKSRook = BitBoard(boardinfo.blackPieces.board & boardinfo.rooks.board).get(H8);
    // castling rights can only go from true to false. If you move a rook back into proper position you cannot castle anymore.
    if(!whiteQSRook && boardinfo.whiteCastleLong) boardinfo.whiteCastleLong = false;
    if(!whiteKSRook && boardinfo.whiteCastleShort) boardinfo.whiteCastleShort = false;
    if(!blackQSRook && boardinfo.blackCastleLong) boardinfo.blackCastleLong = false;
    if(!blackKSRook && boardinfo.blackCastleShort) boardinfo.blackCastleShort = false;

    // if the kings have moved:
    bool whiteKing = BitBoard(boardinfo.whitePieces.board & boardinfo.kings.board).get(E1);
    bool blackKing = BitBoard(boardinfo.blackPieces.board & boardinfo.kings.board).get(E8);
    if(!whiteKing && (boardinfo.whiteCastleLong || boardinfo.whiteCastleShort))
    {
        boardinfo.whiteCastleLong = false;
        boardinfo.whiteCastleShort = false;
    } else if (!blackKing && (boardinfo.blackCastleLong || boardinfo.blackCastleShort))
    {
        boardinfo.blackCastleLong = false;
        boardinfo.blackCastleShort = false;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x28(%rdi), %rsi
andq (%rdi), %rsi
leaq -0x30(%rbp), %r14
movq %r14, %rdi
callq 0x3036
movq %r14, %rdi
xorl %esi, %esi
callq 0x30a4
movl %eax, %r14d
movq 0x28(%rbx), %rsi
andq (%rbx), %rsi
leaq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0x3036
pushq $0x7
popq %rsi
movq %r15, %rdi
callq 0x30a4
movl %eax, %r15d
movq 0x28(%rbx), %rsi
andq 0x8(%rbx), %rsi
leaq -0x30(%rbp), %r12
movq %r12, %rdi
callq 0x3036
pushq $0x38
popq %rsi
movq %r12, %rdi
callq 0x30a4
movl %eax, %r12d
movq 0x28(%rbx), %rsi
andq 0x8(%rbx), %rsi
leaq -0x30(%rbp), %r13
movq %r13, %rdi
callq 0x3036
pushq $0x3f
popq %rsi
movq %r13, %rdi
callq 0x30a4
testl %r14d, %r14d
jne 0x483c
cmpb $0x1, 0x42(%rbx)
jne 0x483c
movb $0x0, 0x42(%rbx)
testl %r15d, %r15d
jne 0x484b
cmpb $0x1, 0x41(%rbx)
jne 0x484b
movb $0x0, 0x41(%rbx)
testl %r12d, %r12d
jne 0x485a
cmpb $0x1, 0x44(%rbx)
jne 0x485a
movb $0x0, 0x44(%rbx)
testl %eax, %eax
jne 0x4868
cmpb $0x1, 0x43(%rbx)
jne 0x4868
movb $0x0, 0x43(%rbx)
movq 0x38(%rbx), %rsi
andq (%rbx), %rsi
leaq -0x30(%rbp), %r14
movq %r14, %rdi
callq 0x3036
pushq $0x4
popq %rsi
movq %r14, %rdi
callq 0x30a4
movl %eax, %r14d
movq 0x38(%rbx), %rsi
andq 0x8(%rbx), %rsi
leaq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0x3036
pushq $0x3c
popq %rsi
movq %r15, %rdi
callq 0x30a4
testl %r14d, %r14d
je 0x48c5
testl %eax, %eax
jne 0x48dc
cmpb $0x0, 0x44(%rbx)
jne 0x48bd
cmpb $0x1, 0x43(%rbx)
jne 0x48dc
movb $0x0, 0x44(%rbx)
pushq $0x43
jmp 0x48d7
cmpb $0x0, 0x42(%rbx)
jne 0x48d1
cmpb $0x1, 0x41(%rbx)
jne 0x48ad
movb $0x0, 0x42(%rbx)
pushq $0x41
popq %rax
movb $0x0, (%rbx,%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop