// File: jswaff[P]prophet3/src/attack.cpp
// Function: get_attackers(position*, square_t, color_t)
uint64 get_attackers(position *p,square_t sq,color_t player) {
    uint64 attackers = 0;

    attackers = bb_knight_moves[sq] & (player==WHITE ? p->white_knights : p->black_knights);
    attackers |= bb_king_moves[sq] & (player==WHITE ? bb_squares[p->white_king] : bb_squares[p->black_king]);

    if (player==WHITE) {
        attackers |= ((bb_squares[sq] & ~bb_files[FILE_A]) << 7) & p->white_pawns;
        attackers |= ((bb_squares[sq] & ~bb_files[FILE_H]) << 9) & p->white_pawns;
    } else {
        attackers |= ((bb_squares[sq] & ~bb_files[FILE_A]) >> 9) & p->black_pawns;
        attackers |= ((bb_squares[sq] & ~bb_files[FILE_H]) >> 7) & p->black_pawns;
    }

    attackers |= get_bishop_moves(p,sq,player==WHITE ? p->white_bishops : p->black_bishops);
    attackers |= get_rook_moves(p,sq,player==WHITE ? p->white_rooks : p->black_rooks);
    attackers |= get_queen_moves(p,sq,player==WHITE ? p->white_queens : p->black_queens);

    return attackers;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %ecx
leaq 0x101347(%rip), %rax    # 0x105870
movq (%rax,%rcx,8), %rax
movq %rax, -0x20(%rbp)
cmpl $0x1, -0x10(%rbp)
jne 0x4548
movq -0x8(%rbp), %rax
movq 0x168(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x4557
movq -0x8(%rbp), %rax
movq 0x170(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq -0x28(%rbp), %rcx
andq %rcx, %rax
movq %rax, -0x18(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %ecx
leaq 0x1014fe(%rip), %rax    # 0x105a70
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
cmpl $0x1, -0x10(%rbp)
jne 0x459d
movq -0x8(%rbp), %rax
movl 0x14c(%rax), %eax
movl %eax, %ecx
leaq 0x1010dd(%rip), %rax    # 0x105670
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
jmp 0x45b8
movq -0x8(%rbp), %rax
movl 0x150(%rax), %eax
movl %eax, %ecx
leaq 0x1010c0(%rip), %rax    # 0x105670
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
andq %rcx, %rax
orq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
cmpl $0x1, -0x10(%rbp)
jne 0x4644
movl -0xc(%rbp), %eax
movl %eax, %ecx
leaq 0x101093(%rip), %rax    # 0x105670
movq (%rax,%rcx,8), %rax
leaq 0x101008(%rip), %rcx    # 0x1055f0
movq (%rcx), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
shlq $0x7, %rax
movq -0x8(%rbp), %rcx
andq 0x158(%rcx), %rax
orq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %ecx
leaq 0x10105b(%rip), %rax    # 0x105670
movq (%rax,%rcx,8), %rax
leaq 0x100fd0(%rip), %rcx    # 0x1055f0
movq 0x38(%rcx), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
shlq $0x9, %rax
movq -0x8(%rbp), %rcx
andq 0x158(%rcx), %rax
orq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
jmp 0x46b5
movl -0xc(%rbp), %eax
movl %eax, %ecx
leaq 0x101020(%rip), %rax    # 0x105670
movq (%rax,%rcx,8), %rax
leaq 0x100f95(%rip), %rcx    # 0x1055f0
movq (%rcx), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
shrq $0x9, %rax
movq -0x8(%rbp), %rcx
andq 0x160(%rcx), %rax
orq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movl -0xc(%rbp), %eax
movl %eax, %ecx
leaq 0x100fe8(%rip), %rax    # 0x105670
movq (%rax,%rcx,8), %rax
leaq 0x100f5d(%rip), %rcx    # 0x1055f0
movq 0x38(%rcx), %rcx
xorq $-0x1, %rcx
andq %rcx, %rax
shrq $0x7, %rax
movq -0x8(%rbp), %rcx
andq 0x160(%rcx), %rax
orq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x3c(%rbp)
cmpl $0x1, -0x10(%rbp)
jne 0x46da
movq -0x8(%rbp), %rax
movq 0x178(%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x46e9
movq -0x8(%rbp), %rax
movq 0x180(%rax), %rax
movq %rax, -0x50(%rbp)
movl -0x3c(%rbp), %esi
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rdx
callq 0x8fc0
orq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x60(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x54(%rbp)
cmpl $0x1, -0x10(%rbp)
jne 0x4726
movq -0x8(%rbp), %rax
movq 0x188(%rax), %rax
movq %rax, -0x68(%rbp)
jmp 0x4735
movq -0x8(%rbp), %rax
movq 0x190(%rax), %rax
movq %rax, -0x68(%rbp)
movl -0x54(%rbp), %esi
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rdx
callq 0x9170
orq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x78(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x1, -0x10(%rbp)
jne 0x4772
movq -0x8(%rbp), %rax
movq 0x198(%rax), %rax
movq %rax, -0x80(%rbp)
jmp 0x4781
movq -0x8(%rbp), %rax
movq 0x1a0(%rax), %rax
movq %rax, -0x80(%rbp)
movl -0x6c(%rbp), %esi
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rdx
callq 0x9120
orq -0x18(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)