// File: /workspace/github_cpp_makefile_star2_O3/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 0x3386
movq %r14, %rdi
xorl %esi, %esi
callq 0x33f8
movl %eax, %r14d
movq 0x28(%rbx), %rsi
andq (%rbx), %rsi
leaq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0x3386
movq %r15, %rdi
movl $0x7, %esi
callq 0x33f8
movl %eax, %r15d
movq 0x28(%rbx), %rsi
andq 0x8(%rbx), %rsi
leaq -0x30(%rbp), %r12
movq %r12, %rdi
callq 0x3386
movq %r12, %rdi
movl $0x38, %esi
callq 0x33f8
movl %eax, %r12d
movq 0x28(%rbx), %rsi
andq 0x8(%rbx), %rsi
leaq -0x30(%rbp), %r13
movq %r13, %rdi
callq 0x3386
movq %r13, %rdi
movl $0x3f, %esi
callq 0x33f8
testl %r14d, %r14d
jne 0x529a
cmpb $0x1, 0x42(%rbx)
jne 0x529a
movb $0x0, 0x42(%rbx)
testl %r15d, %r15d
jne 0x52a9
cmpb $0x1, 0x41(%rbx)
jne 0x52a9
movb $0x0, 0x41(%rbx)
testl %r12d, %r12d
jne 0x52b8
cmpb $0x1, 0x44(%rbx)
jne 0x52b8
movb $0x0, 0x44(%rbx)
testl %eax, %eax
jne 0x52c6
cmpb $0x1, 0x43(%rbx)
jne 0x52c6
movb $0x0, 0x43(%rbx)
movq 0x38(%rbx), %rsi
andq (%rbx), %rsi
leaq -0x30(%rbp), %r14
movq %r14, %rdi
callq 0x3386
movq %r14, %rdi
movl $0x4, %esi
callq 0x33f8
movl %eax, %r14d
movq 0x38(%rbx), %rsi
andq 0x8(%rbx), %rsi
leaq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0x3386
movq %r15, %rdi
movl $0x3c, %esi
callq 0x33f8
testl %r14d, %r14d
je 0x532a
testl %eax, %eax
jne 0x5343
cmpb $0x0, 0x44(%rbx)
jne 0x531f
cmpb $0x1, 0x43(%rbx)
jne 0x5343
movb $0x0, 0x44(%rbx)
movl $0x43, %eax
jmp 0x533f
cmpb $0x0, 0x42(%rbx)
jne 0x5336
cmpb $0x1, 0x41(%rbx)
jne 0x530f
movb $0x0, 0x42(%rbx)
movl $0x41, %eax
movb $0x0, (%rbx,%rax)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq