// File: /workspace/github_cpp_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
pushq %rax
movl %esi, %ebx
movq %rdi, %r14
movl %esi, %edi
callq 0x5bd4
movl %eax, %r12d
movl %ebx, %edi
callq 0x5be2
movl %eax, %r15d
movq %r14, %rdi
movl %r12d, %esi
callq 0x451a
movq %rax, %rbx
cmpl $0x2, %r15d
je 0x4aa9
cmpl $0x3e, %r15d
je 0x49b5
cmpl $0x3a, %r15d
je 0x4a1e
cmpl $0x6, %r15d
jne 0x4b40
cmpb $0x1, 0x41(%r14)
jne 0x4b40
leaq 0x38(%r14), %r15
pushq $0x4
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x3062
addq $0x28, %r14
pushq $0x7
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x3062
pushq $0x6
popq %r13
pushq $0x1
popq %r12
movq %r15, %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x3062
pushq $0x5
popq %r15
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x3062
movq %rbx, %rdi
pushq $0x4
popq %rsi
xorl %edx, %edx
callq 0x3062
movq %rbx, %rdi
pushq $0x7
jmp 0x4a85
cmpb $0x1, 0x43(%r14)
jne 0x4b40
leaq 0x38(%r14), %r15
pushq $0x3c
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x3062
addq $0x28, %r14
pushq $0x38
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x3062
pushq $0x3a
popq %r13
pushq $0x1
popq %r12
movq %r15, %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x3062
pushq $0x3b
popq %r15
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x3062
movq %rbx, %rdi
pushq $0x3c
popq %rsi
xorl %edx, %edx
callq 0x3062
movq %rbx, %rdi
pushq $0x38
jmp 0x4a85
cmpb $0x1, 0x44(%r14)
jne 0x4b40
leaq 0x38(%r14), %r15
pushq $0x3c
popq %rsi
movq %r15, %rdi
xorl %edx, %edx
callq 0x3062
addq $0x28, %r14
pushq $0x3f
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x3062
pushq $0x3e
popq %r13
pushq $0x1
popq %r12
movq %r15, %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x3062
pushq $0x3d
popq %r15
movq %r14, %rdi
movl %r15d, %esi
movl %r12d, %edx
callq 0x3062
movq %rbx, %rdi
pushq $0x3c
popq %rsi
xorl %edx, %edx
callq 0x3062
movq %rbx, %rdi
pushq $0x3f
popq %rsi
xorl %edx, %edx
callq 0x3062
movq %rbx, %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x3062
movq %rbx, %rdi
movl %r15d, %esi
movl %r12d, %edx
jmp 0x4b2d
cmpb $0x1, 0x42(%r14)
jne 0x4b40
leaq 0x38(%r14), %r13
pushq $0x4
popq %rsi
movq %r13, %rdi
xorl %edx, %edx
callq 0x3062
addq $0x28, %r14
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3062
pushq $0x2
popq %r12
pushq $0x1
popq %r15
movq %r13, %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x3062
pushq $0x3
popq %r13
movq %r14, %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x3062
movq %rbx, %rdi
pushq $0x4
popq %rsi
xorl %edx, %edx
callq 0x3062
movq %rbx, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x3062
movq %rbx, %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x3062
movq %rbx, %rdi
movl %r13d, %esi
movl %r15d, %edx
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3062
movq 0x7489(%rip), %rdi      # 0xbfd0
leaq 0x3ce9(%rip), %rsi      # 0x8837
callq 0x2180
movq %rax, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x20c0
nop