// File: niekh1234[P]nnchesslib/movegen.cpp
// Function: nnchesslib::genCastlingMoves(nnchesslib::ChessBoard, std::vector<unsigned int, std::allocator<unsigned int>>&, nnchesslib::Color, nnchesslib::BitBoard)
void nnchesslib::genCastlingMoves(ChessBoard board, MoveList& moveList, Color color, BitBoard blockers)
{
    if(color == WHITE)
    {
        // white queenside:
        bool attackedSquaresQS = board.squareAttacked(C1, color) || board.squareAttacked(D1, color) || board.squareAttacked(E1, color);
        if(board.boardinfo.whiteCastleLong && !blockers.get(B1) && !blockers.get(C1) && !blockers.get(D1) && !attackedSquaresQS)
        {
            Move move = createMove(E1, C1, CASTLING);
            moveList.push_back(move);
        } 
        // white kingside:
        bool attackedSquaresKS = board.squareAttacked(F1, color) || board.squareAttacked(G1, color) || board.squareAttacked(E1, color);
        if(board.boardinfo.whiteCastleShort && !blockers.get(F1) && !blockers.get(G1) && !attackedSquaresKS)
        {
            Move move = createMove(E1, G1, CASTLING);
            moveList.push_back(move);
        }
    }
    if(color == BLACK)
    {
        // black queenside:
        bool attackedSquaresQS = board.squareAttacked(C8, color) || board.squareAttacked(D8, color) || board.squareAttacked(E8, color);
        if(board.boardinfo.blackCastleLong && !blockers.get(B8) && !blockers.get(C8) && !blockers.get(D8) && !attackedSquaresQS)
        {
            Move move = createMove(E8, C8, CASTLING);
            moveList.push_back(move);
        } 
        // black kingside:
        bool attackedSquaresKS = board.squareAttacked(F8, color) || board.squareAttacked(G8, color) || board.squareAttacked(E8, color);
        if(board.boardinfo.blackCastleShort && !blockers.get(F8) && !blockers.get(G8) && !attackedSquaresKS)
        {
            Move move = createMove(E8, G8, CASTLING);
            moveList.push_back(move);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
leaq 0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
movq %rdx, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
cmpl $0x1, -0x14(%rbp)
jne 0xc26c
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %edx
movl $0x2, %esi
callq 0x7af0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x41(%rbp)
jne 0xc143
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %edx
movl $0x3, %esi
callq 0x7af0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x41(%rbp)
jne 0xc143
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %edx
movl $0x4, %esi
callq 0x7af0
movb %al, -0x41(%rbp)
movq -0x40(%rbp), %rax
movb -0x41(%rbp), %cl
andb $0x1, %cl
movb %cl, -0x15(%rbp)
testb $0x1, 0x42(%rax)
je 0xc1b9
leaq -0x8(%rbp), %rdi
movl $0x1, %esi
callq 0x4ce0
cmpl $0x0, %eax
jne 0xc1b9
leaq -0x8(%rbp), %rdi
movl $0x2, %esi
callq 0x4ce0
cmpl $0x0, %eax
jne 0xc1b9
leaq -0x8(%rbp), %rdi
movl $0x3, %esi
callq 0x4ce0
cmpl $0x0, %eax
jne 0xc1b9
testb $0x1, -0x15(%rbp)
jne 0xc1b9
movl $0x4, %edi
movl $0x2, %esi
movl $0x3, %edx
callq 0xab00
movl %eax, -0x1c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x1c(%rbp), %rsi
callq 0xcbd0
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %edx
movl $0x5, %esi
callq 0x7af0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x42(%rbp)
jne 0xc207
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %edx
movl $0x6, %esi
callq 0x7af0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x42(%rbp)
jne 0xc207
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %edx
movl $0x4, %esi
callq 0x7af0
movb %al, -0x42(%rbp)
movq -0x40(%rbp), %rax
movb -0x42(%rbp), %cl
andb $0x1, %cl
movb %cl, -0x1d(%rbp)
testb $0x1, 0x41(%rax)
je 0xc26a
leaq -0x8(%rbp), %rdi
movl $0x5, %esi
callq 0x4ce0
cmpl $0x0, %eax
jne 0xc26a
leaq -0x8(%rbp), %rdi
movl $0x6, %esi
callq 0x4ce0
cmpl $0x0, %eax
jne 0xc26a
testb $0x1, -0x1d(%rbp)
jne 0xc26a
movl $0x4, %edi
movl $0x6, %esi
movl $0x3, %edx
callq 0xab00
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x24(%rbp), %rsi
callq 0xcbd0
jmp 0xc26c
cmpl $0x0, -0x14(%rbp)
jne 0xc3ed
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %edx
movl $0x3a, %esi
callq 0x7af0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x43(%rbp)
jne 0xc2c4
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %edx
movl $0x3b, %esi
callq 0x7af0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x43(%rbp)
jne 0xc2c4
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %edx
movl $0x3c, %esi
callq 0x7af0
movb %al, -0x43(%rbp)
movq -0x40(%rbp), %rax
movb -0x43(%rbp), %cl
andb $0x1, %cl
movb %cl, -0x25(%rbp)
testb $0x1, 0x44(%rax)
je 0xc33a
leaq -0x8(%rbp), %rdi
movl $0x39, %esi
callq 0x4ce0
cmpl $0x0, %eax
jne 0xc33a
leaq -0x8(%rbp), %rdi
movl $0x3a, %esi
callq 0x4ce0
cmpl $0x0, %eax
jne 0xc33a
leaq -0x8(%rbp), %rdi
movl $0x3b, %esi
callq 0x4ce0
cmpl $0x0, %eax
jne 0xc33a
testb $0x1, -0x25(%rbp)
jne 0xc33a
movl $0x3c, %edi
movl $0x3a, %esi
movl $0x3, %edx
callq 0xab00
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0xcbd0
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %edx
movl $0x3d, %esi
callq 0x7af0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x44(%rbp)
jne 0xc388
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %edx
movl $0x3e, %esi
callq 0x7af0
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x44(%rbp)
jne 0xc388
movq -0x40(%rbp), %rdi
movl -0x14(%rbp), %edx
movl $0x3c, %esi
callq 0x7af0
movb %al, -0x44(%rbp)
movq -0x40(%rbp), %rax
movb -0x44(%rbp), %cl
andb $0x1, %cl
movb %cl, -0x2d(%rbp)
testb $0x1, 0x43(%rax)
je 0xc3eb
leaq -0x8(%rbp), %rdi
movl $0x3d, %esi
callq 0x4ce0
cmpl $0x0, %eax
jne 0xc3eb
leaq -0x8(%rbp), %rdi
movl $0x3e, %esi
callq 0x4ce0
cmpl $0x0, %eax
jne 0xc3eb
testb $0x1, -0x2d(%rbp)
jne 0xc3eb
movl $0x3c, %edi
movl $0x3e, %esi
movl $0x3, %edx
callq 0xab00
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0xcbd0
jmp 0xc3ed
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)