// File: /workspace/github_cpp_makefile_star2_O3/jswaff[P]prophet3/src/pos.cpp
// Function: remove_piece(position*, square_t)
piece_t remove_piece(position* p,square_t sq) {
    assert(p != 0);
    assert(sq >= A8 && sq <= H1);
    assert(p->piece[sq] != NO_PIECE);

    int piece = p->piece[sq];
    uint64 bb_sq = bb_squares[sq];
    if (piece > NO_PIECE) {
        p->white_pieces ^= bb_sq;
        if (piece==PAWN) {
            p->white_pawns ^= bb_sq;
            p->pawn_key ^= zkeys.pieces[PAWN][WHITE][sq];
        } else if (piece==KNIGHT) {
            p->white_knights ^= bb_sq;
        } else if (piece==BISHOP) {
            p->white_bishops ^= bb_sq;
        } else if (piece==ROOK) {
            p->white_rooks ^= bb_sq;
        } else if (piece==QUEEN) {
            p->white_queens ^= bb_sq;
        }
        p->piece_counts[WHITE][piece]--;
        assert(p->piece_counts[WHITE][piece] >= 0);
        p->hash_key ^= zkeys.pieces[piece][WHITE][sq];
    } else {
        p->black_pieces ^= bb_sq;
        if (piece==-PAWN) {
            p->black_pawns ^= bb_sq;
            p->pawn_key ^= zkeys.pieces[PAWN][BLACK][sq];
        } else if (piece==-KNIGHT) {
            p->black_knights ^= bb_sq;
        } else if (piece==-BISHOP) {
            p->black_bishops ^= bb_sq;
        } else if (piece==-ROOK) {
            p->black_rooks ^= bb_sq;
        } else if (piece==-QUEEN) {
            p->black_queens ^= bb_sq;
        }
        p->piece_counts[BLACK][-piece]--;
        assert(p->piece_counts[BLACK][-piece] >= 0);
        p->hash_key ^= zkeys.pieces[-piece][BLACK][sq];
    }

    p->piece[sq] = NO_PIECE;
    return (piece_t)piece;
}

// Assembly:
pushq %rax
testq %rdi, %rdi
je 0xa8c4
cmpl $0x40, %esi
jae 0xa8e3
movl %esi, %ecx
movl (%rdi,%rcx,4), %eax
testq %rax, %rax
je 0xa902
leaq 0xefcfb(%rip), %rdx     # 0xfa4b0
movq (%rdx,%rcx,8), %rdx
testl %eax, %eax
jle 0xa7f9
xorq %rdx, 0x1a8(%rdi)
leal -0x1(%rax), %esi
cmpl $0x4, %esi
ja 0xa841
leaq 0x20f29(%rip), %r8      # 0x2b6fc
movslq (%r8,%rsi,4), %rsi
addq %r8, %rsi
jmpq *%rsi
xorq %rdx, 0x158(%rdi)
leaq 0xeddae(%rip), %rdx     # 0xf8598
movq 0x600(%rdx,%rcx,8), %rdx
movl $0x1c0, %esi            # imm = 0x1C0
jmp 0xa83d
xorq %rdx, 0x1b0(%rdi)
leal 0x5(%rax), %esi
cmpl $0x4, %esi
ja 0xa897
leaq 0x20ed5(%rip), %r8      # 0x2b6e8
movslq (%r8,%rsi,4), %rsi
addq %r8, %rsi
jmpq *%rsi
movl $0x1a0, %esi            # imm = 0x1A0
jmp 0xa893
movl $0x198, %esi            # imm = 0x198
jmp 0xa83d
movl $0x178, %esi            # imm = 0x178
jmp 0xa83d
movl $0x188, %esi            # imm = 0x188
jmp 0xa83d
movl $0x168, %esi            # imm = 0x168
xorq %rdx, (%rdi,%rsi)
decl 0x11c(%rdi,%rax,4)
movq %rax, %rdx
shlq $0xa, %rdx
addq 0x37742(%rip), %rdx     # 0x41f98
leaq (%rdx,%rcx,8), %rdx
addq $0x200, %rdx            # imm = 0x200
jmp 0xa8b1
xorq %rdx, 0x160(%rdi)
leaq 0xedd27(%rip), %rdx     # 0xf8598
movq 0x400(%rdx,%rcx,8), %rdx
movl $0x1c0, %esi            # imm = 0x1C0
jmp 0xa893
movl $0x180, %esi            # imm = 0x180
jmp 0xa893
movl $0x170, %esi            # imm = 0x170
jmp 0xa893
movl $0x190, %esi            # imm = 0x190
xorq %rdx, (%rdi,%rsi)
movl %eax, %edx
negl %edx
decl 0x100(%rdi,%rdx,4)
shlq $0xa, %rdx
addq 0x376eb(%rip), %rdx     # 0x41f98
leaq (%rdx,%rcx,8), %rdx
movq (%rdx), %rdx
xorq %rdx, 0x1b8(%rdi)
movl $0x0, (%rdi,%rcx,4)
popq %rcx
retq
leaq 0x21484(%rip), %rdi     # 0x2bd4f
leaq 0x20fbf(%rip), %rsi     # 0x2b891
leaq 0x2147d(%rip), %rcx     # 0x2bd56
movl $0x7b, %edx
callq 0x20d0
leaq 0x1e924(%rip), %rdi     # 0x2920e
leaq 0x20fa0(%rip), %rsi     # 0x2b891
leaq 0x2145e(%rip), %rcx     # 0x2bd56
movl $0x7c, %edx
callq 0x20d0
leaq 0x21478(%rip), %rdi     # 0x2bd81
leaq 0x20f81(%rip), %rsi     # 0x2b891
leaq 0x2143f(%rip), %rcx     # 0x2bd56
movl $0x7d, %edx
callq 0x20d0