// File: /workspace/github_cpp_makefile_star2_O3/jswaff[P]prophet3/src/magic.cpp
// Function: init_rook_occupancy_variations()
void init_rook_occupancy_variations() {
    for (uint32 sq=0;sq<64;sq++) {
        uint64 mask = bb_rook_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 <= 4096);

        for (uint32 i=0;i<num_variations;i++) {
            bb_rook_occ_var[sq][i] = bb_rook_attack_set[sq][i] = 0;

            // map the index to an occupancy variation
            int32 index = i;
            while (index) {
                uint32 index_bit = get_lsb(index);
                bb_rook_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_rook_occ_var[sq][i] != bb_rook_occ_var[sq][j]);
            }

            // create the attack set.  that's the first "blocker" in every direction
            square_t to = north((square_t)sq);
            while (to != NO_SQUARE) {
                if (bb_rook_occ_var[sq][i] & bb_squares[to]) {
                    bb_rook_attack_set[sq][i] |= bb_squares[to];
                    break;
                }
                to = north(to);
            }
            to = south((square_t)sq);
            while (to != NO_SQUARE) {
                if (bb_rook_occ_var[sq][i] & bb_squares[to]) {
                    bb_rook_attack_set[sq][i] |= bb_squares[to];
                    break;
                }
                to = south(to);
            }
            to = east((square_t)sq);
            while (to != NO_SQUARE) {
                if (bb_rook_occ_var[sq][i] & bb_squares[to]) {
                    bb_rook_attack_set[sq][i] |= bb_squares[to];
                    break;
                }
                to = east(to);
            }
            to = west((square_t)sq);
            while (to != NO_SQUARE) {
                if (bb_rook_occ_var[sq][i] & bb_squares[to]) {
                    bb_rook_attack_set[sq][i] |= bb_squares[to];
                    break;
                }
                to = west(to);
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
leaq 0x2f5483(%rip), %r12    # 0x2fc100
leaq 0xf382c(%rip), %r13     # 0xfa4b0
xorl %ebx, %ebx
leaq 0xf5273(%rip), %rax     # 0xfbf00
movq (%rax,%rbx,8), %r14
movq %r14, %rdi
callq 0x3b14
movl %eax, 0xc(%rsp)
cmpl $0xc, %eax
ja 0x6e30
movq %rbx, (%rsp)
shlq $0xf, %rbx
leaq 0x4f544b(%rip), %rax    # 0x4fc100
addq %rbx, %rax
movq %rax, 0x10(%rsp)
leaq 0x2f543c(%rip), %rax    # 0x2fc100
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 0x6d46
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 0x6cf2
testq %rbx, %rbx
movq 0x18(%rsp), %r12
je 0x6d46
xorl %ecx, %ecx
cmpq (%r12,%rcx,8), %rax
je 0x6e11
incq %rcx
cmpq %rcx, %rbx
jne 0x6d34
movq 0x10(%rsp), %rax
leaq (%rax,%rbx,8), %r15
movq (%rsp), %rdi
callq 0xcc05
cmpl $0x40, %eax
je 0x6d71
movl %eax, %ecx
movq (%r13,%rcx,8), %rcx
testq %rcx, (%rbp)
jne 0x6d6e
movl %eax, %edi
jmp 0x6d53
orq %rcx, (%r15)
movq (%rsp), %rdi
callq 0xcc3e
cmpl $0x40, %eax
je 0x6d93
movl %eax, %ecx
movq (%r13,%rcx,8), %rcx
testq %rcx, (%rbp)
jne 0x6d90
movl %eax, %edi
jmp 0x6d75
orq %rcx, (%r15)
movq (%rsp), %rdi
callq 0xcc7d
cmpl $0x40, %eax
je 0x6db5
movl %eax, %ecx
movq (%r13,%rcx,8), %rcx
testq %rcx, (%rbp)
jne 0x6db2
movl %eax, %edi
jmp 0x6d97
orq %rcx, (%r15)
movq (%rsp), %rdi
callq 0xccba
cmpl $0x40, %eax
je 0x6dd7
movl %eax, %ecx
movq (%r13,%rcx,8), %rcx
testq %rcx, (%rbp)
jne 0x6dd4
movl %eax, %edi
jmp 0x6db9
orq %rcx, (%r15)
incq %rbx
movl %ebx, %eax
movl 0xc(%rsp), %ecx
shrl %cl, %eax
testl %eax, %eax
je 0x6cd3
movq (%rsp), %rbx
incq %rbx
addq $0x8000, %r12           # imm = 0x8000
cmpq $0x40, %rbx
jne 0x6c86
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x239d5(%rip), %rdi     # 0x2a7ed
leaq 0x23814(%rip), %rsi     # 0x2a633
leaq 0x239a1(%rip), %rcx     # 0x2a7c7
movl $0xc1, %edx
callq 0x20d0
leaq 0x23979(%rip), %rdi     # 0x2a7b0
leaq 0x237f5(%rip), %rsi     # 0x2a633
leaq 0x23982(%rip), %rcx     # 0x2a7c7
movl $0xb2, %edx
callq 0x20d0