// File: bjohnsonfl[P]Overhead-Chess-Engine-/position.cpp
// Function: position::pinningBoards(square, unsigned long&, player)
bitboard position:: pinningBoards(square sq, bitboard &pinners, player color)
{

    player us = color;
    player them = player(!us);
    bitboard enemyRookQueen = get_pieces(p_queen, p_rook) & get_pieces(them);
    bitboard enemyBishopQueen = get_pieces(p_queen, p_bishop) & get_pieces(them);
    bitboard snipers = 0, pinned = 0, pinnedHold = 0;
    bitboard ourPieces = get_pieces(us);
    square piece = empty;
    
    snipers = xRayRook(get_pieces(), get_pieces(us), sq) & enemyRookQueen;
    while(snipers)
    {
        piece = square (lsb_sq(snipers));
        pinnedHold |= inBetweenSqBitMask[sq][piece] & ourPieces;
        if(pinnedHold != pinned) pinners |= squareBitMask[piece];
        pinned |= pinnedHold;
        pop_lsb(&snipers);
    }
    
    snipers = xRayBishop(get_pieces(), get_pieces(us), sq) & enemyBishopQueen;
    while(snipers)
    {
        piece = square (lsb_sq(snipers));
        pinnedHold |= inBetweenSqBitMask[sq][piece] & ourPieces;
        if(pinnedHold != pinned) pinners |= squareBitMask[piece];
        pinned |= pinnedHold;
        pop_lsb(&snipers);
    }
    
    return pinned;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0x70(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %eax
movl %eax, -0x24(%rbp)
movl $0x4, %esi
movl $0x3, %edx
callq 0x7700
movq -0x70(%rbp), %rdi
movq %rax, -0x80(%rbp)
movl -0x24(%rbp), %esi
callq 0x7600
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movq -0x80(%rbp), %rax
andq %rcx, %rax
movq %rax, -0x30(%rbp)
movl $0x4, %esi
movl $0x2, %edx
callq 0x7700
movq -0x70(%rbp), %rdi
movq %rax, -0x78(%rbp)
movl -0x24(%rbp), %esi
callq 0x7600
movq -0x70(%rbp), %rdi
movq %rax, %rcx
movq -0x78(%rbp), %rax
andq %rcx, %rax
movq %rax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movl -0x20(%rbp), %esi
callq 0x7600
movq -0x70(%rbp), %rdi
movq %rax, -0x58(%rbp)
movl $0x40, -0x5c(%rbp)
callq 0x7690
movq -0x70(%rbp), %rdi
movq %rax, -0x68(%rbp)
movl -0x20(%rbp), %esi
callq 0x7600
movq -0x70(%rbp), %rdi
movq -0x68(%rbp), %rsi
movq %rax, %rdx
movl -0xc(%rbp), %ecx
callq 0x9a30
andq -0x30(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x97ed
movq -0x40(%rbp), %rdi
callq 0x7780
movl %eax, -0x5c(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %ecx
leaq 0xae08(%rip), %rax      # 0x145a0
shlq $0x9, %rcx
addq %rcx, %rax
movl -0x5c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
andq -0x58(%rbp), %rax
orq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x97d6
movl -0x5c(%rbp), %eax
movl %eax, %ecx
leaq 0x96d8(%rip), %rax      # 0x12ea0
movq (%rax,%rcx,8), %rcx
movq -0x18(%rbp), %rax
orq (%rax), %rcx
movq %rcx, (%rax)
movq -0x50(%rbp), %rax
orq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x77a0
jmp 0x9779
movq -0x70(%rbp), %rdi
callq 0x7690
movq -0x70(%rbp), %rdi
movq %rax, -0x88(%rbp)
movl -0x20(%rbp), %esi
callq 0x7600
movq -0x70(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq %rax, %rdx
movl -0xc(%rbp), %ecx
callq 0x9aa0
andq -0x38(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x989b
movq -0x40(%rbp), %rdi
callq 0x7780
movl %eax, -0x5c(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %ecx
leaq 0xad5a(%rip), %rax      # 0x145a0
shlq $0x9, %rcx
addq %rcx, %rax
movl -0x5c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
andq -0x58(%rbp), %rax
orq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
je 0x9884
movl -0x5c(%rbp), %eax
movl %eax, %ecx
leaq 0x962a(%rip), %rax      # 0x12ea0
movq (%rax,%rcx,8), %rcx
movq -0x18(%rbp), %rax
orq (%rax), %rcx
movq %rcx, (%rax)
movq -0x50(%rbp), %rax
orq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x77a0
jmp 0x9827
movq -0x48(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax,%rax)