// File: /workspace/github_cpp_makefile_star2_O1/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 $0x18, %rsp
movq %rcx, 0x10(%rsp)
movl %edx, 0x4(%rsp)
movq %rdi, %rbx
movq %r8, 0x8(%rsp)
movslq %r8d, %rax
imulq $0x4c, %rax, %rax
leaq 0x1c7b5(%rip), %rbp     # 0x3c490
movslq (%rbp,%rax), %rcx
movl (%rdi,%rcx,4), %edx
movq 0x1938(%rdi), %rdi
movl %edx, 0x6c(%rdi)
movl %ecx, 0x48(%rdi)
movl $0x1, %r15d
cmpl $0x2, 0x48(%rbp,%rax)
jl 0x1fd6e
movl %r9d, %r13d
addq %rax, %rbp
movl $0x1, %r15d
movl $0x1, %r12d
movl $0x10202, %edx          # imm = 0x10202
movslq (%rbp,%r12,4), %rcx
cmpl %r13d, %ecx
je 0x1fd62
movl (%rbx,%rcx,4), %r8d
cmpl $0x10, %r8d
ja 0x1fd2e
btl %r8d, %edx
jb 0x1fd62
movq 0x1938(%rbx), %rax
movslq %r15d, %r15
movl %r8d, 0x6c(%rax,%r15,4)
movl %ecx, 0x48(%rax,%r15,4)
movl %r8d, %edx
sarl $0x3, %edx
andl $0x7, %r8d
incl %r15d
movq %rbx, %rdi
movq %rsi, %r14
callq 0x1fedc
movl $0x10202, %edx          # imm = 0x10202
movq %r14, %rsi
incq %r12
movslq 0x48(%rbp), %rax
cmpq %rax, %r12
jl 0x1fd14
movq 0x1938(%rbx), %rax
movl %r15d, 0x90(%rax)
movq 0x10(%rsp), %r14
movl %r14d, %edx
movl 0x4(%rsp), %r9d
movl %r9d, %ecx
cmpl $0x1, %r9d
jne 0x1fddd
cmpb $0x0, 0x50(%rsp)
movq 0x8(%rsp), %r11
je 0x1fdbc
xorl %edi, %edi
cmpl $0x1, %r14d
setne %dil
shll $0x4, %edi
addl %edi, %r11d
addl $-0x8, %r11d
movslq %r11d, %rdi
movl $0x10, (%rbx,%rdi,4)
movslq %r11d, %r10
movq %rdx, %rdi
shlq $0xc, %rdi
leaq 0x3981c3(%rip), %r8     # 0x3b7f90
addq %rdi, %r8
movq 0x200(%r8,%r10,8), %rdi
xorq %rdi, (%rax)
jmp 0x1fdf0
leaq 0x39b43c(%rip), %rdi    # 0x3bb220
movl (%rdi,%rcx,4), %edi
subl %edi, 0x28(%rax,%rdx,4)
movq 0x8(%rsp), %r11
movslq %r11d, %r11
leaq 0xf85b6(%rip), %rdi     # 0x1183b0
movq (%rdi,%r11,8), %r8
andq %r8, 0x140(%rbx,%rdx,8)
movq (%rdi,%r11,8), %r8
andq %r8, 0x100(%rbx,%rcx,8)
movq (%rdi,%r11,8), %rdi
andq %rdi, 0x100(%rbx)
movq %rdx, %rdi
shlq $0xc, %rdi
leaq 0x398165(%rip), %r8     # 0x3b7f90
addq %rdi, %r8
movq %rcx, %rdi
shlq $0x9, %rdi
addq %r8, %rdi
movq (%rdi,%r11,8), %r8
xorq %r8, (%rsi)
shll $0x3, %r14d
orl %r9d, %r14d
shlq $0x8, %r14
leaq 0x39a3cf(%rip), %r8     # 0x3ba220
addq %r14, %r8
movl (%r8,%r11,4), %r8d
subl %r8d, 0x24(%rax)
movq %rdx, %r8
shlq $0x5, %r8
addq %rbx, %r8
movslq 0x150(%r8,%rcx,4), %r9
leaq -0x1(%r9), %r10
movl %r10d, 0x150(%r8,%rcx,4)
movq -0x8(%rdi,%r9,8), %rdi
xorq %rdi, 0x8(%rax)
shlq $0x9, %rdx
addq %rbx, %rdx
movq %rcx, %rdi
shlq $0x6, %rdi
addq %rdx, %rdi
movslq 0x18c(%rdi,%r9,4), %rdx
movslq 0x590(%rbx,%r11,4), %rsi
movl %esi, 0x590(%rbx,%rdx,4)
movl %edx, 0x190(%rdi,%rsi,4)
movslq 0x150(%r8,%rcx,4), %rcx
movl $0x40, 0x190(%rdi,%rcx,4)
movl $0x0, 0x14(%rax)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop