// File: /workspace/github_cpp_makefile_star2_O2/codeandkey[P]neocortex/src/position.cpp
// Function: neocortex::Position::pseudolegal_moves_quiescence_captures(neocortex::Move*)
int Position::pseudolegal_moves_quiescence_captures(Move* out) {
	if (check()) {
		return pseudolegal_moves_evasions(out);
	}

	int count = 0;

	bitboard ctm = board.get_color_occ(color_to_move);
	bitboard opp = board.get_color_occ(!color_to_move);

	bitboard ep_mask = 0;
	int ep_square = ply.back().en_passant_square;

	if (square::is_valid(ep_square)) {
		ep_mask = bb::mask(ep_square);
	}

	/* Pawn moves */
	bitboard pawns = ctm & board.get_piece_occ(piece::PAWN);
	bitboard promoting_rank = (color_to_move == piece::WHITE) ? RANK_7 : RANK_2;

	int adv_dir = (color_to_move == piece::WHITE) ? NORTH : SOUTH;
	int left_dir = (color_to_move == piece::WHITE) ? NORTHWEST : SOUTHWEST;
	int right_dir = (color_to_move == piece::WHITE) ? NORTHEAST : SOUTHEAST;

	bitboard promoting_pawns = pawns & promoting_rank;

	/* Promoting left captures */
	bitboard promoting_left_cap = bb::shift(promoting_pawns & ~FILE_A, left_dir) & opp;

	while (promoting_left_cap) {
		int dst = bb::poplsb(promoting_left_cap);
		out[count++] = Move(dst - left_dir, dst, piece::QUEEN);
		out[count++] = Move(dst - left_dir, dst, piece::KNIGHT);
	}

	/* Promoting right captures */
	bitboard promoting_right_cap = bb::shift(promoting_pawns & ~FILE_H, right_dir) & opp;

	while (promoting_right_cap) {
		int dst = bb::poplsb(promoting_right_cap);
		out[count++] = Move(dst - right_dir, dst, piece::QUEEN);
		out[count++] = Move(dst - right_dir, dst, piece::KNIGHT);
	}

	/* Promoting advances */
	bitboard promoting_advances = bb::shift(promoting_pawns, adv_dir) & ~board.get_global_occ();

	while (promoting_advances) {
		int dst = bb::poplsb(promoting_advances);
		out[count++] = Move(dst - adv_dir, dst, piece::QUEEN);
		out[count++] = Move(dst - adv_dir, dst, piece::KNIGHT);
	}

	/* Nonpromoting pawn moves */
	bitboard npm_pawns = pawns & ~promoting_pawns;

	/* Left captures */
	bitboard npm_left_cap = bb::shift(npm_pawns & ~FILE_A, left_dir) & (opp | ep_mask);

	while (npm_left_cap) {
		int dst = bb::poplsb(npm_left_cap);
		out[count++] = Move(dst - left_dir, dst);
	}

	/* Right captures */
	bitboard npm_right_cap = bb::shift(npm_pawns & ~FILE_H, right_dir) & (opp | ep_mask);

	while (npm_right_cap) {
		int dst = bb::poplsb(npm_right_cap);
		out[count++] = Move(dst - right_dir, dst);
	}

	/* Queen captures  */
	bitboard queens = ctm & board.get_piece_occ(piece::QUEEN);

	while (queens) {
		int src = bb::poplsb(queens);
		bitboard moves = attacks::queen(src, board.get_global_occ()) & opp;

		while (moves) {
			int dst = bb::poplsb(moves);
			out[count++] = Move(src, dst);
		}
	}

	/* Rook captures */
	bitboard rooks = ctm & board.get_piece_occ(piece::ROOK);

	while (rooks) {
		int src = bb::poplsb(rooks);
		bitboard moves = attacks::rook(src, board.get_global_occ()) & opp;

		while (moves) {
			int dst = bb::poplsb(moves);
			out[count++] = Move(src, dst);
		}
	}

	/* Knight captures */
	bitboard knights = ctm & board.get_piece_occ(piece::KNIGHT);

	while (knights) {
		int src = bb::poplsb(knights);
		bitboard moves = attacks::knight(src) & opp;

		while (moves) {
			int dst = bb::poplsb(moves);
			out[count++] = Move(src, dst);
		}
	}

	/* Bishop captures */
	bitboard bishops = ctm & board.get_piece_occ(piece::BISHOP);

	while (bishops) {
		int src = bb::poplsb(bishops);
		bitboard moves = attacks::bishop(src, board.get_global_occ()) & opp;

		while (moves) {
			int dst = bb::poplsb(moves);
			out[count++] = Move(src, dst);
		}
	}

	/* King captures */
	bitboard kings = ctm & board.get_piece_occ(piece::KING);

	while (kings) {
		int src = bb::poplsb(kings);
		bitboard moves = attacks::king(src) & opp;

		while (moves) {
			int dst = bb::poplsb(moves);
			out[count++] = Move(src, dst);
		}
	}

	assert(count <= MAX_PL_MOVES);
	return count;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rsi, %r12
movq %rdi, %rbx
movq 0x160(%rdi), %rax
cmpl $0x0, -0x14(%rax)
je 0xa786
movq %rbx, %rdi
movq %r12, %rsi
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x94d0
movslq 0x170(%rbx), %rsi
xorl %ecx, %ecx
testq %rsi, %rsi
sete %cl
movq 0x8(%rbx,%rsi,8), %rdx
movq %rdx, 0x20(%rsp)
movq 0x8(%rbx,%rcx,8), %rcx
movq %rcx, 0x18(%rsp)
movl -0x2c(%rax), %edi
cmpl $0x3f, %edi
ja 0xa7c3
callq 0x5103
movq %rax, 0x70(%rsp)
movl 0x170(%rbx), %esi
jmp 0xa7cc
movq $0x0, 0x70(%rsp)
movq %rbx, 0x10(%rsp)
movq 0x18(%rbx), %rdi
andq 0x20(%rsp), %rdi
xorl %ecx, %ecx
testl %esi, %esi
sete %cl
movabsq $0xff000000000000, %rax # imm = 0xFF000000000000
movl $0xff00, %edx           # imm = 0xFF00
cmoveq %rax, %rdx
shll $0x4, %ecx
addl $-0x9, %ecx
movq %rdi, 0x98(%rsp)
andq %rdi, %rdx
movabsq $0xfe00000000fe00, %rax # imm = 0xFE00000000FE00
movq %rdx, 0x28(%rsp)
andq %rdx, %rax
movq %rax, %rdx
movq %rcx, 0x68(%rsp)
shlq %cl, %rdx
shrq $0x9, %rax
movq %rsi, 0x58(%rsp)
testl %esi, %esi
cmoveq %rdx, %rax
andq 0x18(%rsp), %rax
leaq 0x90(%rsp), %rcx
movq %rax, (%rcx)
xorl %r14d, %r14d
leaq 0x4(%rsp), %r13
pushq $0x2
popq %rbx
movq %r12, 0x30(%rsp)
testq %rax, %rax
je 0xa8c3
leaq 0x90(%rsp), %rdi
callq 0x64fc
movl %eax, %ebp
movl %eax, %r15d
subl 0x68(%rsp), %r15d
movq %r13, %rdi
movl %r15d, %esi
movl %eax, %edx
pushq $0x4
popq %rcx
callq 0x6d4e
movl 0xc(%rsp), %eax
movl %eax, 0x8(%r12)
movq 0x4(%rsp), %rax
movq %rax, (%r12)
movq %r13, %rdi
movl %r15d, %esi
movl %ebp, %edx
movl %ebx, %ecx
callq 0x6d4e
addq $0x2, %r14
movl 0xc(%rsp), %eax
movl %eax, 0x14(%r12)
movq 0x4(%rsp), %rax
movq %rax, 0xc(%r12)
movq 0x90(%rsp), %rax
addq $0x18, %r12
jmp 0xa851
xorl %ecx, %ecx
movq 0x58(%rsp), %rsi
testl %esi, %esi
sete %cl
shll $0x4, %ecx
addl $-0x7, %ecx
movabsq $0x7f000000007f00, %rax # imm = 0x7F000000007F00
andq 0x28(%rsp), %rax
movq %rax, %rdx
movq %rcx, 0x60(%rsp)
shlq %cl, %rdx
shrq $0x7, %rax
testl %esi, %esi
cmoveq %rdx, %rax
andq 0x18(%rsp), %rax
leaq 0xb0(%rsp), %rbp
movq %rax, (%rbp)
leaq 0x4(%rsp), %r13
testq %rax, %rax
je 0xa97b
movq %rbp, %rdi
callq 0x64fc
movl %eax, %r15d
movl %eax, %ebx
subl 0x60(%rsp), %ebx
movq %r13, %rdi
movl %ebx, %esi
movl %eax, %edx
pushq $0x4
popq %rcx
callq 0x6d4e
movl 0xc(%rsp), %eax
movl %eax, 0x8(%r12)
movq 0x4(%rsp), %rax
movq %rax, (%r12)
movq %r13, %rdi
movl %ebx, %esi
movl %r15d, %edx
pushq $0x2
popq %rcx
callq 0x6d4e
addq $0x2, %r14
movl 0xc(%rsp), %eax
movl %eax, 0x14(%r12)
movq 0x4(%rsp), %rax
movq %rax, 0xc(%r12)
movq 0xb0(%rsp), %rax
addq $0x18, %r12
jmp 0xa90f
xorl %ebp, %ebp
movq 0x58(%rsp), %rdx
testl %edx, %edx
sete %bpl
shll $0x4, %ebp
addl $-0x8, %ebp
movq 0x28(%rsp), %rsi
movq %rsi, %rax
movl %ebp, %ecx
shlq %cl, %rax
movq %rsi, %rcx
shrq $0x8, %rcx
testl %edx, %edx
cmoveq %rax, %rcx
movq 0x10(%rsp), %rax
movq (%rax), %rax
notq %rax
andq %rcx, %rax
leaq 0x88(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x4(%rsp), %rbx
testq %rax, %rax
je 0xaa39
leaq 0x88(%rsp), %rdi
callq 0x64fc
movl %eax, %r15d
movl %eax, %r13d
subl %ebp, %r13d
movq %rbx, %rdi
movl %r13d, %esi
movl %eax, %edx
pushq $0x4
popq %rcx
callq 0x6d4e
movl 0xc(%rsp), %eax
movl %eax, 0x8(%r12)
movq 0x4(%rsp), %rax
movq %rax, (%r12)
movq %rbx, %rdi
movl %r13d, %esi
movl %r15d, %edx
pushq $0x2
popq %rcx
callq 0x6d4e
addq $0x2, %r14
movl 0xc(%rsp), %eax
movl %eax, 0x14(%r12)
movq 0x4(%rsp), %rax
movq %rax, 0xc(%r12)
movq 0x88(%rsp), %rax
addq $0x18, %r12
jmp 0xa9c6
movq 0x28(%rsp), %rcx
xorq 0x98(%rsp), %rcx
movabsq $-0x101010101010102, %rax # imm = 0xFEFEFEFEFEFEFEFE
movq %rcx, 0x28(%rsp)
andq %rcx, %rax
movq %rax, %rdx
movq 0x68(%rsp), %rcx
shlq %cl, %rdx
shrq $0x9, %rax
cmpl $0x0, 0x58(%rsp)
cmoveq %rdx, %rax
movq 0x70(%rsp), %r13
orq 0x18(%rsp), %r13
andq %r13, %rax
leaq 0xa8(%rsp), %rbx
movq %rax, (%rbx)
leaq 0x4(%rsp), %r15
pushq $-0x1
popq %rbp
testq %rax, %rax
je 0xaad2
movq %rbx, %rdi
callq 0x64fc
movl %eax, %esi
subl 0x68(%rsp), %esi
movq %r15, %rdi
movl %eax, %edx
movl %ebp, %ecx
callq 0x6d4e
incq %r14
movl 0xc(%rsp), %eax
movl %eax, 0x8(%r12)
movq 0x4(%rsp), %rax
movq %rax, (%r12)
movq 0xa8(%rsp), %rax
addq $0xc, %r12
jmp 0xaa90
movabsq $0x7f7f7f7f7f7f7f7f, %rax # imm = 0x7F7F7F7F7F7F7F7F
movq 0x28(%rsp), %rdx
andq %rax, %rdx
movq %rdx, %rax
movq 0x60(%rsp), %rcx
shlq %cl, %rax
shrq $0x7, %rdx
cmpl $0x0, 0x58(%rsp)
cmoveq %rax, %rdx
andq %r13, %rdx
leaq 0xa0(%rsp), %rbx
movq %rdx, (%rbx)
leaq 0x4(%rsp), %r15
pushq $-0x1
popq %rbp
testq %rdx, %rdx
je 0xab54
movq %rbx, %rdi
callq 0x64fc
movl %eax, %esi
subl 0x60(%rsp), %esi
movq %r15, %rdi
movl %eax, %edx
movl %ebp, %ecx
callq 0x6d4e
incq %r14
movl 0xc(%rsp), %eax
movl %eax, 0x8(%r12)
movq 0x4(%rsp), %rax
movq %rax, (%r12)
movq 0xa0(%rsp), %rdx
addq $0xc, %r12
jmp 0xab12
movq 0x10(%rsp), %rax
movq 0x38(%rax), %rax
andq 0x20(%rsp), %rax
leaq 0x80(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x50(%rsp), %r13
leaq 0x4(%rsp), %rbp
pushq $-0x1
popq %r15
testq %rax, %rax
je 0xabfa
leaq 0x80(%rsp), %rdi
callq 0x64fc
movl %eax, %r12d
movq 0x10(%rsp), %rax
movq (%rax), %rsi
movl %r12d, %edi
callq 0xcf4b
andq 0x18(%rsp), %rax
movq %rax, 0x50(%rsp)
movslq %r14d, %r14
imulq $0xc, %r14, %rbx
addq 0x30(%rsp), %rbx
testq %rax, %rax
je 0xabf0
movq %r13, %rdi
callq 0x64fc
movq %rbp, %rdi
movl %r12d, %esi
movl %eax, %edx
movl %r15d, %ecx
callq 0x6d4e
incq %r14
movl 0xc(%rsp), %eax
movl %eax, 0x8(%rbx)
movq 0x4(%rsp), %rax
movq %rax, (%rbx)
movq 0x50(%rsp), %rax
addq $0xc, %rbx
jmp 0xabb6
movq 0x80(%rsp), %rax
jmp 0xab7b
movq 0x10(%rsp), %rax
movq 0x30(%rax), %rax
andq 0x20(%rsp), %rax
leaq 0x50(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x48(%rsp), %r13
leaq 0x4(%rsp), %rbp
pushq $-0x1
popq %r15
testq %rax, %rax
je 0xac97
leaq 0x50(%rsp), %rdi
callq 0x64fc
movl %eax, %r12d
movq 0x10(%rsp), %rax
movq (%rax), %rsi
movl %r12d, %edi
callq 0x649e
andq 0x18(%rsp), %rax
movq %rax, 0x48(%rsp)
movslq %r14d, %r14
imulq $0xc, %r14, %rbx
addq 0x30(%rsp), %rbx
testq %rax, %rax
je 0xac90
movq %r13, %rdi
callq 0x64fc
movq %rbp, %rdi
movl %r12d, %esi
movl %eax, %edx
movl %r15d, %ecx
callq 0x6d4e
incq %r14
movl 0xc(%rsp), %eax
movl %eax, 0x8(%rbx)
movq 0x4(%rsp), %rax
movq %rax, (%rbx)
movq 0x48(%rsp), %rax
addq $0xc, %rbx
jmp 0xac56
movq 0x50(%rsp), %rax
jmp 0xac1e
movq 0x10(%rsp), %rax
movq 0x28(%rax), %rax
andq 0x20(%rsp), %rax
leaq 0x48(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x40(%rsp), %r12
leaq 0x4(%rsp), %r13
pushq $-0x1
popq %rbp
testq %rax, %rax
je 0xad2e
leaq 0x48(%rsp), %rdi
callq 0x64fc
movl %eax, %ebx
cltq
leaq 0x12aec(%rip), %rcx     # 0x1d7c0
movq (%rcx,%rax,8), %rax
andq 0x18(%rsp), %rax
movq %rax, 0x40(%rsp)
movslq %r14d, %r14
imulq $0xc, %r14, %r15
addq 0x30(%rsp), %r15
testq %rax, %rax
je 0xad27
movq %r12, %rdi
callq 0x64fc
movq %r13, %rdi
movl %ebx, %esi
movl %eax, %edx
movl %ebp, %ecx
callq 0x6d4e
incq %r14
movl 0xc(%rsp), %eax
movl %eax, 0x8(%r15)
movq 0x4(%rsp), %rax
movq %rax, (%r15)
movq 0x40(%rsp), %rax
addq $0xc, %r15
jmp 0xacee
movq 0x48(%rsp), %rax
jmp 0xacba
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
andq 0x20(%rsp), %rax
leaq 0x40(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x38(%rsp), %r13
leaq 0x4(%rsp), %rbp
pushq $-0x1
popq %r15
testq %rax, %rax
je 0xadcb
leaq 0x40(%rsp), %rdi
callq 0x64fc
movl %eax, %r12d
movq 0x10(%rsp), %rax
movq (%rax), %rsi
movl %r12d, %edi
callq 0x6440
andq 0x18(%rsp), %rax
movq %rax, 0x38(%rsp)
movslq %r14d, %r14
imulq $0xc, %r14, %rbx
addq 0x30(%rsp), %rbx
testq %rax, %rax
je 0xadc4
movq %r13, %rdi
callq 0x64fc
movq %rbp, %rdi
movl %r12d, %esi
movl %eax, %edx
movl %r15d, %ecx
callq 0x6d4e
incq %r14
movl 0xc(%rsp), %eax
movl %eax, 0x8(%rbx)
movq 0x4(%rsp), %rax
movq %rax, (%rbx)
movq 0x38(%rsp), %rax
addq $0xc, %rbx
jmp 0xad8a
movq 0x40(%rsp), %rax
jmp 0xad52
movq 0x20(%rsp), %rax
movq 0x10(%rsp), %rcx
andq 0x40(%rcx), %rax
leaq 0x38(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x78(%rsp), %r12
leaq 0x4(%rsp), %r13
pushq $-0x1
popq %rbp
testq %rax, %rax
je 0xae62
leaq 0x38(%rsp), %rdi
callq 0x64fc
movl %eax, %ebx
cltq
leaq 0x127b8(%rip), %rcx     # 0x1d5c0
movq (%rcx,%rax,8), %rax
andq 0x18(%rsp), %rax
movq %rax, 0x78(%rsp)
movslq %r14d, %r14
imulq $0xc, %r14, %r15
addq 0x30(%rsp), %r15
testq %rax, %rax
je 0xae5b
movq %r12, %rdi
callq 0x64fc
movq %r13, %rdi
movl %ebx, %esi
movl %eax, %edx
movl %ebp, %ecx
callq 0x6d4e
incq %r14
movl 0xc(%rsp), %eax
movl %eax, 0x8(%r15)
movq 0x4(%rsp), %rax
movq %rax, (%r15)
movq 0x78(%rsp), %rax
addq $0xc, %r15
jmp 0xae22
movq 0x38(%rsp), %rax
jmp 0xadee
cmpl $0x65, %r14d
jge 0xae7d
movl %r14d, %eax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa01f(%rip), %rdi      # 0x14ea3
leaq 0x9e8a(%rip), %rsi      # 0x14d15
leaq 0xa0dc(%rip), %rcx      # 0x14f6e
movl $0x3fa, %edx            # imm = 0x3FA
callq 0x41f0