// File: /workspace/github_cpp_makefile_star2_O2/cpirc[P]Monochrome/src/bitboard.cpp
// Function: init_bitboards()
void init_bitboards() {
    initmagicmoves();

    // Pawns
    for (int sq = A1; sq <= H8; sq++) {
        std::uint64_t from = 1ULL << sq;
        pawn_mask[US][sq] = ((from << 7) & ~file_mask[FILE_H]) |
                            ((from << 9) & ~file_mask[FILE_A]);
        pawn_mask[THEM][sq] = ((from >> 7) & ~file_mask[FILE_A]) |
                              ((from >> 9) & ~file_mask[FILE_H]);
    }

    // Knights
    for (int sq = A1; sq <= H8; sq++) {
        std::uint64_t from = 1ULL << sq;
        knight_mask[sq] = (from >> 17) & (~file_mask[FILE_H]);   // Up 2 right 1
        knight_mask[sq] |= (from >> 15) & (~file_mask[FILE_A]);  // Up 2 left 1
        knight_mask[sq] |=
            (from << 17) & (~file_mask[FILE_A]);  // Down 2 left 1
        knight_mask[sq] |=
            (from << 15) & (~file_mask[FILE_H]);  // Down 2 right 1
        knight_mask[sq] |= (from >> 10) & ~(file_mask[FILE_G] |
                                            file_mask[FILE_H]);  // Right 2 up 1
        knight_mask[sq] |=
            (from << 6) &
            ~(file_mask[FILE_G] | file_mask[FILE_H]);  // Right 2 down 1
        knight_mask[sq] |= (from >> 6) & ~(file_mask[FILE_A] |
                                           file_mask[FILE_B]);  // Left 2 up 1
        knight_mask[sq] |= (from << 10) & ~(file_mask[FILE_A] |
                                            file_mask[FILE_B]);  // Left 2 up 1
        knight_mask[sq] |=
            (from << 10) &
            ~(file_mask[FILE_A] | file_mask[FILE_B]);  // Left 2 down 1
    }

    // Kings
    for (int sq = A1; sq <= H8; sq++) {
        std::uint64_t from = 1ULL << sq;
        king_mask[sq] = (from >> 8);                          // Up 1
        king_mask[sq] |= (from << 8);                         // Down 1
        king_mask[sq] |= (from >> 1) & (~file_mask[FILE_H]);  // Right 1
        king_mask[sq] |= (from << 1) & (~file_mask[FILE_A]);  // Left 1
        king_mask[sq] |= (from >> 7) & (~file_mask[FILE_A]);  // Up 1 Left 1
        king_mask[sq] |= (from >> 9) & (~file_mask[FILE_H]);  // Up 1 Right 1
        king_mask[sq] |= (from << 7) & (~file_mask[FILE_H]);  // Down 1 Right 1
        king_mask[sq] |= (from << 9) & (~file_mask[FILE_A]);  // Down 1 Left 1
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movabsq $-0x101010101010200, %r14 # imm = 0xFEFEFEFEFEFEFE00
movabsq $0x7f7f7f7f7f7f7f00, %r15 # imm = 0x7F7F7F7F7F7F7F00
movabsq $0xfefefefefefefe, %r12 # imm = 0xFEFEFEFEFEFEFE
callq 0x36e7
xorl %ecx, %ecx
pushq $0x1
popq %rbx
leaq 0xcc67(%rip), %rax      # 0xf1a0
cmpq $0x40, %rcx
je 0x258d
movq %rbx, %rdx
shlq %cl, %rdx
movl $0x80, %esi
shlq %cl, %rsi
movl $0x200, %edi            # imm = 0x200
shlq %cl, %rdi
andq %r15, %rsi
andq %r14, %rdi
orq %rsi, %rdi
movq %rdi, (%rax,%rcx,8)
movq %rdx, %rsi
shrq $0x7, %rsi
andq %r12, %rsi
shrq $0x9, %rdx
movabsq $0x7f7f7f7f7f7f7f, %rdi # imm = 0x7F7F7F7F7F7F7F
andq %rdi, %rdx
orq %rsi, %rdx
movq %rdx, 0x200(%rax,%rcx,8)
incq %rcx
jmp 0x2539
leaq 0xd00c(%rip), %rdx      # 0xf5a0
xorl %ecx, %ecx
leaq -0xfe00(%r14), %r8
leaq -0x7f00(%r15), %r9
pushq $0x40
popq %r10
movabsq $0x3f3f3f3f3f3f3f00, %r13 # imm = 0x3F3F3F3F3F3F3F00
movabsq $0xfcfcfcfcfcfcfc, %r15 # imm = 0xFCFCFCFCFCFCFC
movabsq $-0x303030303030400, %r12 # imm = 0xFCFCFCFCFCFCFC00
cmpq $0x40, %rcx
je 0x2667
movq %rbx, %rax
shlq %cl, %rax
movq %rax, %rsi
shrq $0x11, %rsi
movabsq $0x7f7f7f7f7f7f, %rdi   # imm = 0x7F7F7F7F7F7F
andq %rdi, %rsi
movq %rax, %r14
shrq $0xf, %r14
movabsq $0xfefefefefefe, %rdi   # imm = 0xFEFEFEFEFEFE
andq %rdi, %r14
orq %rsi, %r14
movl $0x20000, %edi          # imm = 0x20000
shlq %cl, %rdi
movl $0x8000, %esi           # imm = 0x8000
shlq %cl, %rsi
andq %r8, %rdi
andq %r9, %rsi
orq %rdi, %rsi
movq %rax, %rdi
shrq $0xa, %rdi
movabsq $0x3f3f3f3f3f3f3f, %r11 # imm = 0x3F3F3F3F3F3F3F
andq %r11, %rdi
movq %r10, %r11
shlq %cl, %r11
andq %r13, %r11
shrq $0x6, %rax
andq %r15, %rax
orq %rdi, %rax
movl $0x400, %edi            # imm = 0x400
shlq %cl, %rdi
andq %r12, %rdi
orq %r11, %rdi
orq %rsi, %rdi
orq %r14, %rdi
orq %rax, %rdi
movq %rdi, (%rdx)
incq %rcx
addq $0x8, %rdx
jmp 0x25c6
leaq 0xd132(%rip), %rdx      # 0xf7a0
xorl %ecx, %ecx
movabsq $0x7f7f7f7f7f7f7f00, %r12 # imm = 0x7F7F7F7F7F7F7F00
leaq 0x7f(%r12), %rsi
movabsq $-0x101010101010200, %r15 # imm = 0xFEFEFEFEFEFEFE00
leaq 0xfe(%r15), %r8
movabsq $0xfefefefefefefe, %r13 # imm = 0xFEFEFEFEFEFEFE
movabsq $0x7f7f7f7f7f7f7f, %rdi # imm = 0x7F7F7F7F7F7F7F
cmpq $0x40, %rcx
je 0x271d
movq %rbx, %rax
shlq %cl, %rax
movq %rax, %r9
shrq $0x8, %r9
movl $0x100, %r10d           # imm = 0x100
shlq %cl, %r10
orq %r9, %r10
movq %rax, %r9
pushq $0x2
popq %r11
shlq %cl, %r11
andq %r8, %r11
movq %rax, %r14
shrq $0x7, %r14
andq %r13, %r14
shrq $0x9, %rax
andq %rdi, %rax
orq %r14, %rax
movl $0x80, %r14d
shlq %cl, %r14
andq %r12, %r14
orq %r11, %r14
shrq %r9
orq %r10, %r14
movl $0x200, %r10d           # imm = 0x200
shlq %cl, %r10
andq %rsi, %r9
andq %r15, %r10
orq %r9, %r10
orq %r14, %r10
orq %rax, %r10
movq %r10, (%rdx)
incq %rcx
addq $0x8, %rdx
jmp 0x26a4
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq