// File: /workspace/github_cpp_makefile_star2_O1/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 0x2f5534(%rip), %rbp    # 0x2fc100
leaq 0xf38dd(%rip), %r12     # 0xfa4b0
xorl %ebx, %ebx
leaq 0xf5324(%rip), %rax     # 0xfbf00
movq (%rax,%rbx,8), %r14
movq %r14, %rdi
callq 0x3b08
movl %eax, 0x14(%rsp)
cmpl $0xc, %eax
ja 0x6d7a
movq %rbx, 0x8(%rsp)
shlq $0xf, %rbx
leaq 0x4f54fb(%rip), %rax    # 0x4fc100
addq %rbx, %rax
movq %rax, 0x18(%rsp)
leaq 0x2f54ec(%rip), %rax    # 0x2fc100
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 0x6c8f
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 0x6c3d
movq (%r13), %rax
xorl %ecx, %ecx
leaq 0xf3834(%rip), %r12     # 0xfa4b0
cmpq (%rbp,%rcx,8), %rax
je 0x6d5b
incq %rcx
cmpq %rcx, %rbx
jne 0x6c7c
movq 0x18(%rsp), %rax
leaq (%rax,%rbx,8), %r15
movq 0x8(%rsp), %rdi
callq 0xcc11
cmpl $0x40, %eax
je 0x6cba
movl %eax, %ecx
movq (%r12,%rcx,8), %rcx
testq %rcx, (%r13)
jne 0x6cb7
movl %eax, %edi
jmp 0x6c9d
orq %rcx, (%r15)
movq 0x8(%rsp), %rdi
callq 0xcc4a
cmpl $0x40, %eax
je 0x6cdc
movl %eax, %ecx
movq (%r12,%rcx,8), %rcx
testq %rcx, (%r13)
jne 0x6cd9
movl %eax, %edi
jmp 0x6cbf
orq %rcx, (%r15)
movq 0x8(%rsp), %rdi
callq 0xcc89
cmpl $0x40, %eax
je 0x6cfe
movl %eax, %ecx
movq (%r12,%rcx,8), %rcx
testq %rcx, (%r13)
jne 0x6cfb
movl %eax, %edi
jmp 0x6ce1
orq %rcx, (%r15)
movq 0x8(%rsp), %rdi
callq 0xccc6
cmpl $0x40, %eax
je 0x6d20
movl %eax, %ecx
movq (%r12,%rcx,8), %rcx
testq %rcx, (%r13)
jne 0x6d1d
movl %eax, %edi
jmp 0x6d03
orq %rcx, (%r15)
incq %rbx
movl %ebx, %eax
movl 0x14(%rsp), %ecx
shrl %cl, %eax
testl %eax, %eax
je 0x6c1e
movq 0x8(%rsp), %rbx
incq %rbx
addq $0x8000, %rbp           # imm = 0x8000
cmpq $0x40, %rbx
jne 0x6bd5
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x23a0b(%rip), %rdi     # 0x2a76d
leaq 0x2384a(%rip), %rsi     # 0x2a5b3
leaq 0x239d7(%rip), %rcx     # 0x2a747
movl $0xc1, %edx
callq 0x20d0
leaq 0x239af(%rip), %rdi     # 0x2a730
leaq 0x2382b(%rip), %rsi     # 0x2a5b3
leaq 0x239b8(%rip), %rcx     # 0x2a747
movl $0xb2, %edx
callq 0x20d0