// File: SethKasmann[P]clever-girl/src/state.h
// Function: State::removePiece(Color, PieceType, Square)
inline void State::removePiece(Color pColor, PieceType pPiece, Square pSquare)
{
    Square swap;
    int pieceCount;

    mPieces[pColor][pPiece] &= ~(square_bb[pSquare]);
    mOccupancy[pColor] &= ~(square_bb[pSquare]);
    mBoard[pSquare] = none;

    pieceCount = --mPieceCount[pColor][pPiece];

    swap = mPieceList[pColor][pPiece][pieceCount];
    mPieceIndex[swap] = mPieceIndex[pSquare];
    mPieceList[pColor][pPiece][mPieceIndex[swap]] = swap;
    mPieceList[pColor][pPiece][pieceCount] = no_sq;

    mPstScore[pColor][middle] -= PieceSquareTable::getScore(pPiece, middle, pColor, pSquare);
    mPstScore[pColor][late] -= PieceSquareTable::getScore(pPiece, late, pColor, pSquare);

    mKey ^= Zobrist::key(pColor, pPiece, pSquare);
}

// Assembly:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movl %esi, 0x4c(%rsp)
movl %edx, 0x48(%rsp)
movl %ecx, 0x44(%rsp)
movq 0x50(%rsp), %rdi
movq %rdi, 0x30(%rsp)
movl 0x44(%rsp), %eax
movl %eax, %ecx
leaq 0x119ee4(%rip), %rax    # 0x154b10
movq (%rax,%rcx,8), %rax
xorq $-0x1, %rax
movq %rax, (%rsp)
addq $0x288, %rdi            # imm = 0x288
movl 0x4c(%rsp), %eax
movl %eax, %esi
callq 0x24c10
movq %rax, %rdi
movl 0x48(%rsp), %eax
movl %eax, %esi
callq 0x24c40
movq (%rsp), %rcx
movq 0x30(%rsp), %rdi
andq (%rax), %rcx
movq %rcx, (%rax)
movl 0x44(%rsp), %eax
movl %eax, %ecx
leaq 0x119e9c(%rip), %rax    # 0x154b10
movq (%rax,%rcx,8), %rax
xorq $-0x1, %rax
movq %rax, 0x8(%rsp)
addq $0x78, %rdi
movl 0x4c(%rsp), %eax
movl %eax, %esi
callq 0x24c70
movq 0x8(%rsp), %rcx
movq 0x30(%rsp), %rdi
andq (%rax), %rcx
movq %rcx, (%rax)
addq $0x188, %rdi            # imm = 0x188
movl 0x44(%rsp), %eax
movl %eax, %esi
callq 0x3b530
movq 0x30(%rsp), %rdi
movl $0x6, (%rax)
addq $0x2e8, %rdi            # imm = 0x2E8
movl 0x4c(%rsp), %eax
movl %eax, %esi
callq 0x3b560
movq %rax, %rdi
movl 0x48(%rsp), %eax
movl %eax, %esi
callq 0x3b590
movq 0x30(%rsp), %rdi
movq %rax, %rcx
movl (%rcx), %eax
addl $-0x1, %eax
movl %eax, (%rcx)
movl %eax, 0x3c(%rsp)
addq $0x328, %rdi            # imm = 0x328
movl 0x4c(%rsp), %eax
movl %eax, %esi
callq 0x3b5c0
movq %rax, %rdi
movl 0x48(%rsp), %eax
movl %eax, %esi
callq 0x3b5f0
movq %rax, %rdi
movslq 0x3c(%rsp), %rsi
callq 0x3b620
movq 0x30(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x40(%rsp)
addq $0x88, %rdi
movl 0x44(%rsp), %eax
movl %eax, %esi
callq 0x35f20
movq 0x30(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x14(%rsp)
addq $0x88, %rdi
movl 0x40(%rsp), %eax
movl %eax, %esi
callq 0x35f20
movl 0x14(%rsp), %ecx
movq 0x30(%rsp), %rdi
movl %ecx, (%rax)
movl 0x40(%rsp), %eax
movl %eax, 0x24(%rsp)
addq $0x328, %rdi            # imm = 0x328
movl 0x4c(%rsp), %eax
movl %eax, %esi
callq 0x3b5c0
movq %rax, %rdi
movl 0x48(%rsp), %eax
movl %eax, %esi
callq 0x3b5f0
movq 0x30(%rsp), %rdi
movq %rax, 0x18(%rsp)
addq $0x88, %rdi
movl 0x40(%rsp), %eax
movl %eax, %esi
callq 0x35f20
movq 0x18(%rsp), %rdi
movslq (%rax), %rsi
callq 0x3b620
movl 0x24(%rsp), %ecx
movq 0x30(%rsp), %rdi
movl %ecx, (%rax)
addq $0x328, %rdi            # imm = 0x328
movl 0x4c(%rsp), %eax
movl %eax, %esi
callq 0x3b5c0
movq %rax, %rdi
movl 0x48(%rsp), %eax
movl %eax, %esi
callq 0x3b5f0
movq %rax, %rdi
movslq 0x3c(%rsp), %rsi
callq 0x3b620
movl $0x40, (%rax)
movl 0x48(%rsp), %edi
movl 0x4c(%rsp), %edx
movl 0x44(%rsp), %ecx
xorl %esi, %esi
callq 0x3b650
movq 0x30(%rsp), %rdi
movl %eax, 0x28(%rsp)
addq $0x318, %rdi            # imm = 0x318
movl 0x4c(%rsp), %eax
movl %eax, %esi
callq 0x3b6a0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x24cb0
movl 0x28(%rsp), %edx
movl (%rax), %ecx
subl %edx, %ecx
movl %ecx, (%rax)
movl 0x48(%rsp), %edi
movl 0x4c(%rsp), %edx
movl 0x44(%rsp), %ecx
movl $0x1, %esi
callq 0x3b650
movq 0x30(%rsp), %rdi
movl %eax, 0x2c(%rsp)
addq $0x318, %rdi            # imm = 0x318
movl 0x4c(%rsp), %eax
movl %eax, %esi
callq 0x3b6a0
movq %rax, %rdi
movl $0x1, %esi
callq 0x24cb0
movl 0x2c(%rsp), %edx
movl (%rax), %ecx
subl %edx, %ecx
movl %ecx, (%rax)
movl 0x4c(%rsp), %edi
movl 0x48(%rsp), %esi
movl 0x44(%rsp), %edx
callq 0x39a70
movq %rax, %rcx
movq 0x30(%rsp), %rax
xorq 0x18(%rax), %rcx
movq %rcx, 0x18(%rax)
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)