// File: /workspace/github_cpp_makefile_star2_O3/jswaff[P]prophet3/src/apply.cpp
// Function: add_piece_to_destination(position*, unsigned long long)
void add_piece_to_destination(position* p,move m) {
    square_t from_sq=get_from_sq(m),to_sq=get_to_sq(m);
    int32 piece = p->piece[from_sq];
    add_piece(p,piece,to_sq);
    switch (piece) {
    case PAWN:
        p->fifty_counter=0;
        if (to_sq==north(north(from_sq))) {
            p->ep_sq=north(from_sq);
        } else if (get_rank(to_sq)==RANK_8) {
            assert(get_promopiece(m) != NO_PIECE);
            remove_piece(p,to_sq);
            add_piece(p,get_promopiece(m),to_sq);
        }
        break;
    case -PAWN:
        p->fifty_counter=0;
        if (to_sq==south(south(from_sq))) {
            p->ep_sq=south(from_sq);
        } else if (get_rank(to_sq)==RANK_1) {
            assert(get_promopiece(m) != NO_PIECE);
            remove_piece(p,to_sq);
            add_piece(p,-get_promopiece(m),to_sq);
        }
        break;
    case KING:
        p->white_king=to_sq;
        // move rook if this is a castle
        if (from_sq==E1) {
            if (to_sq==G1) {
                assert(is_castle(m));
                p->fifty_counter=0;
                remove_piece(p,H1);
                add_piece(p,ROOK,F1);
            } else if (to_sq==C1) {
                assert(is_castle(m));
                p->fifty_counter=0;
                remove_piece(p,A1);
                add_piece(p,ROOK,D1);
            }
        }
        break;
    case -KING:
        p->black_king=to_sq;
        if (from_sq==E8) {
            if (to_sq==G8) {
                assert(is_castle(m));
                p->fifty_counter=0;
                remove_piece(p,H8);
                add_piece(p,-ROOK,F8);
            } else if (to_sq==C8) {
                assert(is_castle(m));
                p->fifty_counter=0;
                remove_piece(p,A8);
                add_piece(p,-ROOK,D8);
            }
        }
        break;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x7854
movl %eax, %r15d
movq %r14, %rdi
callq 0x785b
movl %eax, %ebp
movl %r15d, %eax
movl (%rbx,%rax,4), %r12d
movq %rbx, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0xa5f8
testl %r12d, %r12d
jg 0x2e48
cmpl $-0x6, %r12d
je 0x2e90
cmpl $-0x1, %r12d
jne 0x2f7f
movl $0x0, 0x148(%rbx)
movl %r15d, %edi
callq 0xcc3e
movl %eax, %edi
callq 0xcc3e
cmpl %eax, %ebp
jne 0x2f42
movl %r15d, %edi
callq 0xcc3e
jmp 0x2e85
cmpl $0x6, %r12d
je 0x2eeb
cmpl $0x1, %r12d
jne 0x2f7f
movl $0x0, 0x148(%rbx)
movl %r15d, %edi
callq 0xcc05
movl %eax, %edi
callq 0xcc05
cmpl %eax, %ebp
jne 0x2f74
movl %r15d, %edi
callq 0xcc05
movl %eax, 0x13c(%rbx)
jmp 0x2f7f
movl %ebp, 0x150(%rbx)
cmpl $0x4, %r15d
jne 0x2f7f
cmpl $0x2, %ebp
je 0x2fb3
cmpl $0x6, %ebp
jne 0x2f7f
movq %r14, %rdi
callq 0x7897
testb %al, %al
je 0x3065
movl $0x0, 0x148(%rbx)
movq %rbx, %rdi
movl $0x7, %esi
callq 0xa78d
movq %rbx, %rdi
movl $0xfffffffc, %esi       # imm = 0xFFFFFFFC
movl $0x5, %edx
jmp 0x301a
movl %ebp, 0x14c(%rbx)
cmpl $0x3c, %r15d
jne 0x2f7f
cmpl $0x3a, %ebp
je 0x2fe6
cmpl $0x3e, %ebp
jne 0x2f7f
movq %r14, %rdi
callq 0x7897
testb %al, %al
je 0x3084
movl $0x0, 0x148(%rbx)
movq %rbx, %rdi
movl $0x3f, %esi
callq 0xa78d
movq %rbx, %rdi
movl $0x4, %esi
movl $0x3d, %edx
jmp 0x301a
movl %ebp, %edi
callq 0xca69
cmpl $0x7, %eax
jne 0x2f7f
movq %r14, %rdi
callq 0x786f
testl %eax, %eax
je 0x3027
movq %rbx, %rdi
movl %ebp, %esi
callq 0xa78d
movq %r14, %rdi
callq 0x786f
negl %eax
jmp 0x2faa
movl %ebp, %edi
callq 0xca69
testl %eax, %eax
je 0x2f88
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x786f
testl %eax, %eax
je 0x3046
movq %rbx, %rdi
movl %ebp, %esi
callq 0xa78d
movq %r14, %rdi
callq 0x786f
movq %rbx, %rdi
movl %eax, %esi
movl %ebp, %edx
jmp 0x301a
movq %r14, %rdi
callq 0x7897
testb %al, %al
je 0x30a3
movl $0x0, 0x148(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0xa78d
movq %rbx, %rdi
movl $0xfffffffc, %esi       # imm = 0xFFFFFFFC
movl $0x3, %edx
jmp 0x301a
movq %r14, %rdi
callq 0x7897
testb %al, %al
je 0x30c2
movl $0x0, 0x148(%rbx)
movq %rbx, %rdi
movl $0x38, %esi
callq 0xa78d
movq %rbx, %rdi
movl $0x4, %esi
movl $0x3b, %edx
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0xa5f8
leaq 0x26056(%rip), %rdi     # 0x29084
leaq 0x25fdd(%rip), %rsi     # 0x29012
leaq 0x26066(%rip), %rcx     # 0x290a2
movl $0x3d, %edx
callq 0x20d0
leaq 0x26037(%rip), %rdi     # 0x29084
leaq 0x25fbe(%rip), %rsi     # 0x29012
leaq 0x26047(%rip), %rcx     # 0x290a2
movl $0x33, %edx
callq 0x20d0
leaq 0x26066(%rip), %rdi     # 0x290d2
leaq 0x25f9f(%rip), %rsi     # 0x29012
leaq 0x26028(%rip), %rcx     # 0x290a2
movl $0x57, %edx
callq 0x20d0
leaq 0x26047(%rip), %rdi     # 0x290d2
leaq 0x25f80(%rip), %rsi     # 0x29012
leaq 0x26009(%rip), %rcx     # 0x290a2
movl $0x47, %edx
callq 0x20d0
leaq 0x26028(%rip), %rdi     # 0x290d2
leaq 0x25f61(%rip), %rsi     # 0x29012
leaq 0x25fea(%rip), %rcx     # 0x290a2
movl $0x5c, %edx
callq 0x20d0
leaq 0x26009(%rip), %rdi     # 0x290d2
leaq 0x25f42(%rip), %rsi     # 0x29012
leaq 0x25fcb(%rip), %rcx     # 0x290a2
movl $0x4c, %edx
callq 0x20d0