// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rdi, %rbx
leaq 0x10(%rbp), %r14
movq %rdx, -0x20(%rbp)
testl %esi, %esi
je 0x6a70
cmpl $0x1, %esi
jne 0x6b7c
pushq $0x2
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x4580
movb $0x1, %r15b
testb %al, %al
jne 0x699c
pushq $0x3
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x4580
testb %al, %al
jne 0x699c
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x4580
movl %eax, %r15d
cmpb $0x1, 0x42(%r14)
jne 0x69f5
leaq -0x20(%rbp), %rdi
pushq $0x1
popq %rsi
callq 0x30a4
testl %eax, %eax
jne 0x69f5
leaq -0x20(%rbp), %rdi
pushq $0x2
popq %rsi
callq 0x30a4
testl %eax, %eax
jne 0x69f5
leaq -0x20(%rbp), %rdi
pushq $0x3
popq %rsi
callq 0x30a4
testl %eax, %eax
setne %al
orb %al, %r15b
jne 0x69f5
pushq $0x4
popq %rdi
pushq $0x2
popq %rsi
pushq $0x3
popq %rdx
callq 0x5c2c
leaq -0x24(%rbp), %rsi
movl %eax, (%rsi)
movq %rbx, %rdi
callq 0x71b0
pushq $0x5
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x4580
movb $0x1, %r15b
testb %al, %al
jne 0x6a2d
pushq $0x6
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x4580
testb %al, %al
jne 0x6a2d
pushq $0x4
popq %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x4580
movl %eax, %r15d
cmpb $0x1, 0x41(%r14)
jne 0x6b7c
leaq -0x20(%rbp), %rdi
pushq $0x5
popq %rsi
callq 0x30a4
testl %eax, %eax
jne 0x6b7c
leaq -0x20(%rbp), %rdi
pushq $0x6
popq %rsi
callq 0x30a4
testl %eax, %eax
setne %al
orb %al, %r15b
jne 0x6b7c
pushq $0x4
popq %rdi
pushq $0x6
jmp 0x6b65
pushq $0x3a
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x4580
movb $0x1, %r15b
testb %al, %al
jne 0x6aa5
pushq $0x3b
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x4580
testb %al, %al
jne 0x6aa5
pushq $0x3c
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x4580
movl %eax, %r15d
cmpb $0x1, 0x44(%r14)
jne 0x6afe
leaq -0x20(%rbp), %rdi
pushq $0x39
popq %rsi
callq 0x30a4
testl %eax, %eax
jne 0x6afe
leaq -0x20(%rbp), %rdi
pushq $0x3a
popq %rsi
callq 0x30a4
testl %eax, %eax
jne 0x6afe
leaq -0x20(%rbp), %rdi
pushq $0x3b
popq %rsi
callq 0x30a4
testl %eax, %eax
setne %al
orb %al, %r15b
jne 0x6afe
pushq $0x3c
popq %rdi
pushq $0x3a
popq %rsi
pushq $0x3
popq %rdx
callq 0x5c2c
leaq -0x24(%rbp), %rsi
movl %eax, (%rsi)
movq %rbx, %rdi
callq 0x71b0
pushq $0x3d
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x4580
movb $0x1, %r15b
testb %al, %al
jne 0x6b33
pushq $0x3e
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x4580
testb %al, %al
jne 0x6b33
pushq $0x3c
popq %rsi
movq %r14, %rdi
xorl %edx, %edx
callq 0x4580
movl %eax, %r15d
cmpb $0x1, 0x43(%r14)
jne 0x6b7c
leaq -0x20(%rbp), %rdi
pushq $0x3d
popq %rsi
callq 0x30a4
testl %eax, %eax
jne 0x6b7c
leaq -0x20(%rbp), %rdi
pushq $0x3e
popq %rsi
callq 0x30a4
testl %eax, %eax
setne %al
orb %al, %r15b
jne 0x6b7c
pushq $0x3c
popq %rdi
pushq $0x3e
popq %rsi
pushq $0x3
popq %rdx
callq 0x5c2c
leaq -0x24(%rbp), %rsi
movl %eax, (%rsi)
movq %rbx, %rdi
callq 0x71b0
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq