// File: /workspace/github_cpp_makefile_star2_O1/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
pushq %rax
movq 0x28(%rdi), %rax
movq 0x30(%rdi), %r8
movq %rax, %rcx
andq %r8, %rcx
je 0x600b
orq 0x38(%rdi), %r8
bsfq %rcx, %r15
leaq 0xbbab(%rip), %rcx      # 0x117c0
movq %r8, %r9
notq %r9
andq (%rcx,%r15,8), %r9
je 0x5c3e
bsfq %r9, %r10
shll $0x6, %r10d
orl %r15d, %r10d
movslq (%rdx), %r11
movl %r10d, (%rsi,%r11,4)
incl (%rdx)
leaq -0x1(%r9), %r10
andq %r10, %r9
jne 0x5c21
leal (,%r15,8), %r13d
leaq 0xb573(%rip), %rcx      # 0x111c0
movq (%rdi), %r10
movq 0x8(%rdi), %r9
movq (%rcx,%r13), %r11
andq %r10, %r11
leaq 0xb95e(%rip), %rcx      # 0x115c0
movq (%rcx,%r13), %rbx
andq %r9, %rbx
orq %r11, %rbx
leaq 0x682d(%rip), %rcx      # 0xc4a0
movq (%rcx,%r13), %r11
andq %r8, %r11
leaq 0x661f(%rip), %rcx      # 0xc2a0
imulq (%rcx,%r13), %r11
shrq $0x37, %r11
movl %r15d, %r14d
shll $0xc, %r14d
addq 0xb318(%rip), %r14      # 0x10fb0
movq (%r14,%r11,8), %r12
movq 0x10(%rdi), %r14
movq %r14, %r11
andq %r12, %r11
orq %rbx, %r11
leaq 0x62f0(%rip), %rcx      # 0xbfa0
movq (%rcx,%r13), %rbx
andq %r8, %rbx
leaq 0x60e2(%rip), %rcx      # 0xbda0
imulq (%rcx,%r13), %rbx
shrq $0x34, %rbx
shll $0xf, %r15d
addq 0xb2c6(%rip), %r15      # 0x10f98
movq (%r15,%rbx,8), %rbx
movq 0x18(%rdi), %rcx
movq %rcx, %r15
andq %rbx, %r15
orq %r11, %r15
orq %r12, %rbx
movq 0x20(%rdi), %r12
andq %r12, %rbx
leaq 0xbacc(%rip), %r11      # 0x117c0
movq (%r11,%r13), %r11
andq %rax, %r11
orq %rbx, %r11
orq %r15, %r11
movq 0x38(%rdi), %r13
testq %r13, %r11
jne 0x5ffc
movb 0x40(%rdi), %r15b
testb $0x1, %r15b
sete %r11b
testb $0x60, %r8b
setne %bl
orb %r11b, %bl
jne 0x5e94
leaq 0xb48f(%rip), %rdi      # 0x111c0
movq 0x28(%rdi), %r11
andq %r10, %r11
leaq 0xb881(%rip), %rdi      # 0x115c0
movq 0x28(%rdi), %rbx
andq %r9, %rbx
leaq 0x6753(%rip), %rdi      # 0xc4a0
movb %r15b, -0x29(%rbp)
movq 0x28(%rdi), %r15
andq %r8, %r15
leaq 0x6541(%rip), %rdi      # 0xc2a0
imulq 0x28(%rdi), %r15
orq %r11, %rbx
shrq $0x37, %r15
leaq 0xcfde(%rip), %rdi      # 0x12d50
movq 0x5000(%rdi,%r15,8), %r11
leaq 0x621f(%rip), %rdi      # 0xbfa0
movq 0x28(%rdi), %r15
andq %r8, %r15
leaq 0x6011(%rip), %rdi      # 0xbda0
imulq 0x28(%rdi), %r15
shrq $0x34, %r15
leaq 0x4cfb1(%rip), %rdi     # 0x52d50
movq 0x28000(%rdi,%r15,8), %r15
movq %r15, %rdi
orq %r11, %r15
andq %r14, %r11
orq %rbx, %r11
andq %rcx, %rdi
orq %r11, %rdi
andq %r12, %r15
leaq 0xb9fd(%rip), %r11      # 0x117c0
movq 0x28(%r11), %r11
andq %rax, %r11
orq %r15, %r11
movb -0x29(%rbp), %r15b
orq %rdi, %r11
testq %r13, %r11
jne 0x5e94
leaq 0xb3dc(%rip), %rdi      # 0x111c0
movq 0x30(%rdi), %rdi
andq %r10, %rdi
leaq 0xb7ce(%rip), %r11      # 0x115c0
movq 0x30(%r11), %rbx
andq %r9, %rbx
orq %rdi, %rbx
leaq 0x669d(%rip), %rdi      # 0xc4a0
movq 0x30(%rdi), %rdi
andq %r8, %rdi
leaq 0x648f(%rip), %r11      # 0xc2a0
imulq 0x30(%r11), %rdi
shrq $0x37, %rdi
leaq 0x617f(%rip), %r11      # 0xbfa0
movq 0x30(%r11), %r11
andq %r8, %r11
leaq 0x5f71(%rip), %r15      # 0xbda0
imulq 0x30(%r15), %r11
leaq 0xcf15(%rip), %r15      # 0x12d50
movq 0x6000(%r15,%rdi,8), %rdi
shrq $0x34, %r11
leaq 0x4cf02(%rip), %r15     # 0x52d50
movq 0x30000(%r15,%r11,8), %r11
movq %r11, %r15
orq %rdi, %r11
andq %r14, %rdi
orq %rbx, %rdi
andq %rcx, %r15
orq %rdi, %r15
andq %r12, %r11
leaq 0xb94e(%rip), %rdi      # 0x117c0
movq 0x30(%rdi), %rdi
andq %rax, %rdi
orq %r11, %rdi
orq %r15, %rdi
movb -0x29(%rbp), %r15b
testq %r13, %rdi
jne 0x5e94
movslq (%rdx), %rdi
movl $0x1184, (%rsi,%rdi,4)  # imm = 0x1184
incl (%rdx)
testb $0x2, %r15b
sete %dil
testb $0xe, %r8b
setne %r11b
orb %dil, %r11b
jne 0x5ffc
leaq 0xb30c(%rip), %rdi      # 0x111c0
movq 0x18(%rdi), %rdi
andq %r10, %rdi
leaq 0xb6fe(%rip), %r11      # 0x115c0
movq 0x18(%r11), %rbx
andq %r9, %rbx
leaq 0x65d0(%rip), %r11      # 0xc4a0
movq 0x18(%r11), %r11
andq %r8, %r11
leaq 0x63c2(%rip), %r15      # 0xc2a0
imulq 0x18(%r15), %r11
orq %rdi, %rbx
shrq $0x37, %r11
leaq 0xce5f(%rip), %rdi      # 0x12d50
movq 0x3000(%rdi,%r11,8), %r11
leaq 0x60a0(%rip), %rdi      # 0xbfa0
movq 0x18(%rdi), %r15
andq %r8, %r15
leaq 0x5e92(%rip), %rdi      # 0xbda0
imulq 0x18(%rdi), %r15
shrq $0x34, %r15
leaq 0x4ce32(%rip), %rdi     # 0x52d50
movq 0x18000(%rdi,%r15,8), %r15
movq %r15, %rdi
orq %r11, %r15
andq %r14, %r11
orq %rbx, %r11
andq %rcx, %rdi
orq %r11, %rdi
andq %r12, %r15
leaq 0xb87e(%rip), %r11      # 0x117c0
movq 0x18(%r11), %r11
andq %rax, %r11
orq %r15, %r11
orq %rdi, %r11
testq %r13, %r11
jne 0x5ffc
leaq 0xb261(%rip), %rdi      # 0x111c0
andq 0x10(%rdi), %r10
leaq 0xb656(%rip), %rdi      # 0x115c0
andq 0x10(%rdi), %r9
leaq 0x652b(%rip), %rdi      # 0xc4a0
movq 0x10(%rdi), %rdi
andq %r8, %rdi
leaq 0x631d(%rip), %r11      # 0xc2a0
imulq 0x10(%r11), %rdi
orq %r10, %r9
leaq 0x600e(%rip), %r10      # 0xbfa0
andq 0x10(%r10), %r8
shrq $0x37, %rdi
leaq 0xcdaf(%rip), %r10      # 0x12d50
movq 0x2000(%r10,%rdi,8), %rdi
leaq 0x5df0(%rip), %r10      # 0xbda0
imulq 0x10(%r10), %r8
andq %rdi, %r14
orq %r9, %r14
shrq $0x34, %r8
leaq 0x4cd8a(%rip), %r9      # 0x52d50
movq 0x10000(%r9,%r8,8), %r8
andq %r8, %rcx
orq %r14, %rcx
orq %rdi, %r8
leaq 0xb7e2(%rip), %rdi      # 0x117c0
andq 0x10(%rdi), %rax
andq %r12, %r8
orq %r8, %rax
orq %rcx, %rax
testq %r13, %rax
jne 0x5ffc
movslq (%rdx), %rax
movl $0x1084, (%rsi,%rax,4)  # imm = 0x1084
incl (%rdx)
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5c3e(%rip), %rdi      # 0xbc50
leaq 0x5c3a(%rip), %rsi      # 0xbc53
leaq 0x5c42(%rip), %rcx      # 0xbc62
movl $0x3e, %edx
callq 0x3100