// File: /workspace/github_cpp_makefile_star2_O2/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 0x736b
movl %eax, %r15d
movq %r14, %rdi
callq 0x7372
movl %eax, %ebp
movl %r15d, %eax
movl (%rbx,%rax,4), %r12d
movq %rbx, %rdi
movl %r12d, %esi
movl %ebp, %edx
callq 0x9db0
cmpl $-0x6, %r12d
je 0x2df4
cmpl $-0x1, %r12d
je 0x2d75
cmpl $0x6, %r12d
je 0x2da6
cmpl $0x1, %r12d
jne 0x2e77
andl $0x0, 0x148(%rbx)
movl %r15d, %edi
callq 0xc19d
movl %eax, %edi
callq 0xc19d
cmpl %eax, %ebp
jne 0x2e6c
movl %r15d, %edi
callq 0xc19d
jmp 0x2d9b
andl $0x0, 0x148(%rbx)
movl %r15d, %edi
callq 0xc1e0
movl %eax, %edi
callq 0xc1e0
cmpl %eax, %ebp
jne 0x2e3a
movl %r15d, %edi
callq 0xc1e0
movl %eax, 0x13c(%rbx)
jmp 0x2e77
movl %ebp, 0x14c(%rbx)
cmpl $0x3c, %r15d
jne 0x2e77
cmpl $0x3a, %ebp
je 0x2eab
cmpl $0x3e, %ebp
jne 0x2e77
movq %r14, %rdi
callq 0x73ae
testb %al, %al
je 0x2f3d
andl $0x0, 0x148(%rbx)
pushq $0x3f
popq %rsi
movq %rbx, %rdi
callq 0x9f37
pushq $0x4
popq %rsi
pushq $0x3d
jmp 0x2efa
movl %ebp, 0x150(%rbx)
cmpl $0x4, %r15d
jne 0x2e77
cmpl $0x2, %ebp
je 0x2ed4
cmpl $0x6, %ebp
jne 0x2e77
movq %r14, %rdi
callq 0x73ae
testb %al, %al
je 0x2f56
andl $0x0, 0x148(%rbx)
pushq $0x7
popq %rsi
movq %rbx, %rdi
callq 0x9f37
pushq $-0x4
popq %rsi
pushq $0x5
jmp 0x2efa
movl %ebp, %edi
callq 0xc001
cmpl $0x7, %eax
jne 0x2e77
movq %r14, %rdi
callq 0x7386
testl %eax, %eax
je 0x2f0b
movq %rbx, %rdi
movl %ebp, %esi
callq 0x9f37
movq %r14, %rdi
callq 0x7386
negl %eax
jmp 0x2ea2
movl %ebp, %edi
callq 0xc001
testl %eax, %eax
je 0x2e80
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
callq 0x7386
testl %eax, %eax
je 0x2f24
movq %rbx, %rdi
movl %ebp, %esi
callq 0x9f37
movq %r14, %rdi
callq 0x7386
movq %rbx, %rdi
movl %eax, %esi
movl %ebp, %edx
jmp 0x2efe
movq %r14, %rdi
callq 0x73ae
testb %al, %al
je 0x2f6f
andl $0x0, 0x148(%rbx)
pushq $0x38
popq %rsi
movq %rbx, %rdi
callq 0x9f37
pushq $0x4
popq %rsi
pushq $0x3b
jmp 0x2efa
movq %r14, %rdi
callq 0x73ae
testb %al, %al
je 0x2f88
andl $0x0, 0x148(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x9f37
pushq $-0x4
popq %rsi
pushq $0x3
popq %rdx
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x9db0
leaq 0x24172(%rip), %rdi     # 0x27084
leaq 0x240f9(%rip), %rsi     # 0x27012
leaq 0x24182(%rip), %rcx     # 0x270a2
pushq $0x3d
jmp 0x2f9f
leaq 0x24159(%rip), %rdi     # 0x27084
leaq 0x240e0(%rip), %rsi     # 0x27012
leaq 0x24169(%rip), %rcx     # 0x270a2
pushq $0x33
jmp 0x2f9f
leaq 0x2418e(%rip), %rdi     # 0x270d2
leaq 0x240c7(%rip), %rsi     # 0x27012
leaq 0x24150(%rip), %rcx     # 0x270a2
pushq $0x47
jmp 0x2f9f
leaq 0x24175(%rip), %rdi     # 0x270d2
leaq 0x240ae(%rip), %rsi     # 0x27012
leaq 0x24137(%rip), %rcx     # 0x270a2
pushq $0x57
jmp 0x2f9f
leaq 0x2415c(%rip), %rdi     # 0x270d2
leaq 0x24095(%rip), %rsi     # 0x27012
leaq 0x2411e(%rip), %rcx     # 0x270a2
pushq $0x4c
jmp 0x2f9f
leaq 0x24143(%rip), %rdi     # 0x270d2
leaq 0x2407c(%rip), %rsi     # 0x27012
leaq 0x24105(%rip), %rcx     # 0x270a2
pushq $0x5c
popq %rdx
callq 0x20c0