// File: /workspace/github_cpp_makefile_star2_O1/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
movabsq $-0x101010101010102, %rax # imm = 0xFEFEFEFEFEFEFEFE
movabsq $-0x303030303040000, %rcx # imm = 0xFCFCFCFCFCFC0000
movabsq $0x3f3f3f3f3f3f0000, %rdx # imm = 0x3F3F3F3F3F3F0000
movabsq $0xf0f0f0f00000000, %rsi # imm = 0xF0F0F0F00000000
leaq 0x1043f3(%rip), %rdi    # 0x111c70
movq %rdi, -0x40(%rsp)
leaq 0xec3e7(%rip), %rdi     # 0xf9c70
movq %rdi, -0x48(%rsp)
leaq 0xf43db(%rip), %rdi     # 0x101c70
movq %rdi, -0x50(%rsp)
leaq 0xfc3cf(%rip), %rdi     # 0x109c70
movq %rdi, -0x58(%rsp)
xorl %ebx, %ebx
addq $0xfcfc, %rcx           # imm = 0xFCFC
movq %rcx, -0x20(%rsp)
leaq 0x3f3f(%rdx), %rcx
movq %rcx, -0x28(%rsp)
movl $0xf0f0f0f, %ecx        # imm = 0xF0F0F0F
addq %rsi, %rcx
movq %rcx, -0x30(%rsp)
addq $-0xfe, %rax
movq %rax, -0x38(%rsp)
leaq 0xebf91(%rip), %r14     # 0xf9870
movl $0x1, %r12d
movl %ebx, %ecx
shlq %cl, %r12
movq %r12, %rax
movabsq $-0x101010101010102, %rdi # imm = 0xFEFEFEFEFEFEFEFE
andq %rdi, %rax
movq %rax, %rcx
shlq $0x7, %rcx
movq %r12, %rdx
movabsq $0x7f7f7f7f7f7f7f7f, %r9 # imm = 0x7F7F7F7F7F7F7F7F
andq %r9, %rdx
movq %rdx, %rsi
shlq $0x9, %rsi
orq %rcx, %rsi
leaq 0xeb74e(%rip), %r8      # 0xf9070
movq %rsi, (%r8,%rbx,8)
shrq $0x9, %rax
shrq $0x7, %rdx
movl $0x100, %esi            # imm = 0x100
movl %ebx, %ecx
shlq %cl, %rsi
orq %rax, %rdx
movq %rdx, 0x200(%r8,%rbx,8)
leaq 0xebb26(%rip), %rax     # 0xf9470
movq %rsi, (%rax,%rbx,8)
movq %r12, %r11
shrq $0x8, %r11
movq %r11, 0x200(%rax,%rbx,8)
movl $0x2, %eax
shlq %cl, %rax
andq %rdi, %rax
btsq %rbx, %rax
leaq (,%rax,4), %rcx
andq -0x20(%rsp), %rcx
orq %rax, %rcx
movq %rcx, %rax
shlq $0x4, %rax
movabsq $-0xf0f0f0f0f0f0f10, %rdx # imm = 0xF0F0F0F0F0F0F0F0
andq %rdx, %rax
orq %rcx, %rax
movq %r12, %rcx
shrq %rcx
andq %r9, %rcx
btsq %rbx, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
andq -0x28(%rsp), %rdx
orq %rcx, %rdx
movq %rdx, %rsi
shrq $0x4, %rsi
andq -0x30(%rsp), %rsi
orq %rdx, %rsi
orq %rax, %rsi
movq %rsi, %rdi
shlq $0x10, %rdi
orq %rsi, %rdi
movq %rsi, %r10
movq %rsi, %r8
shrq $0x10, %r8
btsq %rbx, %r11
movq %r11, %rdx
shrq $0x10, %rdx
orq %r11, %rdx
movabsq $0x101010101010101, %rax # imm = 0x101010101010101
movl %ebx, %ecx
shlq %cl, %rax
orq %rsi, %r8
orq %rdx, %rax
shrq $0x20, %rdx
orq %rax, %rdx
leaq 0xeb26a(%rip), %rax     # 0xf8c70
movq %rdx, (%rax,%rbx,8)
leaq 0xeb45f(%rip), %rax     # 0xf8e70
movq %rsi, (%rax,%rbx,8)
orq %rsi, %rdx
shlq $0x8, %rsi
orq %rsi, %rdi
shlq $0x10, %rdi
orq %rsi, %rdi
movq %rdi, %rax
shlq $0x20, %rax
orq %rdi, %rax
leaq 0x10c439(%rip), %rcx    # 0x119e70
movq %rax, (%rcx,%rbx,8)
shrq $0x8, %r10
orq %r10, %r8
shrq $0x10, %r8
orq %r10, %r8
movq %r8, %rax
shrq $0x20, %rax
orq %r8, %rax
movq %rax, 0x200(%rcx,%rbx,8)
leaq 0xe2de(%rip), %rax      # 0x1bd40
movq (%rax,%rbx,8), %rax
movq %rax, %rcx
shlq $0x10, %rcx
orq %rax, %rcx
leaq 0x10c7f9(%rip), %r8     # 0x11a270
movq %rcx, (%r8,%rbx,8)
movq %rax, %rsi
shrq $0x10, %rsi
movl $0x200, %edi            # imm = 0x200
movl %ebx, %ecx
shlq %cl, %rdi
orq %rax, %rsi
movq %rsi, 0x200(%r8,%rbx,8)
andq -0x38(%rsp), %rdi
btsq %rbx, %rdi
movq %rdi, %rsi
shlq $0x12, %rsi
movabsq $-0x303030303040000, %rax # imm = 0xFCFCFCFCFCFC0000
andq %rax, %rsi
movl $0x80, %eax
shlq %cl, %rax
orq %rdi, %rsi
leaq -0x7f(%r9), %rcx
andq %rax, %rcx
btsq %rbx, %rcx
movq %rcx, %rax
shlq $0xe, %rax
movabsq $0x3f3f3f3f3f3f0000, %rdi # imm = 0x3F3F3F3F3F3F0000
andq %rdi, %rax
orq %rcx, %rax
movq %r12, %rcx
shrq $0x7, %rcx
movabsq $0xfefefefefefefe, %rdi # imm = 0xFEFEFEFEFEFEFE
andq %rdi, %rcx
btsq %rbx, %rcx
movq %rcx, %rdi
shrq $0xe, %rdi
movabsq $0xfcfcfcfcfcfc, %r8    # imm = 0xFCFCFCFCFCFC
andq %r8, %rdi
orq %rcx, %rdi
movq %r12, %rcx
shrq $0x9, %rcx
movabsq $0x7f7f7f7f7f7f7f, %r8  # imm = 0x7F7F7F7F7F7F7F
andq %r8, %rcx
btsq %rbx, %rcx
movq %rcx, %r8
shrq $0x12, %r8
movabsq $0x3f3f3f3f3f3f, %r9    # imm = 0x3F3F3F3F3F3F
andq %r9, %r8
orq %rcx, %r8
movq %rsi, %rcx
movl $0xf0f0f0f, %r10d       # imm = 0xF0F0F0F
andq %r10, %rcx
shlq $0x24, %rcx
orq %r8, %rsi
orq %rdi, %rsi
shrq $0x1c, %rdi
andl $0xf0f0f0f0, %edi       # imm = 0xF0F0F0F0
orq %rax, %rdi
shlq $0x1c, %rax
movabsq $0xf0f0f0f00000000, %r9 # imm = 0xF0F0F0F00000000
andq %r9, %rax
orq %rcx, %rax
shrq $0x24, %r8
andq %r10, %r8
orq %rax, %r8
orq %r8, %rdi
orq %rdi, %rsi
btrq %rbx, %rsi
leaq 0x10caef(%rip), %rax    # 0x11a680
movq %rsi, (%rax,%rbx,8)
btrq %rbx, %rdx
leaq 0x10cce0(%rip), %rax    # 0x11a880
movq %rdx, (%rax,%rbx,8)
leaq 0xeaec5(%rip), %rax     # 0xf8a70
movq %r12, (%rax,%rbx,8)
movl $0xff00, %eax           # imm = 0xFF00
btq %rbx, %rax
jae 0xdbcc
movl $0x10000, %eax          # imm = 0x10000
movl %ebx, %ecx
shlq %cl, %rax
movq %rax, (%r14,%rbx,8)
xorl %eax, %eax
jmp 0xdbf2
movq %r12, %rcx
movabsq $0xff000000000000, %rax # imm = 0xFF000000000000
andq %rax, %rcx
movq %r12, %rax
shrq $0x10, %rax
testq %rcx, %rcx
movq $0x0, (%r14,%rbx,8)
cmoveq %rcx, %rax
movq %rax, 0x200(%r14,%rbx,8)
leaq 0x1780f(%rip), %rax     # 0x25410
movq (%rax,%rbx,8), %rbp
leaq 0xd434(%rip), %rax      # 0x1b040
movl (%rax,%rbx,4), %eax
movq %rax, -0x8(%rsp)
leaq 0x175f5(%rip), %rax     # 0x25210
movq (%rax,%rbx,8), %rdi
leaq 0xd91a(%rip), %rax      # 0x1b540
movl (%rax,%rbx,4), %eax
movq %rax, -0x10(%rsp)
leaq 0xd70b(%rip), %rax      # 0x1b340
movq (%rax,%rbx,8), %r8
leaq 0xd500(%rip), %rax      # 0x1b140
movq (%rax,%rbx,8), %r11
leaq 0xdbf5(%rip), %rax      # 0x1b840
movq (%rax,%rbx,8), %rdx
movq %rbx, -0x18(%rsp)
leaq 0xd9e5(%rip), %rax      # 0x1b640
movq (%rax,%rbx,8), %r10
xorl %r14d, %r14d
xorl %r15d, %r15d
leaq 0xeae04(%rip), %rax     # 0xf8a70
movq (%r14,%rax), %rax
movabsq $0x4040404040404040, %rcx # imm = 0x4040404040404040
movabsq $-0x7f7f7f7f7f7f7f80, %r9 # imm = 0x8080808080808080
testq %r9, %rax
jne 0xdd25
movabsq $-0x5f5f5f5f5f5f5f60, %rcx # imm = 0xA0A0A0A0A0A0A0A0
movabsq $0x4040404040404040, %r9 # imm = 0x4040404040404040
testq %r9, %rax
jne 0xdd25
movabsq $0x5050505050505050, %rcx # imm = 0x5050505050505050
movabsq $0x2020202020202020, %r9 # imm = 0x2020202020202020
testq %r9, %rax
jne 0xdd25
movabsq $0x2828282828282828, %rcx # imm = 0x2828282828282828
movabsq $0x1010101010101010, %r9 # imm = 0x1010101010101010
testq %r9, %rax
jne 0xdd25
movabsq $0x1414141414141414, %rcx # imm = 0x1414141414141414
movabsq $0x808080808080808, %r9 # imm = 0x808080808080808
testq %r9, %rax
jne 0xdd25
movabsq $0xa0a0a0a0a0a0a0a, %rcx # imm = 0xA0A0A0A0A0A0A0A
movabsq $0x404040404040404, %r9 # imm = 0x404040404040404
testq %r9, %rax
jne 0xdd25
movabsq $0x202020202020202, %r9 # imm = 0x202020202020202
testq %r9, %rax
movabsq $0x505050505050505, %rcx # imm = 0x505050505050505
cmoveq %r9, %rcx
leaq 0x10bf44(%rip), %rax    # 0x119c70
movq %rcx, (%r14,%rax)
movq %r12, %r9
btsq %r15, %r9
movq (%rbp), %r13
movq (%rdi), %rcx
testq %r9, %r13
je 0xdd53
leaq 0x176c6(%rip), %rax     # 0x25410
movq (%rax,%r15,8), %rax
movq (%rax), %rax
jmp 0xdd55
xorl %eax, %eax
movq %r12, %rsi
testq %r9, %rcx
je 0xdd6e
leaq 0x174ac(%rip), %rbx     # 0x25210
movq (%rbx,%r15,8), %r12
movq (%r12), %r12
jmp 0xdd71
xorl %r12d, %r12d
andq %r13, %rax
andq %rcx, %r12
movq %r8, %r13
andq %r9, %r13
imulq %r11, %r13
movq -0x8(%rsp), %rcx
shrq %cl, %r13
orq %rax, %r12
movq %rdx, %rbx
andq %r9, %rbx
imulq %r10, %rbx
movq -0x10(%rsp), %rcx
shrq %cl, %rbx
movq -0x40(%rsp), %rax
movq %r12, (%rax,%r15,8)
movq (%rbp,%r13,8), %rax
movq (%rdi,%rbx,8), %r13
testq %r9, %rax
je 0xddee
leaq 0x17654(%rip), %rcx     # 0x25410
movq (%rcx,%r15,8), %rbx
leaq 0xd579(%rip), %rcx      # 0x1b340
movq (%rcx,%r15,8), %r12
andq %r9, %r12
leaq 0xd36b(%rip), %rcx      # 0x1b140
imulq (%rcx,%r15,8), %r12
leaq 0xd25f(%rip), %rcx      # 0x1b040
movb (%rcx,%r15,4), %cl
shrq %cl, %r12
movq (%rbx,%r12,8), %r12
jmp 0xddf1
xorl %r12d, %r12d
testq %r9, %r13
je 0xde2c
leaq 0x17413(%rip), %rcx     # 0x25210
movq (%rcx,%r15,8), %rbx
leaq 0xda38(%rip), %rcx      # 0x1b840
andq (%rcx,%r15,8), %r9
leaq 0xd82d(%rip), %rcx      # 0x1b640
imulq (%rcx,%r15,8), %r9
leaq 0xd721(%rip), %rcx      # 0x1b540
movb (%rcx,%r15,4), %cl
shrq %cl, %r9
movq (%rbx,%r9,8), %rcx
jmp 0xde2e
xorl %ecx, %ecx
andq %rax, %r12
andq %r13, %rcx
movq -0x48(%rsp), %rax
movq %rcx, (%rax,%r15,8)
movq -0x50(%rsp), %rax
movq %r12, (%rax,%r15,8)
orq %r12, %rcx
movq -0x58(%rsp), %rax
movq %rcx, (%rax,%r15,8)
incq %r15
addq $0x8, %r14
cmpq $0x40, %r15
movq %rsi, %r12
jne 0xdc65
movq -0x18(%rsp), %rbx
incq %rbx
movl $0x200, %eax            # imm = 0x200
addq %rax, -0x40(%rsp)
addq %rax, -0x48(%rsp)
addq %rax, -0x50(%rsp)
addq %rax, -0x58(%rsp)
cmpq $0x40, %rbx
leaq 0xeb9de(%rip), %r14     # 0xf9870
jne 0xd8df
movabsq $0xffffffff000000, %rax # imm = 0xFFFFFFFF000000
movq %rax, 0x10c7c7(%rip)    # 0x11a670
movabsq $0xffffffff00, %rax     # imm = 0xFFFFFFFF00
movq %rax, 0x10c7be(%rip)    # 0x11a678
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq