// File: /workspace/github_cpp_makefile_star2_O3/cpirc[P]Monochrome/src/move.cpp
// Function: make_move(Position&, unsigned int)
void make_move(Position& pos, const Move move) {
    pos.epsq = INVALID_SQUARE;

    const Square from = from_square(move), to = to_square(move);
    const MoveType mt = move_type(move);

    pos.castle &= castling_lookup[from] & castling_lookup[to];

    switch (mt) {
        case NORMAL:
            move_piece(pos, from, to, get_piece_on_square(pos, from), US);
            break;
        case CAPTURE:
            remove_piece(pos, to, get_piece_on_square(pos, to), THEM);
            move_piece(pos, from, to, get_piece_on_square(pos, from), US);
            break;
        case DOUBLE_PUSH:
            move_piece(pos, from, to, PAWN, US);
            pos.epsq = from + 8;
            break;
        case ENPASSANT:
            move_piece(pos, from, to, PAWN, US);
            remove_piece(pos, to - 8, PAWN, THEM);
            break;
        case CASTLE:
            move_piece(pos, from, to, KING, US);
            switch (to) {
                case C1:
                    move_piece(pos, A1, D1, ROOK, US);
                    break;
                case G1:
                    move_piece(pos, H1, F1, ROOK, US);
                    break;
                default:
                    break;
            }
            break;
        case PROM_CAPTURE:
            remove_piece(pos, to, get_piece_on_square(pos, to), THEM);
            remove_piece(pos, from, PAWN, US);
            put_piece(pos, to, promotion_type(move), US);
            break;
        case PROMOTION:
            remove_piece(pos, from, PAWN, US);
            put_piece(pos, to, promotion_type(move), US);
            break;
        default:
            std::puts("MOVE TYPE ERROR");
            break;
    }

    pos.halfmoves++;
    if ((mt != NORMAL && mt != CASTLE) ||
        (mt == NORMAL && get_piece_on_square(pos, to) == PAWN)) {
        pos.history.clear();
        pos.halfmoves = 0;
    }

    flip_position(pos);
    calculate_key(pos);

    pos.history.push_back(pos.hash_key);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl %esi, %r15d
movq %rdi, %rbx
movb $0x40, 0x42(%rdi)
movl %esi, %eax
andl $0x3f, %eax
movl %esi, %r14d
shrl $0x6, %r14d
andl $0x3f, %r14d
movl %esi, %r12d
andl $0x7000, %r12d          # imm = 0x7000
leaq 0x7f4a(%rip), %rcx      # 0xc720
movb (%r14,%rcx), %dl
andb (%rax,%rcx), %dl
andb %dl, 0x40(%rdi)
movl %r12d, %ecx
shrl $0xc, %ecx
leaq 0x7ef3(%rip), %rdx      # 0xc6e0
movslq (%rdx,%rcx,4), %rcx
addq %rdx, %rcx
jmpq *%rcx
movl $0x1, %edx
movl %eax, %ecx
shlq %cl, %rdx
movl $0x1, %ecx
movq (%rbx), %rsi
btq %rax, %rsi
jae 0x49f5
xorl %ecx, %ecx
jmp 0x4a2f
movl $0x1, %edx
movl %eax, %ecx
shlq %cl, %rdx
xorq %rdx, (%rbx)
movl $0x1, %eax
xorq %rdx, 0x30(%rbx)
movl %r14d, %ecx
shlq %cl, %rax
movl %r15d, %ecx
shrl $0xc, %ecx
andl $0x38, %ecx
orq %rax, (%rbx,%rcx)
orq %rax, 0x30(%rbx)
jmp 0x4abb
movl $0x1, %edx
movl %r14d, %ecx
shlq %cl, %rdx
movl $0x1, %esi
movq (%rbx), %rcx
btq %r14, %rcx
jae 0x494f
xorl %ecx, %ecx
jmp 0x498e
cmpb %r14b, %al
je 0x4ba7
movl $0x1, %edx
movl $0x1, %esi
movb %r14b, %cl
shlq %cl, %rsi
btcq %rax, %rsi
movq (%rbx), %rax
xorq %rsi, 0x30(%rbx)
xorq %rsi, %rax
addb $-0x8, %cl
shlq %cl, %rdx
btcq %rcx, %rax
movq %rax, (%rbx)
xorq %rdx, 0x38(%rbx)
jmp 0x4abb
leaq 0x7f0d(%rip), %rdi      # 0xc7c0
callq 0x3260
jmp 0x4abb
cmpb %r14b, %al
je 0x4ba7
movl $0x1, %edx
movl %r14d, %ecx
shlq %cl, %rdx
btcq %rax, %rdx
xorq %rdx, 0x28(%rbx)
xorq 0x30(%rbx), %rdx
movq %rdx, 0x30(%rbx)
cmpq $0x6, %r14
je 0x4aac
cmpl $0x2, %r14d
jne 0x4abb
xorb $0x9, 0x18(%rbx)
xorq $0x9, %rdx
jmp 0x4ab7
cmpb %r14b, %al
je 0x4ba7
movl $0x1, %edx
movl %r14d, %ecx
shlq %cl, %rdx
btcq %rax, %rdx
xorq %rdx, (%rbx)
xorq %rdx, 0x30(%rbx)
addb $0x8, %al
movb %al, 0x42(%rbx)
jmp 0x4abb
movl $0x1, %edx
movl %r14d, %ecx
shlq %cl, %rdx
movl $0x1, %esi
movq (%rbx), %rcx
btq %r14, %rcx
jae 0x4a46
xorl %ecx, %ecx
jmp 0x4a85
movl $0x1, %ecx
testq %rdx, 0x8(%rbx)
jne 0x498e
movl $0x2, %ecx
testq %rdx, 0x10(%rbx)
jne 0x498e
movl $0x3, %ecx
testq %rdx, 0x18(%rbx)
jne 0x498e
movq 0x28(%rbx), %rcx
andq %rdx, %rcx
xorl %edi, %edi
cmpq $0x1, %rcx
adcq $0x5, %rdi
testq %rdx, 0x20(%rbx)
movl $0x4, %ecx
cmoveq %rdi, %rcx
xorq %rdx, (%rbx,%rcx,8)
xorq %rdx, 0x38(%rbx)
movl %eax, %ecx
shlq %cl, %rsi
movq (%rbx), %rcx
btq %rax, %rcx
jae 0x49a8
xorl %ecx, %ecx
jmp 0x49e7
movl $0x1, %ecx
testq %rsi, 0x8(%rbx)
jne 0x49e7
movl $0x2, %ecx
testq %rsi, 0x10(%rbx)
jne 0x49e7
movl $0x3, %ecx
testq %rsi, 0x18(%rbx)
jne 0x49e7
movq 0x28(%rbx), %rcx
andq %rsi, %rcx
xorl %edi, %edi
cmpq $0x1, %rcx
adcq $0x5, %rdi
testq %rsi, 0x20(%rbx)
movl $0x4, %ecx
cmoveq %rdi, %rcx
cmpb %r14b, %al
je 0x4ba7
xorq %rsi, %rdx
jmp 0x4a3c
testq %rdx, 0x8(%rbx)
jne 0x4a2f
movl $0x2, %ecx
testq %rdx, 0x10(%rbx)
jne 0x4a2f
movl $0x3, %ecx
testq %rdx, 0x18(%rbx)
jne 0x4a2f
movq 0x28(%rbx), %rcx
andq %rdx, %rcx
xorl %esi, %esi
cmpq $0x1, %rcx
adcq $0x5, %rsi
testq %rdx, 0x20(%rbx)
movl $0x4, %ecx
cmoveq %rsi, %rcx
cmpb %r14b, %al
je 0x4ba7
btcq %r14, %rdx
xorq %rdx, (%rbx,%rcx,8)
xorq %rdx, 0x30(%rbx)
jmp 0x4abb
movl $0x1, %ecx
testq %rdx, 0x8(%rbx)
jne 0x4a85
movl $0x2, %ecx
testq %rdx, 0x10(%rbx)
jne 0x4a85
movl $0x3, %ecx
testq %rdx, 0x18(%rbx)
jne 0x4a85
movq 0x28(%rbx), %rcx
andq %rdx, %rcx
xorl %edi, %edi
cmpq $0x1, %rcx
adcq $0x5, %rdi
testq %rdx, 0x20(%rbx)
movl $0x4, %ecx
cmoveq %rdi, %rcx
xorq %rdx, (%rbx,%rcx,8)
xorq %rdx, 0x38(%rbx)
movl %eax, %ecx
shlq %cl, %rsi
xorq %rsi, (%rbx)
xorq %rsi, 0x30(%rbx)
movl %r15d, %eax
shrl $0xc, %eax
andl $0x38, %eax
orq %rdx, (%rbx,%rax)
orq %rdx, 0x30(%rbx)
jmp 0x4abb
xorb $-0x60, 0x18(%rbx)
xorq $0xa0, %rdx
movq %rdx, 0x30(%rbx)
incb 0x43(%rbx)
testl $0x6000, %r15d          # imm = 0x6000
je 0x4adb
movq 0x50(%rbx), %rax
cmpq %rax, 0x58(%rbx)
je 0x4ad5
movq %rax, 0x58(%rbx)
movb $0x0, 0x43(%rbx)
jmp 0x4ae4
testl %r12d, %r12d
je 0x4b95
movq $-0x8, %rax
movq 0x8(%rbx,%rax), %rcx
bswapq %rcx
movq %rcx, 0x8(%rbx,%rax)
addq $0x8, %rax
cmpq $0x28, %rax
jb 0x4aeb
movq 0x30(%rbx), %rax
movq 0x38(%rbx), %rcx
movq %rax, 0x38(%rbx)
movq %rcx, 0x30(%rbx)
movl $0x28, %eax
movq 0x8(%rbx,%rax), %rcx
bswapq %rcx
movq %rcx, 0x8(%rbx,%rax)
addq $0x8, %rax
cmpq $0x38, %rax
jb 0x4b17
movb 0x42(%rbx), %al
cmpb $0x40, %al
je 0x4b3a
xorb $0x38, %al
movb %al, 0x42(%rbx)
movb 0x40(%rbx), %al
leal (,%rax,4), %ecx
andb $0xc, %cl
shrb $0x2, %al
xorb %cl, %al
movb %al, 0x40(%rbx)
xorb $0x1, 0x41(%rbx)
movq %rbx, %rdi
callq 0x6952
movq 0x58(%rbx), %rsi
cmpq 0x60(%rbx), %rsi
je 0x4b7d
movq 0x48(%rbx), %rax
movq %rax, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x58(%rbx)
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x48(%rbx), %rdx
addq $0x50, %rbx
movq %rbx, %rdi
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
jmp 0x543c
movq (%rbx), %rax
btq %r14, %rax
jb 0x4ac7
jmp 0x4ae4
leaq 0x7d25(%rip), %rdi      # 0xc8d3
leaq 0x7d29(%rip), %rsi      # 0xc8de
leaq 0x7d31(%rip), %rcx      # 0xc8ed
movl $0x77, %edx
callq 0x3100