// File: /workspace/github_cpp_makefile_star2_O3/cpirc[P]Monochrome/src/move_gen.cpp
// Function: void add_moves<false, (Piece)5>(Position const&, unsigned int*, int&)
void add_moves<false, KING>(const Position& pos, Move* ml, int& idx) {
    std::uint64_t occ = get_occupancy(pos);

    Square from = lsb(get_piece(pos, KING, US));

    std::uint64_t attack_bb = attacks<KING>(from, occ) & ~occ;

    while (attack_bb) {
        Square dest = lsb(attack_bb);

        ml[idx] = get_move(from, dest, NORMAL);
        idx++;

        attack_bb &= attack_bb - 1;
    }

    if (!is_checked(pos, US)) {
        if (pos.castle & US_OO && !(occ & oo_castle_mask) &&
            !(attacks_to<>(pos, F1, occ, US) & get_colour(pos, THEM)) &&
            !(attacks_to<>(pos, G1, occ, US) & get_colour(pos, THEM))) {
            ml[idx] = get_move(E1, G1, CASTLE);
            idx++;
        }

        if (pos.castle & US_OOO && !(occ & ooo_castle_mask) &&
            !(attacks_to<>(pos, D1, occ, US) & get_colour(pos, THEM)) &&
            !(attacks_to<>(pos, C1, occ, US) & get_colour(pos, THEM))) {
            ml[idx] = get_move(E1, C1, CASTLE);
            idx++;
        }
    }

    // No tail call to end template recursion.
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0x28(%rdi), %rax
movq 0x30(%rdi), %r8
movq %rax, %r9
andq %r8, %r9
je 0x5cc2
movq 0x38(%rdi), %rcx
orq %rcx, %r8
bsfq %r9, %r9
leaq 0xbee5(%rip), %r10      # 0x117c0
movq (%r10,%r9,8), %r13
movq %r8, %r10
notq %r10
andq %r13, %r10
je 0x5910
movl (%rdx), %r11d
bsfq %r10, %rbx
shll $0x6, %ebx
orl %r9d, %ebx
movslq %r11d, %r11
movl %ebx, (%rsi,%r11,4)
movl (%rdx), %r11d
incl %r11d
movl %r11d, (%rdx)
leaq -0x1(%r10), %rbx
andq %rbx, %r10
jne 0x58ed
leal (,%r9,8), %r12d
leaq 0xb8a1(%rip), %rbx      # 0x111c0
movq (%rdi), %r11
movq 0x8(%rdi), %r10
movq (%rbx,%r12), %rbx
movq %r11, -0x30(%rbp)
andq %r11, %rbx
leaq 0xbc88(%rip), %r11      # 0x115c0
movq (%r11,%r12), %r14
movq %r10, -0x38(%rbp)
andq %r10, %r14
orq %rbx, %r14
leaq 0x6b53(%rip), %r10      # 0xc4a0
movq (%r10,%r12), %rbx
andq %r8, %rbx
leaq 0x6945(%rip), %r10      # 0xc2a0
imulq (%r10,%r12), %rbx
movl %r9d, %r15d
shll $0xc, %r15d
addq 0xb642(%rip), %r15      # 0x10fb0
shrq $0x37, %rbx
movq (%r15,%rbx,8), %r15
movq 0x10(%rdi), %r11
movq %r11, %rbx
andq %r15, %rbx
orq %r14, %rbx
leaq 0x6616(%rip), %r10      # 0xbfa0
movq (%r10,%r12), %r14
andq %r8, %r14
leaq 0x6408(%rip), %r10      # 0xbda0
imulq (%r10,%r12), %r14
shrq $0x34, %r14
shll $0xf, %r9d
addq 0xb5ec(%rip), %r9       # 0x10f98
movq (%r9,%r14,8), %r14
movq 0x18(%rdi), %r10
movq %r10, %r12
andq %r14, %r12
orq %rbx, %r12
orq %r15, %r14
movq 0x20(%rdi), %r9
andq %r9, %r14
andq %rax, %r13
orq %r14, %r13
orq %r12, %r13
testq %rcx, %r13
jne 0x5cb3
movb 0x40(%rdi), %dil
testb $0x1, %dil
sete %bl
testb $0x60, %r8b
setne %r14b
orb %bl, %r14b
jne 0x5b50
leaq 0xb7c4(%rip), %rbx      # 0x111c0
movq 0x28(%rbx), %rbx
andq -0x30(%rbp), %rbx
leaq 0xbbb5(%rip), %r14      # 0x115c0
movq 0x28(%r14), %r13
andq -0x38(%rbp), %r13
leaq 0x6a86(%rip), %r14      # 0xc4a0
movq 0x28(%r14), %r14
andq %r8, %r14
leaq 0x6878(%rip), %r15      # 0xc2a0
imulq 0x28(%r15), %r14
orq %rbx, %r13
shrq $0x37, %r14
leaq 0xbf85(%rip), %r12      # 0x119c0
movq 0x5000(%r12,%r14,8), %rbx
leaq 0x6556(%rip), %r14      # 0xbfa0
movq 0x28(%r14), %r14
andq %r8, %r14
leaq 0x6348(%rip), %r15      # 0xbda0
imulq 0x28(%r15), %r14
shrq $0x34, %r14
leaq 0x4bf58(%rip), %r15     # 0x519c0
movq 0x28000(%r15,%r14,8), %r14
movq %r14, %r15
orq %rbx, %r14
andq %r11, %rbx
orq %r13, %rbx
andq %r10, %r15
orq %rbx, %r15
andq %r9, %r14
leaq 0xbd34(%rip), %rbx      # 0x117c0
movq 0x28(%rbx), %rbx
andq %rax, %rbx
orq %r14, %rbx
orq %r15, %rbx
testq %rcx, %rbx
jne 0x5b50
leaq 0xb717(%rip), %rbx      # 0x111c0
movq 0x30(%rbx), %rbx
andq -0x30(%rbp), %rbx
leaq 0xbb08(%rip), %r14      # 0x115c0
movq 0x30(%r14), %r13
andq -0x38(%rbp), %r13
orq %rbx, %r13
leaq 0x69d6(%rip), %rbx      # 0xc4a0
movq 0x30(%rbx), %rbx
andq %r8, %rbx
leaq 0x67c8(%rip), %r14      # 0xc2a0
imulq 0x30(%r14), %rbx
shrq $0x37, %rbx
leaq 0x64b8(%rip), %r14      # 0xbfa0
movq 0x30(%r14), %r14
andq %r8, %r14
leaq 0x62aa(%rip), %r15      # 0xbda0
imulq 0x30(%r15), %r14
movq 0x6000(%r12,%rbx,8), %rbx
shrq $0x34, %r14
leaq 0x4beb2(%rip), %r15     # 0x519c0
movq 0x30000(%r15,%r14,8), %r14
movq %r14, %r15
orq %rbx, %r14
andq %r11, %rbx
orq %r13, %rbx
andq %r10, %r15
orq %rbx, %r15
andq %r9, %r14
leaq 0xbc8e(%rip), %rbx      # 0x117c0
movq 0x30(%rbx), %rbx
andq %rax, %rbx
orq %r14, %rbx
orq %r15, %rbx
testq %rcx, %rbx
jne 0x5b50
movslq (%rdx), %rbx
movl $0x1184, (%rsi,%rbx,4)  # imm = 0x1184
incl (%rdx)
testb $0x2, %dil
sete %dil
testb $0xe, %r8b
setne %bl
orb %dil, %bl
jne 0x5cb3
leaq 0xb651(%rip), %rdi      # 0x111c0
movq 0x18(%rdi), %rbx
andq -0x30(%rbp), %rbx
leaq 0xba42(%rip), %rdi      # 0x115c0
movq 0x18(%rdi), %rdi
andq -0x38(%rbp), %rdi
leaq 0x6913(%rip), %r14      # 0xc4a0
movq 0x18(%r14), %r14
andq %r8, %r14
leaq 0x6705(%rip), %r15      # 0xc2a0
imulq 0x18(%r15), %r14
orq %rbx, %rdi
shrq $0x37, %r14
leaq 0xbe12(%rip), %r12      # 0x119c0
movq 0x3000(%r12,%r14,8), %rbx
leaq 0x63e3(%rip), %r14      # 0xbfa0
movq 0x18(%r14), %r14
andq %r8, %r14
leaq 0x61d5(%rip), %r15      # 0xbda0
imulq 0x18(%r15), %r14
shrq $0x34, %r14
leaq 0x4bde5(%rip), %r13     # 0x519c0
movq 0x18000(%r13,%r14,8), %r14
movq %r14, %r15
orq %rbx, %r14
andq %r11, %rbx
orq %rdi, %rbx
andq %r10, %r15
orq %rbx, %r15
andq %r9, %r14
leaq 0xbbc1(%rip), %rdi      # 0x117c0
movq 0x18(%rdi), %rdi
andq %rax, %rdi
orq %r14, %rdi
orq %r15, %rdi
testq %rcx, %rdi
jne 0x5cb3
movq -0x30(%rbp), %r14
leaq 0xb5a0(%rip), %rdi      # 0x111c0
andq 0x10(%rdi), %r14
movq -0x38(%rbp), %rbx
leaq 0xb991(%rip), %rdi      # 0x115c0
andq 0x10(%rdi), %rbx
leaq 0x6866(%rip), %rdi      # 0xc4a0
movq 0x10(%rdi), %rdi
andq %r8, %rdi
leaq 0x6658(%rip), %r15      # 0xc2a0
imulq 0x10(%r15), %rdi
orq %r14, %rbx
leaq 0x6349(%rip), %r14      # 0xbfa0
andq 0x10(%r14), %r8
shrq $0x37, %rdi
movq 0x2000(%r12,%rdi,8), %rdi
leaq 0x6132(%rip), %r14      # 0xbda0
imulq 0x10(%r14), %r8
andq %rdi, %r11
orq %rbx, %r11
shrq $0x34, %r8
movq 0x10000(%r13,%r8,8), %r8
andq %r8, %r10
orq %r11, %r10
orq %rdi, %r8
leaq 0xbb2b(%rip), %rdi      # 0x117c0
andq 0x10(%rdi), %rax
andq %r9, %r8
orq %r8, %rax
orq %r10, %rax
testq %rcx, %rax
jne 0x5cb3
movslq (%rdx), %rax
movl $0x1084, (%rsi,%rax,4)  # imm = 0x1084
incl (%rdx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5f87(%rip), %rdi      # 0xbc50
leaq 0x5f83(%rip), %rsi      # 0xbc53
leaq 0x5f8b(%rip), %rcx      # 0xbc62
movl $0x3e, %edx
callq 0x3100