// File: /workspace/github_cpp_makefile_star2_O1/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 0x775c16(%rip), %rbp    # 0x77c600
leaq 0xf3abf(%rip), %r12     # 0xfa4b0
xorl %ebx, %ebx
leaq 0x6f5a06(%rip), %rax    # 0x6fc400
movq (%rax,%rbx,8), %r14
movq %r14, %rdi
callq 0x3b08
movl %eax, 0x14(%rsp)
cmpl $0xa, %eax
ja 0x6b98
movq %rbx, 0x8(%rsp)
shlq $0xd, %rbx
leaq 0x7f5bdd(%rip), %rax    # 0x7fc600
addq %rbx, %rax
movq %rax, 0x18(%rsp)
leaq 0x775bce(%rip), %rax    # 0x77c600
addq %rax, %rbx
movq %rbx, 0x20(%rsp)
xorl %ebx, %ebx
xorl %eax, %eax
movq 0x18(%rsp), %rcx
movq %rax, (%rcx,%rbx,8)
movq 0x20(%rsp), %rcx
leaq (%rcx,%rbx,8), %r13
movq %rax, (%r13)
testq %rbx, %rbx
je 0x6aad
movl %ebx, %eax
movslq %eax, %r15
movq %r15, %rdi
callq 0x3b5b
movl %eax, %r12d
movq %r14, %rdi
movl %eax, %esi
callq 0x3c9e
orq %rax, (%r13)
movl $0x1, %edx
movl %r12d, %ecx
shll %cl, %edx
movl %r15d, %eax
btcl %r12d, %eax
cmpl %r15d, %edx
jne 0x6a5b
movq (%r13), %rax
xorl %ecx, %ecx
leaq 0xf3a16(%rip), %r12     # 0xfa4b0
cmpq (%rbp,%rcx,8), %rax
je 0x6b79
incq %rcx
cmpq %rcx, %rbx
jne 0x6a9a
movq 0x18(%rsp), %rax
leaq (%rax,%rbx,8), %r15
movq 0x8(%rsp), %rdi
callq 0xccfc
cmpl $0x40, %eax
je 0x6ad8
movl %eax, %ecx
movq (%r12,%rcx,8), %rcx
testq %rcx, (%r13)
jne 0x6ad5
movl %eax, %edi
jmp 0x6abb
orq %rcx, (%r15)
movq 0x8(%rsp), %rdi
callq 0xcd3f
cmpl $0x40, %eax
je 0x6afa
movl %eax, %ecx
movq (%r12,%rcx,8), %rcx
testq %rcx, (%r13)
jne 0x6af7
movl %eax, %edi
jmp 0x6add
orq %rcx, (%r15)
movq 0x8(%rsp), %rdi
callq 0xcd87
cmpl $0x40, %eax
je 0x6b1c
movl %eax, %ecx
movq (%r12,%rcx,8), %rcx
testq %rcx, (%r13)
jne 0x6b19
movl %eax, %edi
jmp 0x6aff
orq %rcx, (%r15)
movq 0x8(%rsp), %rdi
callq 0xcdc7
cmpl $0x40, %eax
je 0x6b3e
movl %eax, %ecx
movq (%r12,%rcx,8), %rcx
testq %rcx, (%r13)
jne 0x6b3b
movl %eax, %edi
jmp 0x6b21
orq %rcx, (%r15)
incq %rbx
movl %ebx, %eax
movl 0x14(%rsp), %ecx
shrl %cl, %eax
testl %eax, %eax
je 0x6a3c
movq 0x8(%rsp), %rbx
incq %rbx
addq $0x2000, %rbp           # imm = 0x2000
cmpq $0x40, %rbx
jne 0x69f3
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x23b7b(%rip), %rdi     # 0x2a6fb
leaq 0x23a2c(%rip), %rsi     # 0x2a5b3
leaq 0x23b45(%rip), %rcx     # 0x2a6d3
movl $0x85, %edx
callq 0x20d0
leaq 0x23b1d(%rip), %rdi     # 0x2a6bc
leaq 0x23a0d(%rip), %rsi     # 0x2a5b3
leaq 0x23b26(%rip), %rcx     # 0x2a6d3
movl $0x76, %edx
callq 0x20d0