// File: /workspace/github_cpp_makefile_star2_O2/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
leaq 0xfa168(%rip), %r15     # 0xfdeb0
xorl %ebx, %ebx
cmpq $0x40, %rbx
je 0x3ea9
movl %ebx, %edi
callq 0xbfd8
movl %eax, %ebp
movl %ebx, %edi
callq 0xc001
movl %eax, %r14d
xorl %eax, %eax
cmpq $0x8, %rax
je 0x3d79
andq $0x0, (%r15,%rax,8)
incq %rax
jmp 0x3d69
movq %r15, (%rsp)
movq %rbx, %rax
shlq $0x6, %rax
leaq 0xfa125(%rip), %rcx     # 0xfdeb0
leaq (%rcx,%rax), %rdx
addq $0x20, %rdx
movq %rdx, 0x30(%rsp)
leaq (%rcx,%rax), %rdx
movq %rdx, 0x40(%rsp)
leaq 0x10(%rcx,%rax), %rdx
movq %rdx, 0x28(%rsp)
leaq 0x30(%rcx,%rax), %rdx
movq %rdx, 0x38(%rsp)
leaq 0x18(%rcx,%rax), %rdx
movq %rdx, 0x8(%rsp)
leaq 0x28(%rcx,%rax), %rdx
movq %rdx, 0x18(%rsp)
leaq 0x8(%rcx,%rax), %rdx
movq %rdx, 0x10(%rsp)
addq %rcx, %rax
addq $0x38, %rax
movq %rax, 0x20(%rsp)
xorl %r15d, %r15d
cmpq $0x40, %r15
je 0x3e99
movl %r15d, %edi
callq 0xbfd8
movl %eax, %r12d
movl %r15d, %edi
callq 0xc001
movl %eax, %r13d
cmpl %r12d, %ebp
jne 0x3e26
movq 0x40(%rsp), %rax
cmpq %rbx, %r15
jb 0x3e18
movq 0x30(%rsp), %rax
jbe 0x3e26
leaq 0xf9691(%rip), %rcx     # 0xfd4b0
movq (%rcx,%r15,8), %rcx
orq %rcx, (%rax)
cmpl %r13d, %r14d
jne 0x3e4a
movq 0x38(%rsp), %rax
cmpq %rbx, %r15
jb 0x3e3c
movq 0x28(%rsp), %rax
jbe 0x3e4a
leaq 0xf966d(%rip), %rcx     # 0xfd4b0
movq (%rcx,%r15,8), %rcx
orq %rcx, (%rax)
movl %ebx, %edi
movl %r15d, %esi
callq 0xc472
testb %al, %al
je 0x3e91
cmpl %r14d, %r13d
jge 0x3e70
movq 0x20(%rsp), %rax
cmpl %ebp, %r12d
jl 0x3e83
movq 0x10(%rsp), %rax
jg 0x3e83
jmp 0x3e91
jle 0x3e91
movq 0x18(%rsp), %rax
cmpl %ebp, %r12d
jl 0x3e83
movq 0x8(%rsp), %rax
jle 0x3e91
leaq 0xf9626(%rip), %rcx     # 0xfd4b0
movq (%rcx,%r15,8), %rcx
orq %rcx, (%rax)
incq %r15
jmp 0x3de2
incq %rbx
movq (%rsp), %r15
addq $0x40, %r15
jmp 0x3d4a
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq