// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0x40, -0x54(%rbp)
movl $0x40, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movq -0x8(%rbp), %rdi
callq 0x75c0
movl %eax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
callq 0x7690
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movl -0x60(%rbp), %esi
movl $0x3, %edx
callq 0x76b0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rdi
movl -0x60(%rbp), %esi
movl $0x2, %edx
callq 0x76b0
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rdi
movl -0x60(%rbp), %esi
movl $0x4, %edx
callq 0x76b0
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x6930
movq -0x28(%rbp), %rdi
callq 0x7780
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0x54(%rbp), %edi
movq -0x20(%rbp), %rsi
movl $0x3, %edx
callq 0x57b0
movq %rax, %rcx
movq -0x68(%rbp), %rax
andq %rcx, %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0x6922
movq -0x30(%rbp), %rdi
callq 0x7780
movl %eax, -0x58(%rbp)
movl -0x54(%rbp), %edi
movl -0x58(%rbp), %esi
callq 0x77d0
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %ecx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x18(%rbp)
movl %ecx, (%rax)
leaq -0x30(%rbp), %rdi
callq 0x77a0
jmp 0x68e2
leaq -0x28(%rbp), %rdi
callq 0x77a0
jmp 0x68a4
jmp 0x6932
cmpq $0x0, -0x38(%rbp)
je 0x69be
movq -0x38(%rbp), %rdi
callq 0x7780
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x70(%rbp)
movl -0x54(%rbp), %edi
movq -0x20(%rbp), %rsi
movl $0x2, %edx
callq 0x57b0
movq %rax, %rcx
movq -0x70(%rbp), %rax
andq %rcx, %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x69b0
movq -0x40(%rbp), %rdi
callq 0x7780
movl %eax, -0x58(%rbp)
movl -0x54(%rbp), %edi
movl -0x58(%rbp), %esi
callq 0x77d0
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %ecx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x18(%rbp)
movl %ecx, (%rax)
leaq -0x40(%rbp), %rdi
callq 0x77a0
jmp 0x6970
leaq -0x38(%rbp), %rdi
callq 0x77a0
jmp 0x6932
jmp 0x69c0
cmpq $0x0, -0x48(%rbp)
je 0x6a68
movq -0x48(%rbp), %rdi
callq 0x7780
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0x54(%rbp), %edi
movq -0x20(%rbp), %rsi
movl $0x3, %edx
callq 0x57b0
movq %rax, -0x80(%rbp)
movl -0x54(%rbp), %edi
movq -0x20(%rbp), %rsi
movl $0x2, %edx
callq 0x57b0
movq -0x80(%rbp), %rcx
movq %rax, %rdx
movq -0x78(%rbp), %rax
orq %rdx, %rcx
andq %rcx, %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x6a5a
movq -0x50(%rbp), %rdi
callq 0x7780
movl %eax, -0x58(%rbp)
movl -0x54(%rbp), %edi
movl -0x58(%rbp), %esi
callq 0x77d0
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %ecx
movq -0x18(%rbp), %rax
movq %rax, %rdx
addq $0x8, %rdx
movq %rdx, -0x18(%rbp)
movl %ecx, (%rax)
leaq -0x50(%rbp), %rdi
callq 0x77a0
jmp 0x6a1a
leaq -0x48(%rbp), %rdi
callq 0x77a0
jmp 0x69c0
movq -0x18(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)