// File: /workspace/github_cpp_makefile_star2_O1/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 0x334a
movq %r14, %rdi
xorl %esi, %esi
callq 0x33bc
movl %eax, %r14d
movq 0x28(%rbx), %rsi
andq (%rbx), %rsi
leaq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0x334a
movq %r15, %rdi
movl $0x7, %esi
callq 0x33bc
movl %eax, %r15d
movq 0x28(%rbx), %rsi
andq 0x8(%rbx), %rsi
leaq -0x30(%rbp), %r12
movq %r12, %rdi
callq 0x334a
movq %r12, %rdi
movl $0x38, %esi
callq 0x33bc
movl %eax, %r12d
movq 0x28(%rbx), %rsi
andq 0x8(%rbx), %rsi
leaq -0x30(%rbp), %r13
movq %r13, %rdi
callq 0x334a
movq %r13, %rdi
movl $0x3f, %esi
callq 0x33bc
testl %r14d, %r14d
jne 0x5286
cmpb $0x1, 0x42(%rbx)
jne 0x5286
movb $0x0, 0x42(%rbx)
testl %r15d, %r15d
jne 0x5295
cmpb $0x1, 0x41(%rbx)
jne 0x5295
movb $0x0, 0x41(%rbx)
testl %r12d, %r12d
jne 0x52a4
cmpb $0x1, 0x44(%rbx)
jne 0x52a4
movb $0x0, 0x44(%rbx)
testl %eax, %eax
jne 0x52b2
cmpb $0x1, 0x43(%rbx)
jne 0x52b2
movb $0x0, 0x43(%rbx)
movq 0x38(%rbx), %rsi
andq (%rbx), %rsi
leaq -0x30(%rbp), %r14
movq %r14, %rdi
callq 0x334a
movq %r14, %rdi
movl $0x4, %esi
callq 0x33bc
movl %eax, %r14d
movq 0x38(%rbx), %rsi
andq 0x8(%rbx), %rsi
leaq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0x334a
movq %r15, %rdi
movl $0x3c, %esi
callq 0x33bc
testl %r14d, %r14d
je 0x5316
testl %eax, %eax
jne 0x532f
cmpb $0x0, 0x44(%rbx)
jne 0x530b
cmpb $0x1, 0x43(%rbx)
jne 0x532f
movb $0x0, 0x44(%rbx)
movl $0x43, %eax
jmp 0x532b
cmpb $0x0, 0x42(%rbx)
jne 0x5322
cmpb $0x1, 0x41(%rbx)
jne 0x52fb
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