// File: /workspace/github_cpp_makefile_star2_O2/bjohnsonfl[P]Overhead-Chess-Engine-/moveGen.cpp
// Function: sliderMoves(position const&, unsigned long, candidate*)
candidate* sliderMoves (const position& pos, bitboard target, candidate* moveList)
{
    // if target is of empty squares, its quiet moves.
    // if target is of enemy pieces, its captures.
    bitboard occupency, rooks, rookSquares, bishops, bishopSquares, queens, queenSquares;
    square from = empty, to = empty;
    move mov = none;
    player color = pos.get_sideToPlay();
    occupency = pos.get_pieces();
    rooks = pos.get_pieces(color, p_rook);
    bishops = pos.get_pieces(color, p_bishop);
    queens = pos.get_pieces(color, p_queen);
    
    
    while(rooks)
    {
        from = lsb_sq(rooks);
        //check now if the from square is absolute pinned
        rookSquares = target & sliderAttacks(from, occupency, p_rook);
        //printBitboard(rookSquares);
        while(rookSquares)
        {
             //could check here if the to square places their king in check
            to = lsb_sq(rookSquares);
            mov = make_move(from, to);
            (*moveList++).mv = mov;
            pop_lsb(&rookSquares);
        }
        pop_lsb(&rooks);
    }
    
    while(bishops)
    {
        from = lsb_sq(bishops);
        //check now if the from square is absolute pinned
        bishopSquares = target & sliderAttacks(from, occupency, p_bishop);
        
        while(bishopSquares)
        {
            //could check here if the to square places their king in check
            to = lsb_sq(bishopSquares);
            mov = make_move(from, to);
            (*moveList++).mv = mov;
            pop_lsb(&bishopSquares);
        }
        pop_lsb(&bishops);
    }
    
    while(queens)
    {
        from = lsb_sq(queens);
        //check now if the from square is absolute pinned
        queenSquares = target & (sliderAttacks(from, occupency, p_rook) | sliderAttacks(from, occupency, p_bishop));
        //printBitboard(queenSquares);
        while(queenSquares)
        {
            //could check here if the to square places their king in check
            to = lsb_sq(queenSquares);
            mov = make_move(from, to);
            (*moveList++).mv = mov;
            pop_lsb(&queenSquares);
        }
        pop_lsb(&queens);
    }
    
    
    
    
    
    return moveList;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %rbx
movq %rsi, (%rsp)
movq 0x170(%rdi), %r15
leaq 0x148(%rdi), %rax
leaq 0x118(%rdi), %rcx
leaq 0x140(%rdi), %rdx
leaq 0x110(%rdi), %rsi
leaq 0x150(%rdi), %r8
leaq 0x120(%rdi), %r9
cmpl $0x0, 0x17c(%rdi)
cmoveq %rcx, %rax
movq (%rax), %rbp
cmovneq %rdx, %rsi
movq (%rsi), %r13
cmovneq %r8, %r9
movq (%r9), %r14
testq %rbp, %rbp
je 0x3d2e
bsfq %rbp, %r12
movl %r12d, %edi
movq %r15, %rsi
pushq $0x3
popq %rdx
callq 0x33a4
andq (%rsp), %rax
testq %rax, %rax
je 0x3d25
bsfq %rax, %rcx
shll $0x6, %ecx
orl %r12d, %ecx
movl %ecx, (%rbx)
addq $0x8, %rbx
leaq -0x1(%rax), %rcx
andq %rcx, %rax
jmp 0x3d07
leaq -0x1(%rbp), %rax
andq %rax, %rbp
jmp 0x3cec
pushq $0x2
popq %rbp
testq %r13, %r13
je 0x3d72
bsfq %r13, %r12
movl %r12d, %edi
movq %r15, %rsi
movl %ebp, %edx
callq 0x33a4
andq (%rsp), %rax
testq %rax, %rax
je 0x3d69
bsfq %rax, %rcx
shll $0x6, %ecx
orl %r12d, %ecx
movl %ecx, (%rbx)
addq $0x8, %rbx
leaq -0x1(%rax), %rcx
andq %rcx, %rax
jmp 0x3d4b
leaq -0x1(%r13), %rax
andq %rax, %r13
jmp 0x3d31
pushq $0x2
popq %r12
testq %r14, %r14
je 0x3dcc
bsfq %r14, %r13
movl %r13d, %edi
movq %r15, %rsi
pushq $0x3
popq %rdx
callq 0x33a4
movq %rax, %rbp
movl %r13d, %edi
movq %r15, %rsi
movl %r12d, %edx
callq 0x33a4
orq %rbp, %rax
andq (%rsp), %rax
testq %rax, %rax
je 0x3dc3
bsfq %rax, %rcx
shll $0x6, %ecx
orl %r13d, %ecx
movl %ecx, (%rbx)
addq $0x8, %rbx
leaq -0x1(%rax), %rcx
andq %rcx, %rax
jmp 0x3da5
leaq -0x1(%r14), %rax
andq %rax, %r14
jmp 0x3d76
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq