// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx # imm = 0xFEFEFEFEFEFEFE00
movabsq $0x7f7f7f7f7f7f7f00, %r14 # imm = 0x7F7F7F7F7F7F7F00
movabsq $0xfefefefefefefe, %r15 # imm = 0xFEFEFEFEFEFEFE
movabsq $0x7f7f7f7f7f7f7f, %r12 # imm = 0x7F7F7F7F7F7F7F
callq 0x4726
xorl %ecx, %ecx
leaq 0xd8f0(%rip), %rax      # 0x111c0
movl $0x1, %edx
shlq %cl, %rdx
movl $0x80, %esi
shlq %cl, %rsi
andq %r14, %rsi
movl $0x200, %edi            # imm = 0x200
shlq %cl, %rdi
andq %rbx, %rdi
orq %rsi, %rdi
movq %rdi, (%rax,%rcx,8)
movq %rdx, %rsi
shrq $0x7, %rsi
andq %r15, %rsi
shrq $0x9, %rdx
andq %r12, %rdx
orq %rsi, %rdx
movq %rdx, 0x200(%rax,%rcx,8)
incq %rcx
cmpq $0x40, %rcx
jne 0x38d0
leaq 0xdc9f(%rip), %rax      # 0x115c0
xorl %ecx, %ecx
movabsq $0xfefefefefefe, %rsi   # imm = 0xFEFEFEFEFEFE
leaq -0xfe00(%rbx), %rdi
leaq -0x7f00(%r14), %r8
movabsq $0x3f3f3f3f3f3f3f, %r9  # imm = 0x3F3F3F3F3F3F3F
movabsq $0x3f3f3f3f3f3f3f00, %r10 # imm = 0x3F3F3F3F3F3F3F00
movabsq $0xfcfcfcfcfcfcfc, %r11 # imm = 0xFCFCFCFCFCFCFC
movabsq $-0x303030303030400, %r13 # imm = 0xFCFCFCFCFCFCFC00
movl $0x1, %r15d
shlq %cl, %r15
movq %r15, %rbx
shrq $0x11, %rbx
movabsq $0x7f7f7f7f7f7f, %rdx   # imm = 0x7F7F7F7F7F7F
andq %rdx, %rbx
movq %r15, %r12
shrq $0xf, %r12
movl $0x20000, %r14d         # imm = 0x20000
shlq %cl, %r14
andq %rsi, %r12
orq %rbx, %r12
andq %rdi, %r14
movl $0x8000, %ebx           # imm = 0x8000
shlq %cl, %rbx
andq %r8, %rbx
orq %r14, %rbx
movq %r15, %r14
movl $0x40, %edx
shlq %cl, %rdx
shrq $0xa, %r14
andq %r9, %r14
andq %r10, %rdx
shrq $0x6, %r15
andq %r11, %r15
orq %r14, %r15
movl $0x400, %r14d           # imm = 0x400
shlq %cl, %r14
andq %r13, %r14
orq %rdx, %r14
orq %rbx, %r14
orq %r12, %r14
orq %r15, %r14
movq %r14, (%rax)
incq %rcx
addq $0x8, %rax
cmpq $0x40, %rcx
jne 0x3963
leaq 0xddc7(%rip), %rax      # 0x117c0
xorl %ecx, %ecx
movabsq $0x7f7f7f7f7f7f7f00, %r15 # imm = 0x7F7F7F7F7F7F7F00
leaq 0x7f(%r15), %rdx
movabsq $-0x101010101010200, %r14 # imm = 0xFEFEFEFEFEFEFE00
leaq 0xfe(%r14), %rsi
movabsq $0xfefefefefefefe, %r12 # imm = 0xFEFEFEFEFEFEFE
movabsq $0x7f7f7f7f7f7f7f, %r13 # imm = 0x7F7F7F7F7F7F7F
movl $0x1, %edi
shlq %cl, %rdi
movq %rdi, %r9
shrq $0x8, %r9
movl $0x100, %r8d            # imm = 0x100
shlq %cl, %r8
movl $0x2, %r10d
shlq %cl, %r10
orq %r9, %r8
movq %rdi, %r9
movq %rdi, %r11
shrq $0x7, %r11
andq %r12, %r11
shrq $0x9, %rdi
andq %r13, %rdi
movl $0x80, %ebx
shlq %cl, %rbx
orq %r11, %rdi
andq %rsi, %r10
andq %r15, %rbx
orq %r10, %rbx
shrq %r9
andq %rdx, %r9
orq %r8, %rbx
movl $0x200, %r8d            # imm = 0x200
shlq %cl, %r8
andq %r14, %r8
orq %r9, %r8
orq %rbx, %r8
orq %rdi, %r8
movq %r8, (%rax)
incq %rcx
addq $0x8, %rax
cmpq $0x40, %rcx
jne 0x3a2e
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop