// File: /workspace/github_cpp_makefile_star2_O2/jswaff[P]prophet3/src/apply.cpp
// Function: apply_move(position*, unsigned long long, undo*)
void apply_move(position *p,move m,undo *undo_stack) {
    assert(p);
    assert(clear_score(m));
    assert(test_pos_consistency(p));
    assert(undo_stack);

    // capture information to undo move
    undo *u = undo_stack+p->move_counter;
    u->mv = m;
    u->hash_key = p->hash_key;
    u->ep_sq = p->ep_sq;
    u->fifty_counter = p->fifty_counter;
    u->castling_rights = p->castling_rights;

    // clear current values
    p->hash_key ^= zkeys.ptm[p->player];
    p->hash_key ^= zkeys.ep[p->ep_sq];
    p->hash_key ^= zkeys.casting_rights[p->castling_rights];

    p->player = opposite_player(p->player);
    p->move_counter++;
    p->fifty_counter++;  // may get reset

    if (is_capture(m)) {
        p->fifty_counter=0;
        u->captured = remove_captured_piece(p,m);
    } else {
        u->captured = NO_PIECE;
    }
    assert(abs(u->captured)==get_captured_piece(m));

    // this could get reset
    p->ep_sq=NO_SQUARE;

    add_piece_to_destination(p,m);
    remove_castling_availability(p,m);
    remove_piece(p,get_from_sq(m));

    // add in current values
    p->hash_key ^= zkeys.ptm[p->player];
    p->hash_key ^= zkeys.ep[p->ep_sq];
    p->hash_key ^= zkeys.casting_rights[p->castling_rights];

    assert(test_pos_consistency(p));
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
testq %rdi, %rdi
je 0x3152
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %rbx
movq %rsi, %rdi
callq 0x73f4
testq %rax, %rax
je 0x316b
movq %rbx, %rdi
callq 0x21176
testb %al, %al
je 0x3184
testq %r15, %r15
je 0x319d
movl 0x144(%rbx), %eax
shlq $0x5, %rax
movq %r14, (%r15,%rax)
movq 0x1b8(%rbx), %rcx
movq %rcx, 0x8(%r15,%rax)
movl 0x13c(%rbx), %edx
movl %edx, 0x14(%r15,%rax)
movl 0x148(%rbx), %esi
movl %esi, 0x18(%r15,%rax)
movl 0x140(%rbx), %esi
movl %esi, 0x1c(%r15,%rax)
movl 0x138(%rbx), %edi
leaq 0xf8567(%rip), %r12     # 0xfb598
xorq 0x1c00(%r12,%rdi,8), %rcx
addq %rax, %r15
movq %rcx, 0x1b8(%rbx)
xorq 0x1c90(%r12,%rdx,8), %rcx
movq %rcx, 0x1b8(%rbx)
xorq 0x1c10(%r12,%rsi,8), %rcx
movq %rcx, 0x1b8(%rbx)
callq 0xd4d8
movl %eax, 0x138(%rbx)
movq 0x144(%rbx), %xmm0
pcmpeqd %xmm1, %xmm1
psubd %xmm1, %xmm0
movq %xmm0, 0x144(%rbx)
movq %r14, %rdi
callq 0x739a
movl %eax, %ecx
xorl %eax, %eax
testb %cl, %cl
je 0x30a6
andl $0x0, 0x148(%rbx)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2c0c
movl %eax, 0x10(%r15)
movl %eax, %ebp
negl %ebp
cmovsl %eax, %ebp
movq %r14, %rdi
callq 0x7390
cmpl %eax, %ebp
jne 0x31ba
movl $0x40, 0x13c(%rbx)
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2cf6
movq %rbx, %rdi
movq %r14, %rsi
callq 0xa10f
movq %r14, %rdi
callq 0x736b
movq %rbx, %rdi
movl %eax, %esi
callq 0x9f37
movl 0x138(%rbx), %eax
movl 0x13c(%rbx), %ecx
movq 0x1b8(%rbx), %rdx
xorq 0x1c00(%r12,%rax,8), %rdx
movq %rdx, 0x1b8(%rbx)
xorq 0x1c90(%r12,%rcx,8), %rdx
movq %rdx, 0x1b8(%rbx)
movl 0x140(%rbx), %eax
xorq 0x1c10(%r12,%rax,8), %rdx
movq %rdx, 0x1b8(%rbx)
movq %rbx, %rdi
callq 0x21176
testb %al, %al
je 0x31d9
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x30266(%rip), %rdi     # 0x333bf
leaq 0x23eb2(%rip), %rsi     # 0x27012
leaq 0x23f78(%rip), %rcx     # 0x270df
pushq $0x67
jmp 0x31b4
leaq 0x23f97(%rip), %rdi     # 0x27109
leaq 0x23e99(%rip), %rsi     # 0x27012
leaq 0x23f5f(%rip), %rcx     # 0x270df
pushq $0x68
jmp 0x31b4
leaq 0x23f8d(%rip), %rdi     # 0x27118
leaq 0x23e80(%rip), %rsi     # 0x27012
leaq 0x23f46(%rip), %rcx     # 0x270df
pushq $0x69
jmp 0x31b4
leaq 0x23f8c(%rip), %rdi     # 0x27130
leaq 0x23e67(%rip), %rsi     # 0x27012
leaq 0x23f2d(%rip), %rcx     # 0x270df
pushq $0x6a
popq %rdx
callq 0x20c0
leaq 0x23f7a(%rip), %rdi     # 0x2713b
leaq 0x23e4a(%rip), %rsi     # 0x27012
leaq 0x23f10(%rip), %rcx     # 0x270df
movl $0x83, %edx
callq 0x20c0
leaq 0x23f38(%rip), %rdi     # 0x27118
leaq 0x23e2b(%rip), %rsi     # 0x27012
leaq 0x23ef1(%rip), %rcx     # 0x270df
movl $0x91, %edx
callq 0x20c0