// File: jswaff[P]prophet3/src/magic.cpp
// Function: init_bishop_magic_moves()
void init_bishop_magic_moves() {
    for (uint32 sq=0;sq<64;sq++) {
        uint64 mask = bb_bishop_masks[sq];
        uint32 num_mask_bits = get_num_bits(mask);
        uint32 num_variations = 1 << num_mask_bits;

        for (uint32 i=0;i<num_variations;i++) {
            int magic_ind = (int)((bb_bishop_occ_var[sq][i] * magic_numbers_bishops[sq]) >> magic_numbers_shift_bishops[sq]);
            bb_magic_bishop_moves[sq][magic_ind] =
                    gen_moves_mask((square_t)sq,bb_bishop_occ_var[sq][i],&northeast)
                    | gen_moves_mask((square_t)sq,bb_bishop_occ_var[sq][i],&southeast)
                    | gen_moves_mask((square_t)sq,bb_bishop_occ_var[sq][i],&southwest)
                    | gen_moves_mask((square_t)sq,bb_bishop_occ_var[sq][i],&northwest);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
cmpl $0x40, -0x4(%rbp)
jae 0xa18d
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x6fd5ab(%rip), %rax    # 0x7075c0
movq (%rax,%rcx,8), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x47b0
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jae 0xa17d
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x77d76b(%rip), %rax    # 0x7877c0
shlq $0xd, %rcx
addq %rcx, %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl -0x4(%rbp), %ecx
movl %ecx, %edx
leaq 0x87d751(%rip), %rcx    # 0x8877c0
imulq (%rcx,%rdx,8), %rax
movl -0x4(%rbp), %ecx
movl %ecx, %edx
leaq 0x87d940(%rip), %rcx    # 0x8879c0
movl (%rcx,%rdx,4), %ecx
shrq %cl, %rax
movl %eax, -0x20(%rbp)
movl -0x4(%rbp), %edi
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x77d728(%rip), %rax    # 0x7877c0
shlq $0xd, %rcx
addq %rcx, %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
leaq 0x8563(%rip), %rdx      # 0x12610
callq 0x92d0
movq %rax, -0x38(%rbp)
movl -0x4(%rbp), %edi
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x77d6fb(%rip), %rax    # 0x7877c0
shlq $0xd, %rcx
addq %rcx, %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
leaq 0x85c6(%rip), %rdx      # 0x126a0
callq 0x92d0
movq %rax, %rcx
movq -0x38(%rbp), %rax
orq %rcx, %rax
movq %rax, -0x30(%rbp)
movl -0x4(%rbp), %edi
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x77d6c4(%rip), %rax    # 0x7877c0
shlq $0xd, %rcx
addq %rcx, %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
leaq 0x861f(%rip), %rdx      # 0x12730
callq 0x92d0
movq %rax, %rcx
movq -0x30(%rbp), %rax
orq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x4(%rbp), %edi
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x77d68d(%rip), %rax    # 0x7877c0
shlq $0xd, %rcx
addq %rcx, %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
leaq 0x8678(%rip), %rdx      # 0x127c0
callq 0x92d0
movq -0x28(%rbp), %rdx
orq %rax, %rdx
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x6fd660(%rip), %rax    # 0x7077c0
shlq $0xd, %rcx
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xa03d
jmp 0xa17f
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x9fff
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)