// File: 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:
subq $0x58, %rsp
movb 0x60(%rsp), %al
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movl %edx, 0x44(%rsp)
movl %ecx, 0x40(%rsp)
movl %r8d, 0x3c(%rsp)
movl %r9d, 0x38(%rsp)
andb $0x1, %al
movb %al, 0x37(%rsp)
movq 0x50(%rsp), %rax
movq %rax, 0x8(%rsp)
movl 0x3c(%rsp), %ecx
movl %ecx, 0x30(%rsp)
movl $0x0, 0x2c(%rsp)
movslq 0x3c(%rsp), %rdx
leaq 0x30720(%rip), %rcx     # 0x6c5a0
imulq $0x4c, %rdx, %rdx
addq %rdx, %rcx
movl (%rcx), %ecx
movl %ecx, 0x28(%rsp)
movslq 0x28(%rsp), %rcx
movl (%rax,%rcx,4), %ecx
movl %ecx, 0x24(%rsp)
movl 0x24(%rsp), %edx
movq 0x1938(%rax), %rcx
movl %edx, 0x6c(%rcx)
movl 0x28(%rsp), %ecx
movq 0x1938(%rax), %rax
movl %ecx, 0x48(%rax)
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
movl $0x1, 0x18(%rsp)
movl 0x18(%rsp), %eax
movslq 0x3c(%rsp), %rdx
leaq 0x306c8(%rip), %rcx     # 0x6c5a0
imulq $0x4c, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x48(%rcx), %eax
jge 0x3bfbc
movq 0x8(%rsp), %rax
movslq 0x3c(%rsp), %rdx
leaq 0x306a7(%rip), %rcx     # 0x6c5a0
imulq $0x4c, %rdx, %rdx
addq %rdx, %rcx
movslq 0x18(%rsp), %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, 0x28(%rsp)
movslq 0x28(%rsp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, 0x24(%rsp)
movl 0x28(%rsp), %eax
cmpl 0x38(%rsp), %eax
jne 0x3bf27
jmp 0x3bfac
cmpl $0x10, 0x24(%rsp)
je 0x3bfaa
cmpl $0x1, 0x24(%rsp)
je 0x3bfaa
cmpl $0x9, 0x24(%rsp)
je 0x3bfaa
movq 0x8(%rsp), %rax
movl 0x24(%rsp), %esi
movq 0x1938(%rax), %rcx
movslq 0x2c(%rsp), %rdx
movl %esi, 0x6c(%rcx,%rdx,4)
movl 0x28(%rsp), %edx
movq 0x1938(%rax), %rax
movslq 0x2c(%rsp), %rcx
movl %edx, 0x48(%rax,%rcx,4)
movl 0x24(%rsp), %edi
callq 0x3e730
movl %eax, 0x20(%rsp)
movl 0x24(%rsp), %edi
callq 0x12990
movq 0x8(%rsp), %rdi
movl %eax, 0x1c(%rsp)
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
movq 0x48(%rsp), %rsi
movl 0x20(%rsp), %edx
movl 0x28(%rsp), %ecx
movl 0x1c(%rsp), %r8d
callq 0x3c2a0
jmp 0x3bfac
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x3bec8
movq 0x8(%rsp), %rax
movl 0x2c(%rsp), %ecx
movq 0x1938(%rax), %rax
movl %ecx, 0x90(%rax)
cmpl $0x1, 0x44(%rsp)
jne 0x3c05f
testb $0x1, 0x37(%rsp)
je 0x3c02a
cmpl $0x1, 0x40(%rsp)
jne 0x3bfff
movl 0x3c(%rsp), %edi
movl $0x8, %esi
callq 0xe9c0
movl %eax, 0x4(%rsp)
jmp 0x3c011
movl 0x3c(%rsp), %edi
movl $0xfffffff8, %esi       # imm = 0xFFFFFFF8
callq 0xe9c0
movl %eax, 0x4(%rsp)
movq 0x8(%rsp), %rax
movl 0x4(%rsp), %ecx
movl %ecx, 0x30(%rsp)
movslq 0x30(%rsp), %rcx
movl $0x10, (%rax,%rcx,4)
movq 0x8(%rsp), %rax
movl 0x40(%rsp), %ecx
movl %ecx, %edx
leaq 0x3ac104(%rip), %rcx    # 0x3e8140
shlq $0xc, %rdx
addq %rdx, %rcx
movslq 0x30(%rsp), %rdx
movq 0x200(%rcx,%rdx,8), %rcx
movq 0x1938(%rax), %rax
xorq (%rax), %rcx
movq %rcx, (%rax)
jmp 0x3c08f
movq 0x8(%rsp), %rax
movl 0x44(%rsp), %ecx
movl %ecx, %edx
leaq 0x3af35f(%rip), %rcx    # 0x3eb3d0
movl (%rcx,%rdx,4), %esi
movq 0x1938(%rax), %rdi
addq $0x28, %rdi
movl 0x40(%rsp), %eax
shlq $0x2, %rax
addq %rax, %rdi
callq 0x29e80
movq 0x8(%rsp), %rdi
addq $0x140, %rdi            # imm = 0x140
movl 0x40(%rsp), %eax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x30(%rsp), %esi
callq 0x29eb0
movq 0x8(%rsp), %rdi
addq $0x100, %rdi            # imm = 0x100
movl 0x44(%rsp), %eax
shlq $0x3, %rax
addq %rax, %rdi
movl 0x30(%rsp), %esi
callq 0x29eb0
movq 0x8(%rsp), %rdi
addq $0x100, %rdi            # imm = 0x100
movl 0x30(%rsp), %esi
callq 0x29eb0
movl 0x40(%rsp), %eax
movl %eax, %ecx
leaq 0x3ac04f(%rip), %rax    # 0x3e8140
shlq $0xc, %rcx
addq %rcx, %rax
movl 0x44(%rsp), %ecx
shlq $0x9, %rcx
addq %rcx, %rax
movslq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %rcx
movq 0x48(%rsp), %rax
xorq (%rax), %rcx
movq %rcx, (%rax)
movl 0x40(%rsp), %edi
movl 0x44(%rsp), %esi
movl 0x30(%rsp), %edx
callq 0x3e770
movl %eax, %esi
movq 0x8(%rsp), %rax
movq 0x1938(%rax), %rdi
addq $0x24, %rdi
callq 0x29ae0
movq 0x8(%rsp), %rax
movq %rax, %rcx
addq $0x150, %rcx            # imm = 0x150
movl 0x40(%rsp), %edx
shlq $0x5, %rdx
addq %rdx, %rcx
movl 0x44(%rsp), %edx
movl (%rcx,%rdx,4), %esi
addl $-0x1, %esi
movl %esi, (%rcx,%rdx,4)
movl 0x40(%rsp), %ecx
movl %ecx, %edx
leaq 0x3abfcd(%rip), %rcx    # 0x3e8140
shlq $0xc, %rdx
addq %rdx, %rcx
movl 0x44(%rsp), %edx
shlq $0x9, %rdx
addq %rdx, %rcx
movq %rax, %rdx
addq $0x150, %rdx            # imm = 0x150
movl 0x40(%rsp), %esi
shlq $0x5, %rsi
addq %rsi, %rdx
movl 0x44(%rsp), %esi
movslq (%rdx,%rsi,4), %rdx
movq (%rcx,%rdx,8), %rdx
movq 0x1938(%rax), %rcx
xorq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rcx)
movq %rax, %rcx
addq $0x190, %rcx            # imm = 0x190
movl 0x40(%rsp), %edx
shlq $0x9, %rdx
addq %rdx, %rcx
movl 0x44(%rsp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
movq %rax, %rdx
addq $0x150, %rdx            # imm = 0x150
movl 0x40(%rsp), %esi
shlq $0x5, %rsi
addq %rsi, %rdx
movl 0x44(%rsp), %esi
movslq (%rdx,%rsi,4), %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, 0x14(%rsp)
movslq 0x30(%rsp), %rcx
movl 0x590(%rax,%rcx,4), %edx
movslq 0x14(%rsp), %rcx
movl %edx, 0x590(%rax,%rcx,4)
movl 0x14(%rsp), %esi
movq %rax, %rcx
addq $0x190, %rcx            # imm = 0x190
movl 0x40(%rsp), %edx
shlq $0x9, %rdx
addq %rdx, %rcx
movl 0x44(%rsp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
movslq 0x14(%rsp), %rdx
movslq 0x590(%rax,%rdx,4), %rdx
movl %esi, (%rcx,%rdx,4)
movq %rax, %rcx
addq $0x190, %rcx            # imm = 0x190
movl 0x40(%rsp), %edx
shlq $0x9, %rdx
addq %rdx, %rcx
movl 0x44(%rsp), %edx
shlq $0x6, %rdx
addq %rdx, %rcx
movq %rax, %rdx
addq $0x150, %rdx            # imm = 0x150
movl 0x40(%rsp), %esi
shlq $0x5, %rsi
addq %rsi, %rdx
movl 0x44(%rsp), %esi
movslq (%rdx,%rsi,4), %rdx
movl $0x40, (%rcx,%rdx,4)
movq 0x1938(%rax), %rax
movl $0x0, 0x14(%rax)
addq $0x58, %rsp
retq
nopl (%rax)