// File: /workspace/github_cpp_makefile_star2_O2/SethKasmann[P]clever-girl/src/bitboard.cpp
// Function: bb_init()
void bb_init()
{
    for (Square sq_src = first_sq; sq_src <= last_sq; ++sq_src)
    {
        U64 bit = 1ULL << sq_src;
        square_bb[sq_src] = bit;
        pawn_attacks[white][sq_src] = ((bit & Not_h_file) << 7)
                                    | ((bit & Not_a_file) << 9);
        pawn_attacks[black][sq_src] = ((bit & Not_h_file) >> 9)
                                    | ((bit & Not_a_file) >> 7);
        pawn_push[white][sq_src]    = bit << 8;
        pawn_push[black][sq_src]    = bit >> 8;

        U64 front = east_fill(bit) | west_fill(bit);
        in_front[white][sq_src] = north_fill(front << 8);
        in_front[black][sq_src] = south_fill(front >> 8);

        king_net_bb[white][sq_src] = King_moves[sq_src] | (King_moves[sq_src] << 16);
        king_net_bb[black][sq_src] = King_moves[sq_src] | (King_moves[sq_src] >> 16);

        file_bb[sq_src] = north_fill(bit) | south_fill(bit);
        rank_bb[sq_src] = east_fill(bit) | west_fill(bit);

        bishopMoves[sq_src] = (north_east_fill(bit) | north_west_fill(bit) 
                    | south_east_fill(bit) | south_west_fill(bit)) & ~bit;

        rookMoves[sq_src] = (north_fill(bit) | south_fill(bit) 
                  | east_fill(bit) | west_fill(bit)) & ~bit;

        if (bit & Rank_2)
        {
            pawn_dbl_push[white][sq_src] = bit << 16;
            pawn_dbl_push[black][sq_src] = 0;
        }
        else if (bit & Rank_7)
        {
            pawn_dbl_push[white][sq_src] = 0;
            pawn_dbl_push[black][sq_src] = bit >> 16;
        }
        else
        {
            pawn_dbl_push[white][sq_src] = 0;
            pawn_dbl_push[black][sq_src] = 0;
        }
        for (Square sq_dst = H1; sq_dst <= A8; ++sq_dst)
        {
            adj_files[sq_dst] = sq_dst & File_a ? File_b
                              : sq_dst & File_b ? File_a | File_c
                              : sq_dst & File_c ? File_b | File_d
                              : sq_dst & File_d ? File_c | File_e
                              : sq_dst & File_e ? File_d | File_f
                              : sq_dst & File_f ? File_e | File_g
                              : sq_dst & File_g ? File_f | File_h
                              : File_g;


            U64 r_attacks, b_attacks, occ;
            occ = 1ULL << sq_src | 1ULL << sq_dst;
            
            r_attacks = Rmagic(sq_src, 0);
            b_attacks = Bmagic(sq_src, 0);

            r_attacks &= (r_attacks & occ ? Rmagic(sq_dst, 0) : 0);
            b_attacks &= (b_attacks & occ ? Bmagic(sq_dst, 0) : 0);

            coplanar[sq_src][sq_dst] = r_attacks | b_attacks;

            r_attacks = Rmagic(sq_src, occ);
            b_attacks = Bmagic(sq_src, occ);

            r_attacks &= (r_attacks & occ ? Rmagic(sq_dst, occ) : 0);
            b_attacks &= (b_attacks & occ ? Bmagic(sq_dst, occ) : 0);

            between_dia[sq_src][sq_dst] = b_attacks;
            between_hor[sq_src][sq_dst] = r_attacks;
            between[sq_src][sq_dst] = b_attacks | r_attacks;
        }
    }
    outpost_area[white] = Rank_4 | Rank_5 | Rank_6 | Rank_7;
    outpost_area[black] = Rank_2 | Rank_3 | Rank_4 | Rank_5;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
leaq 0x134c9b(%rip), %rax    # 0x13fc80
movq %rax, 0x20(%rsp)
leaq 0x11cc8f(%rip), %rax    # 0x127c80
movq %rax, 0x18(%rsp)
leaq 0x124c83(%rip), %rax    # 0x12fc80
movq %rax, 0x10(%rsp)
leaq 0x12cc77(%rip), %rax    # 0x137c80
movq %rax, 0x8(%rsp)
xorl %ecx, %ecx
cmpq $0x40, %rcx
je 0xb50f
pushq $0x1
popq %r15
shlq %cl, %r15
leaq 0x11ba58(%rip), %rax    # 0x126a80
movq %r15, (%rax,%rcx,8)
movq %r15, %rax
movabsq $-0x101010101010102, %rdx # imm = 0xFEFEFEFEFEFEFEFE
andq %rdx, %rax
movq %rax, %rdi
shlq $0x7, %rdi
movq %r15, %rdx
movabsq $0x7f7f7f7f7f7f7f7f, %rsi # imm = 0x7F7F7F7F7F7F7F7F
andq %rsi, %rdx
movq %rdx, %rsi
shlq $0x9, %rsi
orq %rdi, %rsi
leaq 0x11c01c(%rip), %rdi    # 0x127080
movq %rsi, (%rdi,%rcx,8)
shrq $0x9, %rax
shrq $0x7, %rdx
orq %rax, %rdx
movq %rdx, 0x200(%rdi,%rcx,8)
movl $0x100, %eax            # imm = 0x100
shlq %cl, %rax
leaq 0x11c3f6(%rip), %rdx    # 0x127480
movq %rax, (%rdx,%rcx,8)
movq %r15, %r14
shrq $0x8, %r14
movq %r14, 0x200(%rdx,%rcx,8)
movq %r15, %rdi
movq %rcx, (%rsp)
callq 0xb677
movq %rax, %r12
movq %r15, %rdi
callq 0xb6bb
orq %r12, %rax
movq %rax, %rcx
shlq $0x10, %rcx
orq %rax, %rcx
movq %rax, %rdx
movq %rax, %rsi
shrq $0x10, %rsi
orq %rax, %rsi
shlq $0x8, %rax
orq %rax, %rcx
shlq $0x10, %rcx
orq %rax, %rcx
movq %rcx, %rax
shlq $0x20, %rax
orq %rcx, %rax
movq (%rsp), %rcx
leaq 0x13cd8f(%rip), %rdi    # 0x147e80
movq %rax, (%rdi,%rcx,8)
shrq $0x8, %rdx
orq %rdx, %rsi
shrq $0x10, %rsi
orq %rdx, %rsi
movq %rsi, %rax
shrq $0x20, %rax
orq %rsi, %rax
movq (%rsp), %rcx
movq %rax, 0x200(%rdi,%rcx,8)
movq (%rsp), %rax
leaq 0xbbbc(%rip), %rcx      # 0x16ce0
movq (%rcx,%rax,8), %rax
movq %rax, %rcx
shlq $0x10, %rcx
orq %rax, %rcx
movq (%rsp), %rdx
leaq 0x13d143(%rip), %rsi    # 0x148280
movq %rcx, (%rsi,%rdx,8)
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
movq (%rsp), %rax
movq %rcx, 0x200(%rsi,%rax,8)
movabsq $0x101010101010101, %rax # imm = 0x101010101010101
movq (%rsp), %rcx
shlq %cl, %rax
movq (%rsp), %rcx
btsq %rcx, %r14
movq %r14, %r13
shrq $0x10, %r13
orq %r14, %r13
orq %r13, %rax
shrq $0x20, %r13
orq %rax, %r13
movq (%rsp), %rax
leaq 0x11baf1(%rip), %rcx    # 0x126c80
movq %r13, (%rcx,%rax,8)
movq %r15, %rdi
callq 0xb677
movq %rax, %r12
movq %r15, %rdi
callq 0xb6bb
orq %r12, %rax
movq (%rsp), %rcx
leaq 0x11bccc(%rip), %rdx    # 0x126e80
movq %rax, (%rdx,%rcx,8)
movq %r15, %rdi
callq 0xb700
movq %rax, %rbx
movq %r15, %rdi
callq 0xb73d
movq %rax, %r12
orq %rbx, %r12
movq %r15, %rdi
callq 0xb77a
movq %rax, %rbx
movq %r15, %rdi
callq 0xb7b8
orq %rbx, %rax
orq %r12, %rax
movq (%rsp), %rcx
btrq %rcx, %rax
movq (%rsp), %rcx
leaq 0x13d493(%rip), %rdx    # 0x148690
movq %rax, (%rdx,%rcx,8)
movq %r15, %rdi
callq 0xb677
movq %rax, %r12
movq %r15, %rdi
callq 0xb6bb
movq (%rsp), %rcx
orq %r12, %rax
orq %r13, %rax
btrq %rcx, %rax
leaq 0x13d667(%rip), %rdx    # 0x148890
movq %rax, (%rdx,%rcx,8)
movl $0xff00, %eax           # imm = 0xFF00
btq %rcx, %rax
jae 0xb24f
movl $0x10000, %eax          # imm = 0x10000
shlq %cl, %rax
leaq 0x11c639(%rip), %rsi    # 0x127880
movq %rax, (%rsi,%rcx,8)
xorl %eax, %eax
jmp 0xb279
movq %r15, %rdx
movabsq $0xff000000000000, %rax # imm = 0xFF000000000000
andq %rax, %rdx
leaq 0x11c61a(%rip), %rsi    # 0x127880
andq $0x0, (%rsi,%rcx,8)
movq %r15, %rax
shrq $0x10, %rax
testq %rdx, %rdx
cmoveq %rdx, %rax
movq %rax, 0x200(%rsi,%rcx,8)
leaq 0x181a8(%rip), %rax     # 0x23430
movq (%rax,%rcx,8), %rsi
leaq 0xae3d(%rip), %rax      # 0x160d0
movl (%rax,%rcx,4), %eax
movq %rax, 0x30(%rsp)
leaq 0x17f8e(%rip), %rax     # 0x23230
movq (%rax,%rcx,8), %rdi
leaq 0xb323(%rip), %rax      # 0x165d0
movl (%rax,%rcx,4), %eax
movq %rax, 0x28(%rsp)
leaq 0xb114(%rip), %rax      # 0x163d0
movq (%rax,%rcx,8), %r8
leaq 0xaf09(%rip), %rax      # 0x161d0
movq (%rax,%rcx,8), %r9
leaq 0xb5fe(%rip), %rax      # 0x168d0
movq (%rax,%rcx,8), %rax
leaq 0xb3f3(%rip), %r10      # 0x166d0
movq (%r10,%rcx,8), %r11
xorl %r12d, %r12d
xorl %r13d, %r13d
movq %r15, %rdx
cmpq $0x40, %r13
je 0xb4ea
leaq 0x11b785(%rip), %rcx    # 0x126a80
movq (%r12,%rcx), %rcx
movabsq $0x4040404040404040, %rbx # imm = 0x4040404040404040
movabsq $-0x7f7f7f7f7f7f7f80, %r10 # imm = 0x8080808080808080
testq %r10, %rcx
jne 0xb3b4
movabsq $-0x5f5f5f5f5f5f5f60, %rbx # imm = 0xA0A0A0A0A0A0A0A0
movabsq $0x4040404040404040, %r10 # imm = 0x4040404040404040
testq %r10, %rcx
jne 0xb3b4
movabsq $0x5050505050505050, %rbx # imm = 0x5050505050505050
movabsq $0x2020202020202020, %r10 # imm = 0x2020202020202020
testq %r10, %rcx
jne 0xb3b4
movabsq $0x2828282828282828, %rbx # imm = 0x2828282828282828
movabsq $0x1010101010101010, %r10 # imm = 0x1010101010101010
testq %r10, %rcx
jne 0xb3b4
movabsq $0x1414141414141414, %rbx # imm = 0x1414141414141414
movabsq $0x808080808080808, %r10 # imm = 0x808080808080808
testq %r10, %rcx
jne 0xb3b4
movabsq $0xa0a0a0a0a0a0a0a, %rbx # imm = 0xA0A0A0A0A0A0A0A
movabsq $0x404040404040404, %r10 # imm = 0x404040404040404
testq %r10, %rcx
jne 0xb3b4
movabsq $0x202020202020202, %r10 # imm = 0x202020202020202
testq %r10, %rcx
movabsq $0x505050505050505, %rbx # imm = 0x505050505050505
cmoveq %r10, %rbx
leaq 0x13c8c5(%rip), %rcx    # 0x147c80
movq %rbx, (%r12,%rcx)
movq %r15, %r14
btsq %r13, %r14
movq (%rsi), %rcx
testq %r14, %rcx
je 0xb3de
leaq 0x1805b(%rip), %r10     # 0x23430
movq (%r10,%r13,8), %rbx
movq (%rbx), %rbx
jmp 0xb3e0
xorl %ebx, %ebx
movq (%rdi), %rbp
testq %r14, %rbp
je 0xb3f8
leaq 0x17e41(%rip), %r10     # 0x23230
movq (%r10,%r13,8), %r15
movq (%r15), %r15
jmp 0xb3fb
xorl %r15d, %r15d
andq %rcx, %rbx
andq %rbp, %r15
movq %r8, %rbp
andq %r14, %rbp
imulq %r9, %rbp
movq 0x30(%rsp), %rcx
shrq %cl, %rbp
orq %rbx, %r15
movq %rax, %r10
andq %r14, %r10
imulq %r11, %r10
movq 0x28(%rsp), %rcx
shrq %cl, %r10
movq 0x20(%rsp), %rcx
movq %r15, (%rcx,%r13,8)
movq (%rsi,%rbp,8), %rbx
movq (%rdi,%r10,8), %rbp
testq %r14, %rbx
je 0xb477
leaq 0x17feb(%rip), %rcx     # 0x23430
movq (%rcx,%r13,8), %r10
leaq 0xaf80(%rip), %rcx      # 0x163d0
movq (%rcx,%r13,8), %r15
andq %r14, %r15
leaq 0xad72(%rip), %rcx      # 0x161d0
imulq (%rcx,%r13,8), %r15
leaq 0xac66(%rip), %rcx      # 0x160d0
movb (%rcx,%r13,4), %cl
shrq %cl, %r15
movq (%r10,%r15,8), %r15
jmp 0xb47a
xorl %r15d, %r15d
testq %r14, %rbp
je 0xb4b5
leaq 0x17daa(%rip), %rcx     # 0x23230
movq (%rcx,%r13,8), %r10
leaq 0xb43f(%rip), %rcx      # 0x168d0
andq (%rcx,%r13,8), %r14
leaq 0xb234(%rip), %rcx      # 0x166d0
imulq (%rcx,%r13,8), %r14
leaq 0xb128(%rip), %rcx      # 0x165d0
movb (%rcx,%r13,4), %cl
shrq %cl, %r14
movq (%r10,%r14,8), %rcx
jmp 0xb4b7
xorl %ecx, %ecx
andq %rbx, %r15
andq %rbp, %rcx
movq 0x18(%rsp), %r10
movq %rcx, (%r10,%r13,8)
movq 0x10(%rsp), %r10
movq %r15, (%r10,%r13,8)
orq %r15, %rcx
movq 0x8(%rsp), %r10
movq %rcx, (%r10,%r13,8)
incq %r13
addq $0x8, %r12
movq %rdx, %r15
jmp 0xb2ea
movq (%rsp), %rcx
incq %rcx
movl $0x200, %eax            # imm = 0x200
addq %rax, 0x20(%rsp)
addq %rax, 0x18(%rsp)
addq %rax, 0x10(%rsp)
addq %rax, 0x8(%rsp)
jmp 0xb010
movabsq $0xffffffff000000, %rax # imm = 0xFFFFFFFF000000
movq %rax, 0x13d160(%rip)    # 0x148680
movabsq $0xffffffff00, %rax     # imm = 0xFFFFFFFF00
movq %rax, 0x13d157(%rip)    # 0x148688
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq