// File: jswaff[P]prophet3/src/magic.cpp
// Function: init_rook_magic_moves()
void init_rook_magic_moves() {
    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;

        for (uint32 i=0;i<num_variations;i++) {
            int magic_ind = (int)((bb_rook_occ_var[sq][i] * magic_numbers_rooks[sq]) >> magic_numbers_shift_rooks[sq]);
            bb_magic_rook_moves[sq][magic_ind] =
                    gen_moves_mask((square_t)sq,bb_rook_occ_var[sq][i],&north)
                    | gen_moves_mask((square_t)sq,bb_rook_occ_var[sq][i],&south)
                    | gen_moves_mask((square_t)sq,bb_rook_occ_var[sq][i],&east)
                    | gen_moves_mask((square_t)sq,bb_rook_occ_var[sq][i],&west);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
cmpl $0x40, -0x4(%rbp)
jae 0xa33d
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0xfcefb(%rip), %rax     # 0x1070c0
movq (%rax,%rcx,8), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x47b0
movl %eax, -0x14(%rbp)
movl -0x14(%rbp), %ecx
movl $0x1, %eax
shll %cl, %eax
movl %eax, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jae 0xa32d
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x2fd0bb(%rip), %rax    # 0x3072c0
shlq $0xf, %rcx
addq %rcx, %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl -0x4(%rbp), %ecx
movl %ecx, %edx
leaq 0x6fd0a1(%rip), %rcx    # 0x7072c0
imulq (%rcx,%rdx,8), %rax
movl -0x4(%rbp), %ecx
movl %ecx, %edx
leaq 0x6fd290(%rip), %rcx    # 0x7074c0
movl (%rcx,%rdx,4), %ecx
shrq %cl, %rax
movl %eax, -0x20(%rbp)
movl -0x4(%rbp), %edi
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x2fd078(%rip), %rax    # 0x3072c0
shlq $0xf, %rcx
addq %rcx, %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
leaq 0x81b3(%rip), %rdx      # 0x12410
callq 0x92d0
movq %rax, -0x38(%rbp)
movl -0x4(%rbp), %edi
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x2fd04b(%rip), %rax    # 0x3072c0
shlq $0xf, %rcx
addq %rcx, %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
leaq 0x8206(%rip), %rdx      # 0x12490
callq 0x92d0
movq %rax, %rcx
movq -0x38(%rbp), %rax
orq %rcx, %rax
movq %rax, -0x30(%rbp)
movl -0x4(%rbp), %edi
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x2fd014(%rip), %rax    # 0x3072c0
shlq $0xf, %rcx
addq %rcx, %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
leaq 0x824f(%rip), %rdx      # 0x12510
callq 0x92d0
movq %rax, %rcx
movq -0x30(%rbp), %rax
orq %rcx, %rax
movq %rax, -0x28(%rbp)
movl -0x4(%rbp), %edi
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0x2fcfdd(%rip), %rax    # 0x3072c0
shlq $0xf, %rcx
addq %rcx, %rax
movl -0x1c(%rbp), %ecx
movq (%rax,%rcx,8), %rsi
leaq 0x8298(%rip), %rdx      # 0x12590
callq 0x92d0
movq -0x28(%rbp), %rdx
orq %rax, %rdx
movl -0x4(%rbp), %eax
movl %eax, %ecx
leaq 0xfcfb0(%rip), %rax     # 0x1072c0
shlq $0xf, %rcx
addq %rcx, %rax
movslq -0x20(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xa1ed
jmp 0xa32f
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0xa1af
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)