// File: /workspace/github_cpp_makefile_star2_O3/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 0x775b6a(%rip), %r12    # 0x77c600
leaq 0xf3a13(%rip), %r13     # 0xfa4b0
xorl %ebx, %ebx
leaq 0x6f595a(%rip), %rax    # 0x6fc400
movq (%rax,%rbx,8), %r14
movq %r14, %rdi
callq 0x3b14
movl %eax, 0xc(%rsp)
cmpl $0xa, %eax
ja 0x6c49
movq %rbx, (%rsp)
shlq $0xd, %rbx
leaq 0x7f5b32(%rip), %rax    # 0x7fc600
addq %rbx, %rax
movq %rax, 0x10(%rsp)
leaq 0x775b23(%rip), %rax    # 0x77c600
addq %rax, %rbx
movq %rbx, 0x20(%rsp)
xorl %ebx, %ebx
movq %r12, 0x18(%rsp)
xorl %eax, %eax
movq 0x10(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
movq 0x20(%rsp), %rcx
leaq (%rcx,%rbx,8), %rbp
movq %rax, (%rbp)
testq %rbx, %rbx
je 0x6b5f
movl %ebx, %ecx
movslq %ecx, %r15
movq %r15, %rdi
callq 0x3b67
movl %eax, %r12d
movq %r14, %rdi
movl %eax, %esi
callq 0x3caa
orq (%rbp), %rax
movl $0x1, %edx
movl %r12d, %ecx
shll %cl, %edx
movq %rax, (%rbp)
movl %r15d, %ecx
btcl %r12d, %ecx
cmpl %r15d, %edx
jne 0x6b0b
testq %rbx, %rbx
movq 0x18(%rsp), %r12
je 0x6b5f
xorl %ecx, %ecx
cmpq (%r12,%rcx,8), %rax
je 0x6c2a
incq %rcx
cmpq %rcx, %rbx
jne 0x6b4d
movq 0x10(%rsp), %rax
leaq (%rax,%rbx,8), %r15
movq (%rsp), %rdi
callq 0xccf0
cmpl $0x40, %eax
je 0x6b8a
movl %eax, %ecx
movq (%r13,%rcx,8), %rcx
testq %rcx, (%rbp)
jne 0x6b87
movl %eax, %edi
jmp 0x6b6c
orq %rcx, (%r15)
movq (%rsp), %rdi
callq 0xcd33
cmpl $0x40, %eax
je 0x6bac
movl %eax, %ecx
movq (%r13,%rcx,8), %rcx
testq %rcx, (%rbp)
jne 0x6ba9
movl %eax, %edi
jmp 0x6b8e
orq %rcx, (%r15)
movq (%rsp), %rdi
callq 0xcd7a
cmpl $0x40, %eax
je 0x6bce
movl %eax, %ecx
movq (%r13,%rcx,8), %rcx
testq %rcx, (%rbp)
jne 0x6bcb
movl %eax, %edi
jmp 0x6bb0
orq %rcx, (%r15)
movq (%rsp), %rdi
callq 0xcdba
cmpl $0x40, %eax
je 0x6bf0
movl %eax, %ecx
movq (%r13,%rcx,8), %rcx
testq %rcx, (%rbp)
jne 0x6bed
movl %eax, %edi
jmp 0x6bd2
orq %rcx, (%r15)
incq %rbx
movl %ebx, %eax
movl 0xc(%rsp), %ecx
shrl %cl, %eax
testl %eax, %eax
je 0x6aec
movq (%rsp), %rbx
incq %rbx
addq $0x2000, %r12           # imm = 0x2000
cmpq $0x40, %rbx
jne 0x6a9f
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x23b4a(%rip), %rdi     # 0x2a77b
leaq 0x239fb(%rip), %rsi     # 0x2a633
leaq 0x23b14(%rip), %rcx     # 0x2a753
movl $0x85, %edx
callq 0x20d0
leaq 0x23aec(%rip), %rdi     # 0x2a73c
leaq 0x239dc(%rip), %rsi     # 0x2a633
leaq 0x23af5(%rip), %rcx     # 0x2a753
movl $0x76, %edx
callq 0x20d0