// File: /workspace/github_cpp_makefile_star2_O3/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), %r14
cmovneq %rdx, %rsi
movq (%rsi), %r13
cmovneq %r8, %r9
movq (%r9), %rbp
testq %r14, %r14
je 0x3f1a
bsfq %r14, %r12
movl %r12d, %edi
movq %r15, %rsi
movl $0x3, %edx
callq 0x357e
andq (%rsp), %rax
je 0x3f11
bsfq %rax, %rcx
shll $0x6, %ecx
orl %r12d, %ecx
movl %ecx, (%rbx)
addq $0x8, %rbx
leaq -0x1(%rax), %rcx
andq %rcx, %rax
jne 0x3ef8
leaq -0x1(%r14), %rax
andq %rax, %r14
jne 0x3ede
testq %r13, %r13
je 0x3f60
movq (%rsp), %r14
bsfq %r13, %r12
movl %r12d, %edi
movq %r15, %rsi
movl $0x2, %edx
callq 0x357e
andq %r14, %rax
je 0x3f55
bsfq %rax, %rcx
shll $0x6, %ecx
orl %r12d, %ecx
movl %ecx, (%rbx)
addq $0x8, %rbx
leaq -0x1(%rax), %rcx
andq %rcx, %rax
jne 0x3f3c
leaq -0x1(%r13), %rax
andq %rax, %r13
jne 0x3f23
jmp 0x3f64
movq (%rsp), %r14
testq %rbp, %rbp
je 0x3fba
bsfq %rbp, %r12
movl %r12d, %edi
movq %r15, %rsi
movl $0x3, %edx
callq 0x357e
movq %rax, %r13
movl %r12d, %edi
movq %r15, %rsi
movl $0x2, %edx
callq 0x357e
orq %r13, %rax
andq %r14, %rax
je 0x3fb1
bsfq %rax, %rcx
shll $0x6, %ecx
orl %r12d, %ecx
movl %ecx, (%rbx)
addq $0x8, %rbx
leaq -0x1(%rax), %rcx
andq %rcx, %rax
jne 0x3f98
leaq -0x1(%rbp), %rax
andq %rax, %rbp
jne 0x3f69
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq