// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rdx, 0x10(%rsp)
movl %esi, 0x4(%rsp)
movq %rdi, %r15
xorl %eax, %eax
xorl %edx, %edx
testl %ecx, %ecx
setne %al
sete %dl
movq 0x150(%rdi), %rcx
orq 0x120(%rdi), %rcx
movq 0x110(%rdi), %rbp
movq 0x118(%rdi), %rbx
orq 0x148(%rdi), %rbx
orq %rcx, %rbx
movq 0x160(%rdi,%rdx,8), %rdx
movq %rdx, 0x18(%rsp)
orq 0x140(%rdi), %rbp
orq %rcx, %rbp
leaq 0x160(,%rax,8), %rcx
movq %rcx, 0x8(%rsp)
movq 0x160(%rdi,%rax,8), %r12
movq 0x170(%rdi), %r14
movl %esi, %edi
movq %r14, %rsi
movl $0x3, %edx
callq 0x34b9
movq %rax, %r13
movq %rax, %rsi
andq %r12, %rsi
xorq %r14, %rsi
movl 0x4(%rsp), %r14d
movl %r14d, %edi
movl $0x3, %edx
callq 0x34b9
xorq %r13, %rax
andq %rbx, %rax
movl %r14d, %r10d
movl %r14d, %r13d
andq 0x18(%rsp), %rax
je 0x56e2
movq 0x10(%rsp), %r9
movq (%r9), %rcx
xorl %r14d, %r14d
movq %r13, %rdx
shlq $0x9, %rdx
addq 0x58e2(%rip), %rdx      # 0xaf90
leaq 0x672b(%rip), %rsi      # 0xbde0
xorl %ebx, %ebx
movq %rbx, %r8
bsfq %rax, %rdi
movq (%rdx,%rdi,8), %rbx
andq %r12, %rbx
orq %r8, %rbx
cmpq %r14, %rbx
je 0x56d4
orq (%rsi,%rdi,8), %rcx
movq %rcx, (%r9)
orq %rbx, %r14
leaq -0x1(%rax), %rdi
andq %rdi, %rax
jne 0x56b7
jmp 0x56e7
xorl %ebx, %ebx
xorl %r14d, %r14d
movq 0x170(%r15), %rsi
movq %rsi, 0x20(%rsp)
movq 0x8(%rsp), %rax
movq (%r15,%rax), %r15
movl %r10d, %edi
movl $0x2, %edx
callq 0x34b9
movq %rax, 0x8(%rsp)
andq %rax, %r15
xorq 0x20(%rsp), %r15
movl 0x4(%rsp), %edi
movq %r15, %rsi
movl $0x2, %edx
callq 0x34b9
xorq 0x8(%rsp), %rax
andq %rax, %rbp
andq 0x18(%rsp), %rbp
je 0x577a
movq 0x10(%rsp), %rdi
movq (%rdi), %rax
shlq $0x9, %r13
addq 0x5847(%rip), %r13      # 0xaf90
leaq 0x6690(%rip), %rcx      # 0xbde0
movq %rbx, %rsi
bsfq %rbp, %rdx
movq (%r13,%rdx,8), %rbx
andq %r12, %rbx
orq %rsi, %rbx
cmpq %r14, %rbx
je 0x576e
orq (%rcx,%rdx,8), %rax
movq %rax, (%rdi)
orq %rbx, %r14
leaq -0x1(%rbp), %rdx
andq %rdx, %rbp
jne 0x5750
movq %r14, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq