// File: codeandkey[P]neocortex/src/position.cpp
// Function: neocortex::Position::see_capture(neocortex::Move)
int Position::see_capture(Move cap) {
	assert(!(bb::mask(cap.dst()) & board.get_piece_occ(piece::KING)));

	bool ep = false;
	int csq = cap.dst();

	if (piece::type(board.get_piece(cap.src())) == piece::PAWN && bb::mask(cap.dst()) == en_passant_mask()) {
		ep = true;
		csq = cap.dst() + ((color_to_move == piece::WHITE) ? SOUTH : NORTH);
	}

	int capped = piece::null;

	/* Make capture */
	if (ep) {
		capped = board.remove(csq);
		board.place(cap.dst(), board.remove(cap.src()));
	} else {
		capped = board.replace(cap.dst(), board.remove(cap.src()));
	}

	int ret = eval::MATERIAL_MG[piece::type(capped)] - see(cap.dst(), !color_to_move);

	/* Undo capture */
	if (ep) {
		board.place(csq, capped);
		board.place(cap.src(), board.remove(cap.dst()));
	}
	else {
		board.place(cap.src(), board.replace(cap.dst(), capped));
	}

	return ret;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rsi, -0x1c(%rbp)
movl %edx, -0x14(%rbp)
movq -0x1c(%rbp), %rax
movq %rax, -0xc(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x4(%rbp)
movq %rdi, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0xc(%rbp), %rdi
callq 0x14dd0
movl %eax, %edi
callq 0x6bd0
movq -0x48(%rbp), %rdi
movq %rax, -0x40(%rbp)
movl $0x5, %esi
callq 0x14e50
movq %rax, %rcx
movq -0x40(%rbp), %rax
andq %rcx, %rax
cmpq $0x0, %rax
setne %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x11964
jmp 0x11966
jmp 0x11985
leaq 0x160f8(%rip), %rdi     # 0x27a65
leaq 0x15e51(%rip), %rsi     # 0x277c5
movl $0x463, %edx            # imm = 0x463
leaq 0x1611f(%rip), %rcx     # 0x27a9f
callq 0x5290
movb $0x0, -0x29(%rbp)
leaq -0xc(%rbp), %rdi
callq 0x14dd0
movl %eax, -0x30(%rbp)
leaq -0xc(%rbp), %rdi
callq 0x14df0
movq -0x48(%rbp), %rdi
movl %eax, %esi
callq 0x14db0
movl %eax, %edi
callq 0x8d20
cmpl $0x0, %eax
jne 0x11a0a
leaq -0xc(%rbp), %rdi
callq 0x14dd0
movl %eax, %edi
callq 0x6bd0
movq -0x48(%rbp), %rdi
movq %rax, -0x50(%rbp)
callq 0xe000
movq %rax, %rcx
movq -0x50(%rbp), %rax
cmpq %rcx, %rax
jne 0x11a0a
movb $0x1, -0x29(%rbp)
leaq -0xc(%rbp), %rdi
callq 0x14dd0
movq -0x48(%rbp), %rcx
movl 0x170(%rcx), %esi
movl $0x8, %ecx
movl $0xfffffff8, %edx       # imm = 0xFFFFFFF8
cmpl $0x0, %esi
cmovel %edx, %ecx
addl %ecx, %eax
movl %eax, -0x30(%rbp)
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
testb $0x1, -0x29(%rbp)
je 0x11a56
movq -0x48(%rbp), %rdi
movl -0x30(%rbp), %esi
callq 0x7da0
movl %eax, -0x34(%rbp)
leaq -0xc(%rbp), %rdi
callq 0x14dd0
movl %eax, -0x54(%rbp)
leaq -0xc(%rbp), %rdi
callq 0x14df0
movq -0x48(%rbp), %rdi
movl %eax, %esi
callq 0x7da0
movq -0x48(%rbp), %rdi
movl -0x54(%rbp), %esi
movl %eax, %edx
callq 0x7b80
jmp 0x11a87
leaq -0xc(%rbp), %rdi
callq 0x14dd0
movl %eax, -0x58(%rbp)
leaq -0xc(%rbp), %rdi
callq 0x14df0
movq -0x48(%rbp), %rdi
movl %eax, %esi
callq 0x7da0
movq -0x48(%rbp), %rdi
movl -0x58(%rbp), %esi
movl %eax, %edx
callq 0x7f10
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %edi
callq 0x8d20
movslq %eax, %rcx
leaq 0x14df7(%rip), %rax     # 0x26890
movl (%rax,%rcx,4), %eax
movl %eax, -0x5c(%rbp)
leaq -0xc(%rbp), %rdi
callq 0x14dd0
movq -0x48(%rbp), %rdi
movl %eax, %esi
cmpl $0x0, 0x170(%rdi)
setne %al
xorb $-0x1, %al
andb $0x1, %al
movzbl %al, %edx
callq 0x12070
movl %eax, %ecx
movl -0x5c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x38(%rbp)
testb $0x1, -0x29(%rbp)
je 0x11b13
movq -0x48(%rbp), %rdi
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
callq 0x7b80
leaq -0xc(%rbp), %rdi
callq 0x14df0
movl %eax, -0x60(%rbp)
leaq -0xc(%rbp), %rdi
callq 0x14dd0
movq -0x48(%rbp), %rdi
movl %eax, %esi
callq 0x7da0
movq -0x48(%rbp), %rdi
movl -0x60(%rbp), %esi
movl %eax, %edx
callq 0x7b80
jmp 0x11b44
leaq -0xc(%rbp), %rdi
callq 0x14df0
movl %eax, -0x64(%rbp)
leaq -0xc(%rbp), %rdi
callq 0x14dd0
movq -0x48(%rbp), %rdi
movl %eax, %esi
movl -0x34(%rbp), %edx
callq 0x7f10
movq -0x48(%rbp), %rdi
movl -0x64(%rbp), %esi
movl %eax, %edx
callq 0x7b80
movl -0x38(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)