// File: /workspace/github_cpp_makefile_star2_O1/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 0x7d4a(%rip), %rcx      # 0xc840
movb (%r14,%rcx), %dl
andb (%rax,%rcx), %dl
andb %dl, 0x40(%rdi)
movl %r12d, %ecx
shrl $0xc, %ecx
leaq 0x7cd3(%rip), %rdx      # 0xc7e0
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 0x4d15
xorl %ecx, %ecx
jmp 0x4d4f
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 0x4ddb
movl $0x1, %edx
movl %r14d, %ecx
shlq %cl, %rdx
movl $0x1, %esi
movq (%rbx), %rcx
btq %r14, %rcx
jae 0x4c6f
xorl %ecx, %ecx
jmp 0x4cae
cmpb %r14b, %al
je 0x4ec7
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 0x4ddb
leaq 0x7cad(%rip), %rdi      # 0xc880
callq 0x3260
jmp 0x4ddb
cmpb %r14b, %al
je 0x4ec7
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 0x4dcc
cmpl $0x2, %r14d
jne 0x4ddb
xorb $0x9, 0x18(%rbx)
xorq $0x9, %rdx
jmp 0x4dd7
cmpb %r14b, %al
je 0x4ec7
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 0x4ddb
movl $0x1, %edx
movl %r14d, %ecx
shlq %cl, %rdx
movl $0x1, %esi
movq (%rbx), %rcx
btq %r14, %rcx
jae 0x4d66
xorl %ecx, %ecx
jmp 0x4da5
movl $0x1, %ecx
testq %rdx, 0x8(%rbx)
jne 0x4cae
movl $0x2, %ecx
testq %rdx, 0x10(%rbx)
jne 0x4cae
movl $0x3, %ecx
testq %rdx, 0x18(%rbx)
jne 0x4cae
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 0x4cc8
xorl %ecx, %ecx
jmp 0x4d07
movl $0x1, %ecx
testq %rsi, 0x8(%rbx)
jne 0x4d07
movl $0x2, %ecx
testq %rsi, 0x10(%rbx)
jne 0x4d07
movl $0x3, %ecx
testq %rsi, 0x18(%rbx)
jne 0x4d07
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 0x4ec7
xorq %rsi, %rdx
jmp 0x4d5c
testq %rdx, 0x8(%rbx)
jne 0x4d4f
movl $0x2, %ecx
testq %rdx, 0x10(%rbx)
jne 0x4d4f
movl $0x3, %ecx
testq %rdx, 0x18(%rbx)
jne 0x4d4f
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 0x4ec7
btcq %r14, %rdx
xorq %rdx, (%rbx,%rcx,8)
xorq %rdx, 0x30(%rbx)
jmp 0x4ddb
movl $0x1, %ecx
testq %rdx, 0x8(%rbx)
jne 0x4da5
movl $0x2, %ecx
testq %rdx, 0x10(%rbx)
jne 0x4da5
movl $0x3, %ecx
testq %rdx, 0x18(%rbx)
jne 0x4da5
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 0x4ddb
xorb $-0x60, 0x18(%rbx)
xorq $0xa0, %rdx
movq %rdx, 0x30(%rbx)
incb 0x43(%rbx)
testl $0x6000, %r15d          # imm = 0x6000
je 0x4dfb
movq 0x50(%rbx), %rax
cmpq %rax, 0x58(%rbx)
je 0x4df5
movq %rax, 0x58(%rbx)
movb $0x0, 0x43(%rbx)
jmp 0x4e04
testl %r12d, %r12d
je 0x4eb5
movq $-0x8, %rax
movq 0x8(%rbx,%rax), %rcx
bswapq %rcx
movq %rcx, 0x8(%rbx,%rax)
addq $0x8, %rax
cmpq $0x28, %rax
jb 0x4e0b
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 0x4e37
movb 0x42(%rbx), %al
cmpb $0x40, %al
je 0x4e5a
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 0x6c3a
movq 0x58(%rbx), %rsi
cmpq 0x60(%rbx), %rsi
je 0x4e9d
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 0x57ca
movq (%rbx), %rax
btq %r14, %rax
jb 0x4de7
jmp 0x4e04
leaq 0x7ac5(%rip), %rdi      # 0xc993
leaq 0x7ac9(%rip), %rsi      # 0xc99e
leaq 0x7ad1(%rip), %rcx      # 0xc9ad
movl $0x77, %edx
callq 0x3100