// File: /workspace/github_cpp_makefile_star2_O2/jswaff[P]prophet3/src/pos.cpp
// Function: add_piece(position*, int, square_t)
void add_piece(position* p,int32 piece,square_t sq) {
    assert(piece != NO_PIECE);
    assert(sq >= 0 && sq < 64);
    assert(p->piece[sq]==NO_PIECE);

    p->piece[sq] = piece;
    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]++;
        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]++;
        p->hash_key ^= zkeys.pieces[-piece][BLACK][sq];
    }
}

// Assembly:
pushq %rax
testl %esi, %esi
je 0x9ee8
cmpl $0x40, %edx
jae 0x9f01
movl %edx, %eax
cmpl $0x0, (%rdi,%rax,4)
jne 0x9f1a
movl %esi, (%rdi,%rax,4)
leaq 0xf36d8(%rip), %rcx     # 0xfd4b0
movq (%rcx,%rax,8), %rcx
testl %esi, %esi
jle 0x9e1e
orq %rcx, 0x1a8(%rdi)
leal -0x1(%rsi), %edx
cmpl $0x4, %edx
ja 0x9e6c
leaq 0x1f88e(%rip), %r8      # 0x29684
movslq (%r8,%rdx,4), %rdx
addq %r8, %rdx
jmpq *%rdx
orq %rcx, 0x158(%rdi)
leaq 0xf178b(%rip), %rcx     # 0xfb598
movq 0x600(%rcx,%rax,8), %rcx
xorq %rcx, 0x1c0(%rdi)
jmp 0x9e6c
orq %rcx, 0x1b0(%rdi)
leal 0x5(%rsi), %edx
cmpl $0x4, %edx
ja 0x9ec4
leaq 0x1f838(%rip), %r8      # 0x29670
movslq (%r8,%rdx,4), %rdx
addq %r8, %rdx
jmpq *%rdx
orq %rcx, 0x1a0(%rdi)
jmp 0x9ec4
orq %rcx, 0x198(%rdi)
jmp 0x9e6c
orq %rcx, 0x178(%rdi)
jmp 0x9e6c
orq %rcx, 0x188(%rdi)
jmp 0x9e6c
orq %rcx, 0x168(%rdi)
movl %esi, %ecx
incl 0x11c(%rdi,%rcx,4)
shlq $0xa, %rcx
addq 0x3b118(%rip), %rcx     # 0x44f98
leaq (%rcx,%rax,8), %rax
addq $0x200, %rax            # imm = 0x200
jmp 0x9edc
orq %rcx, 0x160(%rdi)
leaq 0xf16fe(%rip), %rcx     # 0xfb598
movq 0x400(%rcx,%rax,8), %rcx
xorq %rcx, 0x1c0(%rdi)
jmp 0x9ec4
orq %rcx, 0x180(%rdi)
jmp 0x9ec4
orq %rcx, 0x170(%rdi)
jmp 0x9ec4
orq %rcx, 0x190(%rdi)
negl %esi
incl 0x100(%rdi,%rsi,4)
shlq $0xa, %rsi
addq 0x3b0c0(%rip), %rsi     # 0x44f98
leaq (%rsi,%rax,8), %rax
movq (%rax), %rax
xorq %rax, 0x1b8(%rdi)
popq %rax
retq
leaq 0x1eab2(%rip), %rdi     # 0x289a1
leaq 0x1f94b(%rip), %rsi     # 0x29841
leaq 0x1fdac(%rip), %rcx     # 0x29ca9
pushq $0x51
jmp 0x9f31
leaq 0x1fdcd(%rip), %rdi     # 0x29cd5
leaq 0x1f932(%rip), %rsi     # 0x29841
leaq 0x1fd93(%rip), %rcx     # 0x29ca9
pushq $0x52
jmp 0x9f31
leaq 0x1fdc7(%rip), %rdi     # 0x29ce8
leaq 0x1f919(%rip), %rsi     # 0x29841
leaq 0x1fd7a(%rip), %rcx     # 0x29ca9
pushq $0x53
popq %rdx
callq 0x20c0