// File: /workspace/github_cpp_makefile_star2_O3/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, -0x28(%rbp)
testl %esi, %esi
je 0x7a85
cmpl $0x1, %esi
jne 0x7c94
movq %r14, %rdi
movl $0x2, %esi
movl $0x1, %edx
callq 0x4fa8
movb $0x1, %r15b
testb %al, %al
jne 0x79fe
movq %r14, %rdi
movl $0x3, %esi
movl $0x1, %edx
callq 0x4fa8
testb %al, %al
jne 0x79fe
movq %r14, %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x4fa8
movl %eax, %r15d
cmpb $0x1, 0x42(%r14)
jne 0x7b53
leaq -0x28(%rbp), %rdi
movl $0x1, %esi
callq 0x33f8
testl %eax, %eax
jne 0x7b53
leaq -0x28(%rbp), %rdi
movl $0x2, %esi
callq 0x33f8
testl %eax, %eax
jne 0x7b53
leaq -0x28(%rbp), %rdi
movl $0x3, %esi
callq 0x33f8
testl %eax, %eax
setne %al
orb %al, %r15b
jne 0x7b53
movl $0x4, %edi
movl $0x2, %esi
movl $0x3, %edx
callq 0x6ab0
movl %eax, -0x1c(%rbp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x7b47
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x7b53
movq %r14, %rdi
movl $0x3a, %esi
xorl %edx, %edx
callq 0x4fa8
movb $0x1, %r15b
testb %al, %al
jne 0x7ac0
movq %r14, %rdi
movl $0x3b, %esi
xorl %edx, %edx
callq 0x4fa8
testb %al, %al
jne 0x7ac0
movq %r14, %rdi
movl $0x3c, %esi
xorl %edx, %edx
callq 0x4fa8
movl %eax, %r15d
cmpb $0x1, 0x44(%r14)
jne 0x7bef
leaq -0x28(%rbp), %rdi
movl $0x39, %esi
callq 0x33f8
testl %eax, %eax
jne 0x7bef
leaq -0x28(%rbp), %rdi
movl $0x3a, %esi
callq 0x33f8
testl %eax, %eax
jne 0x7bef
leaq -0x28(%rbp), %rdi
movl $0x3b, %esi
callq 0x33f8
testl %eax, %eax
setne %al
orb %al, %r15b
jne 0x7bef
movl $0x3c, %edi
movl $0x3a, %esi
movl $0x3, %edx
callq 0x6ab0
movl %eax, -0x1c(%rbp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x7be3
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x7bef
leaq -0x1c(%rbp), %rdx
movq %rbx, %rdi
callq 0x83a8
movq %r14, %rdi
movl $0x5, %esi
movl $0x1, %edx
callq 0x4fa8
movb $0x1, %r15b
testb %al, %al
jne 0x7b97
movq %r14, %rdi
movl $0x6, %esi
movl $0x1, %edx
callq 0x4fa8
testb %al, %al
jne 0x7b97
movq %r14, %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x4fa8
movl %eax, %r15d
cmpb $0x1, 0x41(%r14)
jne 0x7c94
leaq -0x28(%rbp), %rdi
movl $0x5, %esi
callq 0x33f8
testl %eax, %eax
jne 0x7c94
leaq -0x28(%rbp), %rdi
movl $0x6, %esi
callq 0x33f8
testl %eax, %eax
setne %al
orb %al, %r15b
jne 0x7c94
movl $0x4, %edi
movl $0x6, %esi
jmp 0x7c65
leaq -0x1c(%rbp), %rdx
movq %rbx, %rdi
callq 0x83a8
movq %r14, %rdi
movl $0x3d, %esi
xorl %edx, %edx
callq 0x4fa8
movb $0x1, %r15b
testb %al, %al
jne 0x7c2a
movq %r14, %rdi
movl $0x3e, %esi
xorl %edx, %edx
callq 0x4fa8
testb %al, %al
jne 0x7c2a
movq %r14, %rdi
movl $0x3c, %esi
xorl %edx, %edx
callq 0x4fa8
movl %eax, %r15d
cmpb $0x1, 0x43(%r14)
jne 0x7c94
leaq -0x28(%rbp), %rdi
movl $0x3d, %esi
callq 0x33f8
testl %eax, %eax
jne 0x7c94
leaq -0x28(%rbp), %rdi
movl $0x3e, %esi
callq 0x33f8
testl %eax, %eax
setne %al
orb %al, %r15b
jne 0x7c94
movl $0x3c, %edi
movl $0x3e, %esi
movl $0x3, %edx
callq 0x6ab0
movl %eax, -0x1c(%rbp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x7c88
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x7c94
leaq -0x1c(%rbp), %rdx
movq %rbx, %rdi
callq 0x83a8
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq