// File: /workspace/github_cpp_makefile_star2_O3/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 0xa730
cmpl $0x40, %edx
jae 0xa74f
movl %edx, %eax
cmpl $0x0, (%rdi,%rax,4)
jne 0xa76e
movl %esi, (%rdi,%rax,4)
leaq 0xefe90(%rip), %rcx     # 0xfa4b0
movq (%rcx,%rax,8), %rcx
testl %esi, %esi
jle 0xa666
orq %rcx, 0x1a8(%rdi)
leal -0x1(%rsi), %edx
cmpl $0x4, %edx
ja 0xa6b4
leaq 0x21096(%rip), %r8      # 0x2b6d4
movslq (%r8,%rdx,4), %rdx
addq %r8, %rdx
jmpq *%rdx
orq %rcx, 0x158(%rdi)
leaq 0xedf43(%rip), %rcx     # 0xf8598
movq 0x600(%rcx,%rax,8), %rcx
xorq %rcx, 0x1c0(%rdi)
jmp 0xa6b4
orq %rcx, 0x1b0(%rdi)
leal 0x5(%rsi), %edx
cmpl $0x4, %edx
ja 0xa70c
leaq 0x21040(%rip), %r8      # 0x2b6c0
movslq (%r8,%rdx,4), %rdx
addq %r8, %rdx
jmpq *%rdx
orq %rcx, 0x1a0(%rdi)
jmp 0xa70c
orq %rcx, 0x198(%rdi)
jmp 0xa6b4
orq %rcx, 0x178(%rdi)
jmp 0xa6b4
orq %rcx, 0x188(%rdi)
jmp 0xa6b4
orq %rcx, 0x168(%rdi)
movl %esi, %ecx
incl 0x11c(%rdi,%rcx,4)
shlq $0xa, %rcx
addq 0x378d0(%rip), %rcx     # 0x41f98
leaq (%rcx,%rax,8), %rax
addq $0x200, %rax            # imm = 0x200
jmp 0xa724
orq %rcx, 0x160(%rdi)
leaq 0xedeb6(%rip), %rcx     # 0xf8598
movq 0x400(%rcx,%rax,8), %rcx
xorq %rcx, 0x1c0(%rdi)
jmp 0xa70c
orq %rcx, 0x180(%rdi)
jmp 0xa70c
orq %rcx, 0x170(%rdi)
jmp 0xa70c
orq %rcx, 0x190(%rdi)
negl %esi
incl 0x100(%rdi,%rsi,4)
shlq $0xa, %rsi
addq 0x37878(%rip), %rsi     # 0x41f98
leaq (%rsi,%rax,8), %rax
movq (%rax), %rax
xorq %rax, 0x1b8(%rdi)
popq %rax
retq
leaq 0x202ba(%rip), %rdi     # 0x2a9f1
leaq 0x21153(%rip), %rsi     # 0x2b891
leaq 0x215b4(%rip), %rcx     # 0x2bcf9
movl $0x51, %edx
callq 0x20d0
leaq 0x215cf(%rip), %rdi     # 0x2bd25
leaq 0x21134(%rip), %rsi     # 0x2b891
leaq 0x21595(%rip), %rcx     # 0x2bcf9
movl $0x52, %edx
callq 0x20d0
leaq 0x215c3(%rip), %rdi     # 0x2bd38
leaq 0x21115(%rip), %rsi     # 0x2b891
leaq 0x21576(%rip), %rcx     # 0x2bcf9
movl $0x53, %edx
callq 0x20d0