// File: niekh1234[P]nnchesslib/attacks.cpp
// Function: nnchesslib::Attacks::getBishopAttacksRays(int, unsigned long long)
U64 Attacks::getBishopAttacksRays(int sq, U64 blockers)
{
    U64 combinedAttacks = (U64)0;

    // north west attacks
    U64 bishopAttacksNorthWest = Rays::getRay(NORTH_WEST, sq);
    U64 northWestBlocker = bishopAttacksNorthWest & blockers;
    if(blockers)
    {
        int index = bitScanForward(northWestBlocker);
        bishopAttacksNorthWest ^= Rays::getRay(NORTH_WEST, index);
    }
    combinedAttacks |= bishopAttacksNorthWest;

    // north east attacks
    // this is different because above method did not work properly.
    combinedAttacks |= Rays::getRay(NORTH_EAST, sq);
    if (Rays::getRay(NORTH_EAST, sq) & blockers) {
        combinedAttacks &= ~(Rays::getRay(NORTH_EAST, bitScanForward(Rays::getRay(NORTH_EAST, sq) & blockers)));
    }

    // south east attacks
    U64 bishopAttacksSouthEast = Rays::getRay(SOUTH_EAST, sq);
    U64 southEastBlocker = bishopAttacksSouthEast & blockers;
    if(blockers)
    {
        int index = bitScanReverse(southEastBlocker);
        bishopAttacksSouthEast ^= Rays::getRay(SOUTH_EAST, index);
    }
    combinedAttacks |= bishopAttacksSouthEast;

    // south west attacks
    U64 bishopAttacksSouthWest = Rays::getRay(SOUTH_WEST, sq);
    U64 southWestBlocker = bishopAttacksSouthWest & blockers;
    if(blockers)
    {
        int index = bitScanReverse(southWestBlocker);
        bishopAttacksSouthWest ^= Rays::getRay(SOUTH_WEST, index);
    }
    combinedAttacks |= bishopAttacksSouthWest;

    return combinedAttacks;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl -0x4(%rbp), %esi
movl $0x5, %edi
callq 0xd630
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
andq -0x10(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x449c
movq -0x28(%rbp), %rdi
callq 0xd7d0
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %esi
movl $0x5, %edi
callq 0xd630
xorq -0x20(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
orq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movl -0x4(%rbp), %esi
movl $0x4, %edi
callq 0xd630
orq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movl -0x4(%rbp), %esi
movl $0x4, %edi
callq 0xd630
andq -0x10(%rbp), %rax
cmpq $0x0, %rax
je 0x4505
movl -0x4(%rbp), %esi
movl $0x4, %edi
callq 0xd630
movq %rax, %rdi
andq -0x10(%rbp), %rdi
callq 0xd7d0
movl %eax, %esi
movl $0x4, %edi
callq 0xd630
xorq $-0x1, %rax
andq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movl -0x4(%rbp), %esi
movl $0x6, %edi
callq 0xd630
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
andq -0x10(%rbp), %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x454a
movq -0x40(%rbp), %rdi
callq 0xd800
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %esi
movl $0x6, %edi
callq 0xd630
xorq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
orq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movl -0x4(%rbp), %esi
movl $0x7, %edi
callq 0xd630
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
andq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x459b
movq -0x58(%rbp), %rdi
callq 0xd800
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %esi
movl $0x7, %edi
callq 0xd630
xorq -0x50(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
orq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)