// File: /workspace/github_cpp_makefile_star2_O1/jswaff[P]prophet3/src/bitboards.cpp
// Function: init_rays()
void init_rays() {
    for (int i=0;i<64;i++) {
        file_t file_i = get_file((square_t)i);
        rank_t rank_i = get_rank((square_t)i);

        for (int j=0;j<8;j++) {
            bb_rays[i][j] = 0;
        }

        for (int j=0;j<64;j++) {
            file_t file_j = get_file((square_t)j);
            rank_t rank_j = get_rank((square_t)j);

            // figure out if j is north or south of i
            if (file_i==file_j) {
                if (j<i) {
                    bb_rays[i][NORTH] |= bb_squares[j];
                } else if (j>i) {
                    bb_rays[i][SOUTH] |= bb_squares[j];
                }
            }
            // figure out if j is east or west of i
            if (rank_i==rank_j) {
                if (j<i) {
                    bb_rays[i][WEST] |= bb_squares[j];
                } else if (j>i) {
                    bb_rays[i][EAST] |= bb_squares[j];
                }
            }

            if (is_diagonal((square_t)i,(square_t)j)) {
                if (rank_j < rank_i) {
                    if (file_j < file_i) {
                        bb_rays[i][NORTHWEST] |= bb_squares[j];
                    } else if (file_j > file_i) {
                        bb_rays[i][NORTHEAST] |= bb_squares[j];
                    }
                } else if (rank_j > rank_i) {
                    if (file_j < file_i) {
                        bb_rays[i][SOUTHWEST] |= bb_squares[j];
                    } else if (file_j > file_i) {
                        bb_rays[i][SOUTHEAST] |= bb_squares[j];
                    }
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
xorl %ebx, %ebx
movq %rbx, %r15
shlq $0x6, %r15
leaq 0xf6f8f(%rip), %r12     # 0xfaeb0
leaq (%r12,%r15), %rax
movq %rax, 0x40(%rsp)
movl %ebx, %edi
callq 0xca4a
movl %eax, %ebp
movl %ebx, %edi
callq 0xca75
movl %eax, %r14d
leaq (%r12,%r15), %rax
addq $0x20, %rax
xorps %xmm0, %xmm0
movaps %xmm0, -0x20(%rax)
movaps %xmm0, -0x10(%rax)
movaps %xmm0, (%rax)
movq %rax, 0x30(%rsp)
movaps %xmm0, 0x10(%rax)
leaq 0x10(%r12,%r15), %rax
movq %rax, 0x28(%rsp)
leaq 0x30(%r12,%r15), %rax
movq %rax, 0x38(%rsp)
leaq 0x18(%r12,%r15), %rax
movq %rax, 0x8(%rsp)
leaq 0x28(%r12,%r15), %rax
movq %rax, 0x18(%rsp)
leaq 0x8(%r12,%r15), %rax
movq %rax, 0x10(%rsp)
leaq (%r12,%r15), %rax
addq $0x38, %rax
movq %rax, 0x20(%rsp)
xorl %r15d, %r15d
movl %r15d, %edi
callq 0xca4a
movl %eax, %r12d
movl %r15d, %edi
callq 0xca75
movl %eax, %r13d
cmpl %r12d, %ebp
jne 0x3fd8
movq 0x40(%rsp), %rax
cmpq %rbx, %r15
jb 0x3fca
movq 0x30(%rsp), %rax
jbe 0x3fd8
leaq 0xf64df(%rip), %rcx     # 0xfa4b0
movq (%rcx,%r15,8), %rcx
orq %rcx, (%rax)
cmpl %r13d, %r14d
jne 0x3ffc
movq 0x38(%rsp), %rax
cmpq %rbx, %r15
jb 0x3fee
movq 0x28(%rsp), %rax
jbe 0x3ffc
leaq 0xf64bb(%rip), %rcx     # 0xfa4b0
movq (%rcx,%r15,8), %rcx
orq %rcx, (%rax)
movl %ebx, %edi
movl %r15d, %esi
callq 0xce63
testb %al, %al
je 0x4043
cmpl %r14d, %r13d
jge 0x4022
movq 0x20(%rsp), %rax
cmpl %ebp, %r12d
jl 0x4035
movq 0x10(%rsp), %rax
jg 0x4035
jmp 0x4043
jle 0x4043
movq 0x18(%rsp), %rax
cmpl %ebp, %r12d
jl 0x4035
movq 0x8(%rsp), %rax
jle 0x4043
leaq 0xf6474(%rip), %rcx     # 0xfa4b0
movq (%rcx,%r15,8), %rcx
orq %rcx, (%rax)
incq %r15
cmpq $0x40, %r15
jne 0x3f9e
incq %rbx
cmpq $0x40, %rbx
jne 0x3f13
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq