// File: 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
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
movl -0xc(%rbp), %edi
callq 0xaa40
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %edi
callq 0xaa60
movq -0x28(%rbp), %rdi
movl %eax, -0x14(%rbp)
movl -0x10(%rbp), %esi
callq 0x7a20
movq %rax, -0x20(%rbp)
cmpl $0x6, -0x14(%rbp)
jne 0x81d6
movq -0x28(%rbp), %rax
testb $0x1, 0x41(%rax)
je 0x81d6
movq -0x28(%rbp), %rdi
addq $0x38, %rdi
movl $0x4, %esi
xorl %edx, %edx
callq 0x4c40
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
movl $0x7, %esi
xorl %edx, %edx
callq 0x4c40
movq -0x28(%rbp), %rdi
addq $0x38, %rdi
movl $0x6, %esi
movl $0x1, %edx
callq 0x4c40
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
movl $0x5, %esi
movl $0x1, %edx
callq 0x4c40
movq -0x20(%rbp), %rdi
movl $0x4, %esi
xorl %edx, %edx
callq 0x4c40
movq -0x20(%rbp), %rdi
movl $0x7, %esi
xorl %edx, %edx
callq 0x4c40
movq -0x20(%rbp), %rdi
movl $0x6, %esi
movl $0x1, %edx
callq 0x4c40
movq -0x20(%rbp), %rdi
movl $0x5, %esi
movl $0x1, %edx
callq 0x4c40
jmp 0x8420
cmpl $0x2, -0x14(%rbp)
jne 0x8289
movq -0x28(%rbp), %rax
testb $0x1, 0x42(%rax)
je 0x8289
movq -0x28(%rbp), %rdi
addq $0x38, %rdi
movl $0x4, %esi
xorl %edx, %edx
callq 0x4c40
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x4c40
movq -0x28(%rbp), %rdi
addq $0x38, %rdi
movl $0x2, %esi
movl $0x1, %edx
callq 0x4c40
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
movl $0x3, %esi
movl $0x1, %edx
callq 0x4c40
movq -0x20(%rbp), %rdi
movl $0x4, %esi
xorl %edx, %edx
callq 0x4c40
movq -0x20(%rbp), %rdi
xorl %edx, %edx
movl %edx, %esi
callq 0x4c40
movq -0x20(%rbp), %rdi
movl $0x2, %esi
movl $0x1, %edx
callq 0x4c40
movq -0x20(%rbp), %rdi
movl $0x3, %esi
movl $0x1, %edx
callq 0x4c40
jmp 0x841e
cmpl $0x3a, -0x14(%rbp)
jne 0x8342
movq -0x28(%rbp), %rax
testb $0x1, 0x44(%rax)
je 0x8342
movq -0x28(%rbp), %rdi
addq $0x38, %rdi
movl $0x3c, %esi
xorl %edx, %edx
callq 0x4c40
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
movl $0x3f, %esi
xorl %edx, %edx
callq 0x4c40
movq -0x28(%rbp), %rdi
addq $0x38, %rdi
movl $0x3e, %esi
movl $0x1, %edx
callq 0x4c40
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
movl $0x3d, %esi
movl $0x1, %edx
callq 0x4c40
movq -0x20(%rbp), %rdi
movl $0x3c, %esi
xorl %edx, %edx
callq 0x4c40
movq -0x20(%rbp), %rdi
movl $0x3f, %esi
xorl %edx, %edx
callq 0x4c40
movq -0x20(%rbp), %rdi
movl $0x3e, %esi
movl $0x1, %edx
callq 0x4c40
movq -0x20(%rbp), %rdi
movl $0x3d, %esi
movl $0x1, %edx
callq 0x4c40
jmp 0x841c
cmpl $0x3e, -0x14(%rbp)
jne 0x83f8
movq -0x28(%rbp), %rax
testb $0x1, 0x43(%rax)
je 0x83f8
movq -0x28(%rbp), %rdi
addq $0x38, %rdi
movl $0x3c, %esi
xorl %edx, %edx
callq 0x4c40
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
movl $0x38, %esi
xorl %edx, %edx
callq 0x4c40
movq -0x28(%rbp), %rdi
addq $0x38, %rdi
movl $0x3a, %esi
movl $0x1, %edx
callq 0x4c40
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
movl $0x3b, %esi
movl $0x1, %edx
callq 0x4c40
movq -0x20(%rbp), %rdi
movl $0x3c, %esi
xorl %edx, %edx
callq 0x4c40
movq -0x20(%rbp), %rdi
movl $0x38, %esi
xorl %edx, %edx
callq 0x4c40
movq -0x20(%rbp), %rdi
movl $0x3a, %esi
movl $0x1, %edx
callq 0x4c40
movq -0x20(%rbp), %rdi
movl $0x3b, %esi
movl $0x1, %edx
callq 0x4c40
jmp 0x841a
movq 0xabd1(%rip), %rdi      # 0x12fd0
leaq 0x6591(%rip), %rsi      # 0xe997
callq 0x3250
movq %rax, %rdi
movq 0xaba3(%rip), %rsi      # 0x12fb8
callq 0x3290
jmp 0x841c
jmp 0x841e
jmp 0x8420
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)