// File: /workspace/github_cpp_makefile_star2_O2/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 0x2f88ec(%rip), %r15    # 0x2ff100
xorl %r14d, %r14d
cmpq $0x40, %r14
je 0x6991
leaq 0xf86d8(%rip), %rax     # 0xfef00
movq (%rax,%r14,8), %rbx
movq %rbx, %rdi
callq 0x3928
movl %eax, 0xc(%rsp)
cmpl $0xc, %eax
ja 0x69bf
movq %r14, %rcx
shlq $0xf, %rcx
leaq 0x4f88b1(%rip), %rax    # 0x4ff100
addq %rcx, %rax
movq %rax, 0x10(%rsp)
leaq 0x2f88a2(%rip), %rax    # 0x2ff100
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 0x6982
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 0x68c9
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 0x68a1
xorl %ecx, %ecx
movq 0x20(%rsp), %r14
leaq 0xf6bd9(%rip), %r13     # 0xfd4b0
cmpq %rcx, %rbp
je 0x68ee
leaq 0x1(%rcx), %rdx
cmpq (%r15,%rcx,8), %rax
movq %rdx, %rcx
jne 0x68d7
jmp 0x69a0
movl %r14d, %eax
movl %eax, %edi
callq 0xc19d
cmpl $0x40, %eax
je 0x6911
movl %eax, %ecx
movq (%r13,%rcx,8), %rcx
testq %rcx, (%r12)
je 0x68f1
movq (%rsp), %rax
orq %rcx, (%rax)
movl %r14d, %eax
movl %eax, %edi
callq 0xc1e0
cmpl $0x40, %eax
je 0x6934
movl %eax, %ecx
movq (%r13,%rcx,8), %rcx
testq %rcx, (%r12)
je 0x6914
movq (%rsp), %rax
orq %rcx, (%rax)
movl %r14d, %eax
movl %eax, %edi
callq 0xc224
cmpl $0x40, %eax
je 0x6957
movl %eax, %ecx
movq (%r13,%rcx,8), %rcx
testq %rcx, (%r12)
je 0x6937
movq (%rsp), %rax
orq %rcx, (%rax)
movl %r14d, %eax
movl %eax, %edi
callq 0xc267
cmpl $0x40, %eax
je 0x697a
movl %eax, %ecx
movq (%r13,%rcx,8), %rcx
testq %rcx, (%r12)
je 0x695a
movq (%rsp), %rax
orq %rcx, (%rax)
incq %rbp
jmp 0x686d
incq %r14
addq $0x8000, %r15           # imm = 0x8000
jmp 0x6817
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x21df6(%rip), %rdi     # 0x2879d
leaq 0x21c35(%rip), %rsi     # 0x285e3
leaq 0x21dc2(%rip), %rcx     # 0x28777
movl $0xc1, %edx
callq 0x20c0
leaq 0x21d9a(%rip), %rdi     # 0x28760
leaq 0x21c16(%rip), %rsi     # 0x285e3
leaq 0x21da3(%rip), %rcx     # 0x28777
movl $0xb2, %edx
callq 0x20c0