// File: /workspace/github_cpp_makefile_star2_O2/ATOMIC-LICHESS[P]ATOMKRAFT/position.cpp
// Function: Position::do_capture_move(unsigned long&, PieceType, Color, Square, Square, bool)
NEW // parameter: Square from
void Position::do_capture_move(Key& key, PieceType capture, Color them, Square to, Square from, bool ep) {

	STARTNEW
#ifndef NDEBUG
	if (capture == KING || type_of_piece_on(from) == KING) {
		cout << "them: " << them << endl;
		cout << "to: " << to << endl;
		cout << "from: " << from << endl;
		cout << "ep: " << ep << endl;
		cout << "capture: " << capture << endl;
		print_debuginfo(*this);
	}
#endif
	ENDNEW

	
	NEW // captures performed by the king are not allowed
	NEW assert(type_of_piece_on(from) != KING);
    assert(capture != KING);

    Square capsq = to;
    
    STARTNEW
    /*
     * gather information about all exploded pieces and stores them in st->expl
     * additionally remove the pieces from relevant lists and bitboards
     * we don't remove the central capture, this is done in the original code
     */ 
    int explCount = 0;
   
    // gather information about the first obligatory capture
    // the actual capture is done later
    Square explSquare = explSq[to].square[0];
    Piece explPiece = board[explSquare];
    Color explColor;
    PieceType explPieceType;
	st->expl.piece[0] = explPiece;
	st->expl.square[0] = explSquare;
	++explCount;
	
	// now capture the other pieces
    for (int k = 1; k < explSq[to].size; ++k) {
    	explSquare = explSq[to].square[k];
    	explPiece = board[explSquare];
    	
    	// skip if we are about to remove the attacking piece
    	if (explSquare == from) continue;
    	
    	if (explPiece != PIECE_NONE && explPiece != WP && explPiece != BP) {
    		// gather information
    		st->expl.piece[explCount] = explPiece;
    		st->expl.square[explCount] = explSquare;
    		explColor = color_of_piece(explPiece);
    		explPieceType = type_of_piece(explPiece);
    		++explCount;
    		
    		// do the capture
    		remove_piece(key, explColor, explSquare, explPieceType);
    		
    	}
    }
    st->expl.size = explCount;
    ENDNEW

    // If the captured piece was a pawn, update pawn hash key,
    // otherwise update non-pawn material.
    if (capture == PAWN)
    {
        if (ep) // en passant ?
        {
            capsq = (them == BLACK)? (to - DELTA_N) : (to - DELTA_S);

            assert(to == st->epSquare);
            assert(relative_rank(opposite_color(them), to) == RANK_6);
            assert(piece_on(to) == PIECE_NONE);
            assert(piece_on(capsq) == make_piece(them, PAWN));

            board[capsq] = PIECE_NONE;
        }
        st->pawnKey ^= zobrist[them][PAWN][capsq];
    } else {
        st->npMaterial[them] -= PieceValueMidgame[capture];
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, %r13d
movq %rcx, 0x8(%rsp)
movl %edx, 0x4(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %rbx
movq %r8, 0x20(%rsp)
movslq %r8d, %rax
movq %rax, 0x10(%rsp)
imulq $0x4c, %rax, %rax
leaq 0x1b7b6(%rip), %rcx     # 0x35490
leaq (%rcx,%rax), %rbp
movslq (%rcx,%rax), %rax
movl (%rdi,%rax,4), %ecx
movq 0x1938(%rdi), %rdx
movl %ecx, 0x6c(%rdx)
movl %eax, 0x48(%rdx)
pushq $0x1
popq %r15
pushq $0x1
popq %r12
movl $0x10202, %r14d         # imm = 0x10202
movslq 0x48(%rbp), %rax
cmpq %rax, %r12
jge 0x19d55
movslq (%rbp,%r12,4), %rcx
cmpl %r13d, %ecx
je 0x19d50
movl (%rbx,%rcx,4), %r8d
cmpl $0x10, %r8d
ja 0x19d23
btl %r8d, %r14d
jb 0x19d50
movq 0x1938(%rbx), %rax
movslq %r15d, %rdx
movl %r8d, 0x6c(%rax,%rdx,4)
movl %ecx, 0x48(%rax,%rdx,4)
movl %r8d, %edx
sarl $0x3, %edx
andl $0x7, %r8d
incl %r15d
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
callq 0x19ece
incq %r12
jmp 0x19d00
movq 0x1938(%rbx), %rax
movl %r15d, 0x90(%rax)
movl 0x4(%rsp), %r9d
cmpl $0x1, %r9d
jne 0x19dc4
cmpb $0x0, 0x60(%rsp)
movq 0x10(%rsp), %r10
movq 0x8(%rsp), %r8
je 0x19da0
xorl %ecx, %ecx
cmpl $0x1, %r8d
setne %cl
shll $0x4, %ecx
movq 0x20(%rsp), %rdx
addl %edx, %ecx
addl $-0x8, %ecx
movslq %ecx, %r10
movl $0x10, (%rbx,%r10,4)
movl %r8d, %edx
movq %rdx, %rcx
shlq $0xc, %rcx
leaq 0x3971df(%rip), %rsi    # 0x3b0f90
addq %rcx, %rsi
movq 0x200(%rsi,%r10,8), %rcx
xorq %rcx, (%rax)
pushq $0x1
popq %rcx
jmp 0x19de2
movl %r9d, %ecx
leaq 0x39a452(%rip), %rdx    # 0x3b4220
movl (%rdx,%rcx,4), %esi
movq 0x8(%rsp), %r8
movl %r8d, %edx
subl %esi, 0x28(%rax,%rdx,4)
movq 0x10(%rsp), %r10
leaq 0xf75c7(%rip), %rsi     # 0x1113b0
movq (%rsi,%r10,8), %rdi
andq %rdi, 0x140(%rbx,%rdx,8)
movq (%rsi,%r10,8), %rdi
andq %rdi, 0x100(%rbx,%rcx,8)
movq (%rsi,%r10,8), %rsi
andq %rsi, 0x100(%rbx)
movq %rdx, %rsi
shlq $0xc, %rsi
leaq 0x397176(%rip), %rdi    # 0x3b0f90
addq %rsi, %rdi
movq %rcx, %rsi
shlq $0x9, %rsi
addq %rdi, %rsi
movq (%rsi,%r10,8), %rdi
movq 0x18(%rsp), %r11
xorq %rdi, (%r11)
shll $0x3, %r8d
orl %r9d, %r8d
shlq $0x8, %r8
leaq 0x3993db(%rip), %rdi    # 0x3b3220
addq %r8, %rdi
movl (%rdi,%r10,4), %edi
subl %edi, 0x24(%rax)
movq %rdx, %rdi
shlq $0x5, %rdi
addq %rbx, %rdi
movslq 0x150(%rdi,%rcx,4), %r8
leaq -0x1(%r8), %r9
movl %r9d, 0x150(%rdi,%rcx,4)
movq -0x8(%rsi,%r8,8), %rsi
xorq %rsi, 0x8(%rax)
shlq $0x9, %rdx
addq %rbx, %rdx
movq %rcx, %rsi
shlq $0x6, %rsi
addq %rdx, %rsi
movslq 0x18c(%rsi,%r8,4), %rdx
movslq 0x590(%rbx,%r10,4), %r8
movl %r8d, 0x590(%rbx,%rdx,4)
movl %edx, 0x190(%rsi,%r8,4)
movslq 0x150(%rdi,%rcx,4), %rcx
movl $0x40, 0x190(%rsi,%rcx,4)
andl $0x0, 0x14(%rax)
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop