// File: /workspace/github_cpp_makefile_star2_O2/jswaff[P]prophet3/src/magic.cpp
// Function: init_bishop_occupancy_variations()
void init_bishop_occupancy_variations() {
    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; //pow(2,num_mask_bits);
        assert(num_variations <= 1024);

        for (uint32 i=0;i<num_variations;i++) {
            bb_bishop_occ_var[sq][i] = bb_bishop_attack_set[sq][i] = 0;

            // map the index to an occupancy variation
            int32 index = i;
            while (index) {
                uint32 index_bit = get_lsb(index);
                bb_bishop_occ_var[sq][i] |= isolate_lsb_bit(mask,index_bit);
                index ^= 1 << index_bit;
            }

            // sanity check
            for (uint32 j=0;j<i;j++) {
                assert(bb_bishop_occ_var[sq][i] != bb_bishop_occ_var[sq][j]);
            }

            // create the attack set.  that's the first "blocker" in every direction
            square_t to = northeast((square_t)sq);
            while (to != NO_SQUARE) {
                if (bb_bishop_occ_var[sq][i] & bb_squares[to]) {
                    bb_bishop_attack_set[sq][i] |= bb_squares[to];
                    break;
                }
                to = northeast(to);
            }
            to = southeast((square_t)sq);
            while (to != NO_SQUARE) {
                if (bb_bishop_occ_var[sq][i] & bb_squares[to]) {
                    bb_bishop_attack_set[sq][i] |= bb_squares[to];
                    break;
                }
                to = southeast(to);
            }
            to = southwest((square_t)sq);
            while (to != NO_SQUARE) {
                if (bb_bishop_occ_var[sq][i] & bb_squares[to]) {
                    bb_bishop_attack_set[sq][i] |= bb_squares[to];
                    break;
                }
                to = southwest(to);
            }
            to = northwest((square_t)sq);
            while (to != NO_SQUARE) {
                if (bb_bishop_occ_var[sq][i] & bb_squares[to]) {
                    bb_bishop_attack_set[sq][i] |= bb_squares[to];
                    break;
                }
                to = northwest(to);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0x778fc9(%rip), %r15    # 0x77f600
xorl %r14d, %r14d
cmpq $0x40, %r14
je 0x67b4
leaq 0x6f8db5(%rip), %rax    # 0x6ff400
movq (%rax,%r14,8), %rbx
movq %rbx, %rdi
callq 0x3928
movl %eax, 0xc(%rsp)
cmpl $0xa, %eax
ja 0x67e2
movq %r14, %rcx
shlq $0xd, %rcx
leaq 0x7f8f8e(%rip), %rax    # 0x7ff600
addq %rcx, %rax
movq %rax, 0x10(%rsp)
leaq 0x778f7f(%rip), %rax    # 0x77f600
addq %rax, %rcx
movq %rcx, 0x18(%rsp)
xorl %ebp, %ebp
movq %r14, 0x20(%rsp)
movl %ebp, %eax
movl 0xc(%rsp), %ecx
shrl %cl, %eax
testl %eax, %eax
jne 0x67a5
movq 0x10(%rsp), %rax
leaq (%rax,%rbp,8), %rax
movq %rax, (%rsp)
andq $0x0, (%rax)
movq 0x18(%rsp), %rax
leaq (%rax,%rbp,8), %r12
andq $0x0, (%r12)
xorl %eax, %eax
movl %ebp, %r13d
testl %r13d, %r13d
je 0x66ec
movslq %r13d, %rdi
callq 0x397d
movl %eax, %r14d
movq %rbx, %rdi
movl %eax, %esi
callq 0x3abb
orq (%r12), %rax
movq %rax, (%r12)
btcl %r14d, %r13d
jmp 0x66c4
xorl %ecx, %ecx
movq 0x20(%rsp), %r14
leaq 0xf6db6(%rip), %r13     # 0xfd4b0
cmpq %rcx, %rbp
je 0x6711
leaq 0x1(%rcx), %rdx
cmpq (%r15,%rcx,8), %rax
movq %rdx, %rcx
jne 0x66fa
jmp 0x67c3
movl %r14d, %eax
movl %eax, %edi
callq 0xc2a9
cmpl $0x40, %eax
je 0x6734
movl %eax, %ecx
movq (%r13,%rcx,8), %rcx
testq %rcx, (%r12)
je 0x6714
movq (%rsp), %rax
orq %rcx, (%rax)
movl %r14d, %eax
movl %eax, %edi
callq 0xc2ff
cmpl $0x40, %eax
je 0x6757
movl %eax, %ecx
movq (%r13,%rcx,8), %rcx
testq %rcx, (%r12)
je 0x6737
movq (%rsp), %rax
orq %rcx, (%rax)
movl %r14d, %eax
movl %eax, %edi
callq 0xc356
cmpl $0x40, %eax
je 0x677a
movl %eax, %ecx
movq (%r13,%rcx,8), %rcx
testq %rcx, (%r12)
je 0x675a
movq (%rsp), %rax
orq %rcx, (%rax)
movl %r14d, %eax
movl %eax, %edi
callq 0xc3ac
cmpl $0x40, %eax
je 0x679d
movl %eax, %ecx
movq (%r13,%rcx,8), %rcx
testq %rcx, (%r12)
je 0x677d
movq (%rsp), %rax
orq %rcx, (%rax)
incq %rbp
jmp 0x6690
incq %r14
addq $0x2000, %r15           # imm = 0x2000
jmp 0x663a
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x21f61(%rip), %rdi     # 0x2872b
leaq 0x21e12(%rip), %rsi     # 0x285e3
leaq 0x21f2b(%rip), %rcx     # 0x28703
movl $0x85, %edx
callq 0x20c0
leaq 0x21f03(%rip), %rdi     # 0x286ec
leaq 0x21df3(%rip), %rsi     # 0x285e3
leaq 0x21f0c(%rip), %rcx     # 0x28703
pushq $0x76
popq %rdx
callq 0x20c0