// File: /workspace/github_cpp_makefile_star2_O3/niekh1234[P]nnchesslib/board.cpp
// Function: nnchesslib::ChessBoard::pushCastlingMove(unsigned int)
void ChessBoard::pushCastlingMove(Move move)
{
    int from = from_Square(move);
    int to = to_Square(move);
    // gets the bitboard corresponding to our piece color.
    BitBoard * ourPieces = getColorOnSquare(from);

    // I already thought of a more efficient way of writing this but cannot be asked at the moment. + this is probably quite fast.

    // white ks castle
    if(to == 6 && boardinfo.whiteCastleShort)
    {
        boardinfo.kings.set(E1, false);
        boardinfo.rooks.set(H1, false);
        boardinfo.kings.set(G1, true);
        boardinfo.rooks.set(F1, true);
        ourPieces->set(E1, false);
        ourPieces->set(H1, false);
        ourPieces->set(G1, true);
        ourPieces->set(F1, true);
    } 
    // white qs castle
    else if (to == 2 && boardinfo.whiteCastleLong)
    {
        boardinfo.kings.set(E1, false);
        boardinfo.rooks.set(A1, false);
        boardinfo.kings.set(C1, true);
        boardinfo.rooks.set(D1, true);
        ourPieces->set(E1, false);
        ourPieces->set(A1, false);
        ourPieces->set(C1, true);
        ourPieces->set(D1, true);
    }
    // black qs castle
    else if (to == 58 && boardinfo.blackCastleLong)
    {
        boardinfo.kings.set(E8, false);
        boardinfo.rooks.set(H8, false);
        boardinfo.kings.set(G8, true);
        boardinfo.rooks.set(F8, true);
        ourPieces->set(E8, false);
        ourPieces->set(H8, false);
        ourPieces->set(G8, true);
        ourPieces->set(F8, true);
    } 
    // black ks castle
    else if (to == 62 && boardinfo.blackCastleShort)
    {
        boardinfo.kings.set(E8, false);
        boardinfo.rooks.set(A8, false);
        boardinfo.kings.set(C8, true);
        boardinfo.rooks.set(D8, true);
        ourPieces->set(E8, false);
        ourPieces->set(A8, false);
        ourPieces->set(C8, true);
        ourPieces->set(D8, true);
    } else {
        std::cout<<"No castling rights!"<<std::endl;
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %ebx
movq %rdi, %r14
movl %esi, %edi
callq 0x6a58
movl %eax, %r12d
movl %ebx, %edi
callq 0x6a66
movl %eax, %r15d
movq %r14, %rdi
movl %r12d, %esi
callq 0x4f40
movq %rax, %rbx
cmpl $0x39, %r15d
jg 0x5434
cmpl $0x2, %r15d
je 0x54da
cmpl $0x6, %r15d
jne 0x5605
cmpb $0x1, 0x41(%r14)
jne 0x5605
leaq 0x38(%r14), %r15
movq %r15, %rdi
movl $0x4, %esi
xorl %edx, %edx
callq 0x33b2
addq $0x28, %r14
movq %r14, %rdi
movl $0x7, %esi
xorl %edx, %edx
callq 0x33b2
movq %r15, %rdi
movl $0x6, %esi
movl $0x1, %edx
callq 0x33b2
movq %r14, %rdi
movl $0x5, %esi
movl $0x1, %edx
callq 0x33b2
movq %rbx, %rdi
movl $0x4, %esi
xorl %edx, %edx
callq 0x33b2
movq %rbx, %rdi
movl $0x7, %esi
xorl %edx, %edx
callq 0x33b2
movq %rbx, %rdi
movl $0x6, %esi
movl $0x1, %edx
callq 0x33b2
movq %rbx, %rdi
movl $0x5, %esi
jmp 0x55f3
cmpl $0x3a, %r15d
je 0x5566
cmpl $0x3e, %r15d
jne 0x5605
cmpb $0x1, 0x43(%r14)
jne 0x5605
leaq 0x38(%r14), %r15
movq %r15, %rdi
movl $0x3c, %esi
xorl %edx, %edx
callq 0x33b2
addq $0x28, %r14
movq %r14, %rdi
movl $0x38, %esi
xorl %edx, %edx
callq 0x33b2
movq %r15, %rdi
movl $0x3a, %esi
movl $0x1, %edx
callq 0x33b2
movq %r14, %rdi
movl $0x3b, %esi
movl $0x1, %edx
callq 0x33b2
movq %rbx, %rdi
movl $0x3c, %esi
xorl %edx, %edx
callq 0x33b2
movq %rbx, %rdi
movl $0x38, %esi
xorl %edx, %edx
callq 0x33b2
movq %rbx, %rdi
movl $0x3a, %esi
movl $0x1, %edx
callq 0x33b2
movq %rbx, %rdi
movl $0x3b, %esi
jmp 0x55f3
cmpb $0x1, 0x42(%r14)
jne 0x5605
leaq 0x38(%r14), %r15
movq %r15, %rdi
movl $0x4, %esi
xorl %edx, %edx
callq 0x33b2
addq $0x28, %r14
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x33b2
movq %r15, %rdi
movl $0x2, %esi
movl $0x1, %edx
callq 0x33b2
movq %r14, %rdi
movl $0x3, %esi
movl $0x1, %edx
callq 0x33b2
movq %rbx, %rdi
movl $0x4, %esi
xorl %edx, %edx
callq 0x33b2
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x33b2
movq %rbx, %rdi
movl $0x2, %esi
movl $0x1, %edx
callq 0x33b2
movq %rbx, %rdi
movl $0x3, %esi
jmp 0x55f3
cmpb $0x1, 0x44(%r14)
jne 0x5605
leaq 0x38(%r14), %r15
movq %r15, %rdi
movl $0x3c, %esi
xorl %edx, %edx
callq 0x33b2
addq $0x28, %r14
movq %r14, %rdi
movl $0x3f, %esi
xorl %edx, %edx
callq 0x33b2
movq %r15, %rdi
movl $0x3e, %esi
movl $0x1, %edx
callq 0x33b2
movq %r14, %rdi
movl $0x3d, %esi
movl $0x1, %edx
callq 0x33b2
movq %rbx, %rdi
movl $0x3c, %esi
xorl %edx, %edx
callq 0x33b2
movq %rbx, %rdi
movl $0x3f, %esi
xorl %edx, %edx
callq 0x33b2
movq %rbx, %rdi
movl $0x3e, %esi
movl $0x1, %edx
callq 0x33b2
movq %rbx, %rdi
movl $0x3d, %esi
movl $0x1, %edx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x33b2
movq 0x79cc(%rip), %rbx      # 0xcfd8
leaq 0x4204(%rip), %rsi      # 0x9817
movl $0x13, %edx
movq %rbx, %rdi
callq 0x2180
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x20e0
nop