// File: /workspace/github_cpp_makefile_star2_O1/cpirc[P]Monochrome/src/perft.cpp
// Function: perft_tt(TT*, Position const&, int)
std::uint64_t perft_tt(TT* tt, const Position& pos, const int depth) {
    assert(tt);

    if (depth == 0) {
        return 1;
    }

    TTEntry entry = tt_poll(tt, pos.hash_key);
    if (entry.hash_key == pos.hash_key && tt_depth(entry.data) == depth) {
        return tt_nodes(entry.data);
    }

    uint64_t nodes = 0;
    Move moves[256];
    int movecount = generate(pos, moves);
    for (int i = 0; i < movecount; i++) {
        Position npos = pos;

        make_move(npos, moves[i]);
        if (is_checked(npos, THEM)) continue;

        nodes += perft_tt(tt, npos, depth - 1);
    }

    tt_add_perft(tt, pos.hash_key, depth, nodes);

    return nodes;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x488, %rsp            # imm = 0x488
movq %rdi, -0x38(%rbp)
testq %rdi, %rdi
je 0x6a05
movl %edx, %r14d
testl %edx, %edx
je 0x69aa
movq %rsi, %r15
movq 0x48(%rsi), %rsi
movq -0x38(%rbp), %rdi
callq 0x976d
cmpq 0x48(%r15), %rdx
jne 0x682e
movl %eax, %ecx
andl $0x7f, %ecx
cmpl $0x40, %ecx
jae 0x6a24
cmpl %r14d, %ecx
jne 0x682e
shrq $0x7, %rax
movslq %eax, %rbx
jmp 0x69d1
leaq -0x4b0(%rbp), %rsi
movq %r15, %rdi
callq 0x608e
testl %eax, %eax
movq %r14, -0x48(%rbp)
jle 0x69b1
leaq 0x50(%r15), %rbx
leal -0x1(%r14), %ecx
movl %ecx, -0x3c(%rbp)
movl %eax, %r14d
xorl %r12d, %r12d
leaq -0xb0(%rbp), %r13
movq $0x0, -0x30(%rbp)
movl $0xa, %ecx
movq %r13, %rdi
movq %r15, %rsi
rep  movsq (%rsi), %es:(%rdi)
leaq -0x60(%rbp), %rdi
movq %rbx, %rsi
callq 0x5692
movl -0x4b0(%rbp,%r12,4), %esi
movq %r13, %rdi
callq 0x4ac0
movq -0x88(%rbp), %rax
movq -0x78(%rbp), %rcx
andq %rax, %rcx
je 0x69e6
bsfq %rcx, %rsi
movq -0x80(%rbp), %rcx
movq -0x78(%rbp), %rdi
orq %rcx, %rdi
leal (,%rsi,8), %edx
movq -0xb0(%rbp), %r9
movq -0xa8(%rbp), %r8
leaq 0xa8ee(%rip), %r10      # 0x111c0
andq 0x200(%r10,%rdx), %r9
leaq 0xacdf(%rip), %r10      # 0x115c0
andq (%r10,%rdx), %r8
leaq 0x5bb4(%rip), %r10      # 0xc4a0
movq (%r10,%rdx), %r10
andq %rdi, %r10
leaq 0x59a6(%rip), %r11      # 0xc2a0
imulq (%r11,%rdx), %r10
orq %r9, %r8
shrq $0x37, %r10
movl %esi, %r9d
shll $0xc, %r9d
addq 0xa69c(%rip), %r9       # 0x10fb0
movq (%r9,%r10,8), %r9
movq -0xa0(%rbp), %r10
andq %r9, %r10
leaq 0x5677(%rip), %r11      # 0xbfa0
andq (%r11,%rdx), %rdi
leaq 0x546c(%rip), %r11      # 0xbda0
imulq (%r11,%rdx), %rdi
orq %r8, %r10
shrq $0x34, %rdi
shll $0xf, %esi
addq 0xa64e(%rip), %rsi      # 0x10f98
movq (%rsi,%rdi,8), %rsi
movq -0x98(%rbp), %rdi
andq %rsi, %rdi
orq %r10, %rdi
orq %r9, %rsi
leaq 0xae5b(%rip), %r8       # 0x117c0
andq (%r8,%rdx), %rax
orq %rdi, %rax
andq -0x90(%rbp), %rsi
orq %rsi, %rax
testq %rcx, %rax
jne 0x698e
movq -0x38(%rbp), %rdi
movq %r13, %rsi
movl -0x3c(%rbp), %edx
callq 0x67cd
addq %rax, -0x30(%rbp)
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x699c
callq 0x31a0
incq %r12
cmpq %r12, %r14
jne 0x6869
jmp 0x69b9
movl $0x1, %ebx
jmp 0x69d1
movq $0x0, -0x30(%rbp)
movq 0x48(%r15), %rsi
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rdx
movq -0x30(%rbp), %rbx
movq %rbx, %rcx
callq 0x99ad
movq %rbx, %rax
addq $0x488, %rsp            # imm = 0x488
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x5263(%rip), %rdi      # 0xbc50
leaq 0x525f(%rip), %rsi      # 0xbc53
leaq 0x5267(%rip), %rcx      # 0xbc62
movl $0x3e, %edx
callq 0x3100
leaq 0x60f8(%rip), %rdi      # 0xcb04
leaq 0x60f4(%rip), %rsi      # 0xcb07
leaq 0x60fb(%rip), %rcx      # 0xcb15
movl $0x38, %edx
callq 0x3100
leaq 0x61a1(%rip), %rdi      # 0xcbcc
leaq 0x616f(%rip), %rsi      # 0xcba1
leaq 0x6171(%rip), %rcx      # 0xcbaa
movl $0x64, %edx
callq 0x3100
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x6a54
callq 0x31a0
movq %rbx, %rdi
callq 0x32d0