// File: /workspace/github_cpp_makefile_star2_O1/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 %r12
pushq %rbx
subq $0x10, %rsp
movq %rdi, %rbx
leaq 0x10(%rbp), %r14
movq %rdx, -0x30(%rbp)
testl %esi, %esi
je 0x7ba4
movl %esi, %r15d
cmpl $0x1, %esi
jne 0x7d00
movq %r14, %rdi
movl $0x2, %esi
movl $0x1, %edx
callq 0x4f94
movb $0x1, %r12b
testb %al, %al
jne 0x7a71
movq %r14, %rdi
movl $0x3, %esi
movl $0x1, %edx
callq 0x4f94
testb %al, %al
jne 0x7a71
movq %r14, %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x4f94
movl %eax, %r12d
cmpb $0x1, 0x42(%r14)
jne 0x7aed
leaq -0x30(%rbp), %rdi
movl $0x1, %esi
callq 0x33bc
testl %eax, %eax
jne 0x7aed
leaq -0x30(%rbp), %rdi
movl $0x2, %esi
callq 0x33bc
testl %eax, %eax
jne 0x7aed
leaq -0x30(%rbp), %rdi
movl $0x3, %esi
callq 0x33bc
testl %eax, %eax
setne %al
orb %al, %r12b
jne 0x7aed
movl $0x4, %edi
movl $0x2, %esi
movl $0x3, %edx
callq 0x6aac
movl %eax, -0x24(%rbp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x7ae1
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x7aed
leaq -0x24(%rbp), %rdx
movq %rbx, %rdi
callq 0x845c
movq %r14, %rdi
movl $0x5, %esi
movl $0x1, %edx
callq 0x4f94
movb $0x1, %r12b
testb %al, %al
jne 0x7b31
movq %r14, %rdi
movl $0x6, %esi
movl $0x1, %edx
callq 0x4f94
testb %al, %al
jne 0x7b31
movq %r14, %rdi
movl $0x4, %esi
movl $0x1, %edx
callq 0x4f94
movl %eax, %r12d
cmpb $0x1, 0x41(%r14)
jne 0x7b9b
leaq -0x30(%rbp), %rdi
movl $0x5, %esi
callq 0x33bc
testl %eax, %eax
jne 0x7b9b
leaq -0x30(%rbp), %rdi
movl $0x6, %esi
callq 0x33bc
testl %eax, %eax
setne %al
orb %al, %r12b
jne 0x7b9b
movl $0x4, %edi
movl $0x6, %esi
movl $0x3, %edx
callq 0x6aac
movl %eax, -0x24(%rbp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x7b8f
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x7b9b
leaq -0x24(%rbp), %rdx
movq %rbx, %rdi
callq 0x845c
testl %r15d, %r15d
jne 0x7d00
movq %r14, %rdi
movl $0x3a, %esi
xorl %edx, %edx
callq 0x4f94
movb $0x1, %r15b
testb %al, %al
jne 0x7bdf
movq %r14, %rdi
movl $0x3b, %esi
xorl %edx, %edx
callq 0x4f94
testb %al, %al
jne 0x7bdf
movq %r14, %rdi
movl $0x3c, %esi
xorl %edx, %edx
callq 0x4f94
movl %eax, %r15d
cmpb $0x1, 0x44(%r14)
jne 0x7c5b
leaq -0x30(%rbp), %rdi
movl $0x39, %esi
callq 0x33bc
testl %eax, %eax
jne 0x7c5b
leaq -0x30(%rbp), %rdi
movl $0x3a, %esi
callq 0x33bc
testl %eax, %eax
jne 0x7c5b
leaq -0x30(%rbp), %rdi
movl $0x3b, %esi
callq 0x33bc
testl %eax, %eax
setne %al
orb %al, %r15b
jne 0x7c5b
movl $0x3c, %edi
movl $0x3a, %esi
movl $0x3, %edx
callq 0x6aac
movl %eax, -0x24(%rbp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x7c4f
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x7c5b
leaq -0x24(%rbp), %rdx
movq %rbx, %rdi
callq 0x845c
movq %r14, %rdi
movl $0x3d, %esi
xorl %edx, %edx
callq 0x4f94
movb $0x1, %r15b
testb %al, %al
jne 0x7c96
movq %r14, %rdi
movl $0x3e, %esi
xorl %edx, %edx
callq 0x4f94
testb %al, %al
jne 0x7c96
movq %r14, %rdi
movl $0x3c, %esi
xorl %edx, %edx
callq 0x4f94
movl %eax, %r15d
cmpb $0x1, 0x43(%r14)
jne 0x7d00
leaq -0x30(%rbp), %rdi
movl $0x3d, %esi
callq 0x33bc
testl %eax, %eax
jne 0x7d00
leaq -0x30(%rbp), %rdi
movl $0x3e, %esi
callq 0x33bc
testl %eax, %eax
setne %al
orb %al, %r15b
jne 0x7d00
movl $0x3c, %edi
movl $0x3e, %esi
movl $0x3, %edx
callq 0x6aac
movl %eax, -0x24(%rbp)
movq 0x8(%rbx), %rsi
cmpq 0x10(%rbx), %rsi
je 0x7cf4
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x8(%rbx)
jmp 0x7d00
leaq -0x24(%rbp), %rdx
movq %rbx, %rdi
callq 0x845c
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq