// File: 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
movq %rsp, %rbp
subq $0x20, %rsp
movl $0x0, -0x4(%rbp)
cmpl $0x40, -0x4(%rbp)
jge 0x52c2
movl -0x4(%rbp), %edi
callq 0x12070
movl %eax, -0x8(%rbp)
movl -0x4(%rbp), %edi
callq 0x120d0
movl %eax, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
cmpl $0x8, -0x10(%rbp)
jge 0x50a5
movslq -0x4(%rbp), %rcx
leaq 0x100fe9(%rip), %rax    # 0x106070
shlq $0x6, %rcx
addq %rcx, %rax
movslq -0x10(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x10(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10(%rbp)
jmp 0x5076
movl $0x0, -0x14(%rbp)
cmpl $0x40, -0x14(%rbp)
jge 0x52b2
movl -0x14(%rbp), %edi
callq 0x12070
movl %eax, -0x18(%rbp)
movl -0x14(%rbp), %edi
callq 0x120d0
movl %eax, -0x1c(%rbp)
movl -0x8(%rbp), %eax
cmpl -0x18(%rbp), %eax
jne 0x513a
movl -0x14(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x5105
movslq -0x14(%rbp), %rcx
leaq 0x100589(%rip), %rax    # 0x105670
movq (%rax,%rcx,8), %rcx
movslq -0x4(%rbp), %rdx
leaq 0x100f7a(%rip), %rax    # 0x106070
shlq $0x6, %rdx
addq %rdx, %rax
orq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x5138
movl -0x14(%rbp), %eax
cmpl -0x4(%rbp), %eax
jle 0x5136
movslq -0x14(%rbp), %rcx
leaq 0x100558(%rip), %rax    # 0x105670
movq (%rax,%rcx,8), %rcx
movslq -0x4(%rbp), %rdx
leaq 0x100f49(%rip), %rax    # 0x106070
shlq $0x6, %rdx
addq %rdx, %rax
orq 0x20(%rax), %rcx
movq %rcx, 0x20(%rax)
jmp 0x5138
jmp 0x513a
movl -0xc(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x51aa
movl -0x14(%rbp), %eax
cmpl -0x4(%rbp), %eax
jge 0x5175
movslq -0x14(%rbp), %rcx
leaq 0x10051b(%rip), %rax    # 0x105670
movq (%rax,%rcx,8), %rcx
movslq -0x4(%rbp), %rdx
leaq 0x100f0c(%rip), %rax    # 0x106070
shlq $0x6, %rdx
addq %rdx, %rax
orq 0x30(%rax), %rcx
movq %rcx, 0x30(%rax)
jmp 0x51a8
movl -0x14(%rbp), %eax
cmpl -0x4(%rbp), %eax
jle 0x51a6
movslq -0x14(%rbp), %rcx
leaq 0x1004e8(%rip), %rax    # 0x105670
movq (%rax,%rcx,8), %rcx
movslq -0x4(%rbp), %rdx
leaq 0x100ed9(%rip), %rax    # 0x106070
shlq $0x6, %rdx
addq %rdx, %rax
orq 0x10(%rax), %rcx
movq %rcx, 0x10(%rax)
jmp 0x51a8
jmp 0x51aa
movl -0x4(%rbp), %edi
movl -0x14(%rbp), %esi
callq 0x12940
testb $0x1, %al
jne 0x51be
jmp 0x52a2
movl -0x1c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x522e
movl -0x18(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x51f9
movslq -0x14(%rbp), %rcx
leaq 0x100497(%rip), %rax    # 0x105670
movq (%rax,%rcx,8), %rcx
movslq -0x4(%rbp), %rdx
leaq 0x100e88(%rip), %rax    # 0x106070
shlq $0x6, %rdx
addq %rdx, %rax
orq 0x38(%rax), %rcx
movq %rcx, 0x38(%rax)
jmp 0x522c
movl -0x18(%rbp), %eax
cmpl -0x8(%rbp), %eax
jle 0x522a
movslq -0x14(%rbp), %rcx
leaq 0x100464(%rip), %rax    # 0x105670
movq (%rax,%rcx,8), %rcx
movslq -0x4(%rbp), %rdx
leaq 0x100e55(%rip), %rax    # 0x106070
shlq $0x6, %rdx
addq %rdx, %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
jmp 0x522c
jmp 0x52a0
movl -0x1c(%rbp), %eax
cmpl -0xc(%rbp), %eax
jle 0x529e
movl -0x18(%rbp), %eax
cmpl -0x8(%rbp), %eax
jge 0x5269
movslq -0x14(%rbp), %rcx
leaq 0x100427(%rip), %rax    # 0x105670
movq (%rax,%rcx,8), %rcx
movslq -0x4(%rbp), %rdx
leaq 0x100e18(%rip), %rax    # 0x106070
shlq $0x6, %rdx
addq %rdx, %rax
orq 0x28(%rax), %rcx
movq %rcx, 0x28(%rax)
jmp 0x529c
movl -0x18(%rbp), %eax
cmpl -0x8(%rbp), %eax
jle 0x529a
movslq -0x14(%rbp), %rcx
leaq 0x1003f4(%rip), %rax    # 0x105670
movq (%rax,%rcx,8), %rcx
movslq -0x4(%rbp), %rdx
leaq 0x100de5(%rip), %rax    # 0x106070
shlq $0x6, %rdx
addq %rdx, %rax
orq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
jmp 0x529c
jmp 0x529e
jmp 0x52a0
jmp 0x52a2
jmp 0x52a4
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x50ac
jmp 0x52b4
movl -0x4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4(%rbp)
jmp 0x504f
addq $0x20, %rsp
popq %rbp
retq
nopl (%rax,%rax)