// File: /workspace/github_cpp_makefile_star2_O3/IncredibleHannes[P]QMUL-ChessGame/src/Model/Board.cpp
// Function: Board::applyPromotion(Move*, Chessman::FigureType)
void Board::applyPromotion(Move *move, Chessman::FigureType type) {
    Chessman *currentChessman = getChessman(move->getTarget());
    move->addType(Move::Promotion);
    int x = move->getTarget().getX();
    int y = move->getTarget().getY();
    switch(type) {
      case Chessman::Queen :
        board[x][y] = new Queen(currentChessman->getColour(), Position(x,y));
        break;
      case Chessman::Rook :
        board[x][y] = new Rook(currentChessman->getColour(), Position(x,y));
        break;
      case Chessman::Bishop :
        board[x][y] = new Bishop(currentChessman->getColour(), Position(x,y));
        break;
      case Chessman::Knight :
        board[x][y] = new Knight(currentChessman->getColour(), Position(x,y));
        break;
      default:
        break;
    }
    Move *m = previousMoves.back();
    previousMoves.pop_back();
    delete m;
    previousMoves.push_back(new Move(*move));
    capturedChessmen.push_back(currentChessman);
    delete move;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %edx, %r12d
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rdi
callq 0x40e0
leaq -0x40(%rbp), %r15
movq %rax, (%r15)
movq (%r14), %r13
movq %r15, %rdi
callq 0x2962
cltq
movq (%r13,%rax,8), %r13
movq %r15, %rdi
callq 0x296a
cltq
movq (%r13,%rax,8), %rax
movq %rax, -0x38(%rbp)
movq %rbx, %rdi
movl $0x4, %esi
callq 0x40ea
movq %rbx, %rdi
callq 0x40e0
movq %rax, (%r15)
movq %r15, %rdi
callq 0x2962
movl %eax, %r13d
movq %rbx, %rdi
callq 0x40e0
movq %rax, (%r15)
leaq -0x40(%rbp), %rdi
callq 0x296a
decl %r12d
cmpl $0x4, %r12d
ja 0x5411
movl %eax, %r15d
leaq 0x1d4e(%rip), %rax      # 0x705c
movslq (%rax,%r12,4), %rcx
addq %rax, %rcx
jmpq *%rcx
movl $0x18, %edi
callq 0x2120
movq %rax, %r12
movq -0x38(%rbp), %rdi
callq 0x37ae
movb %al, -0x29(%rbp)
leaq -0x60(%rbp), %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x292a
movq -0x60(%rbp), %rdx
movzbl -0x29(%rbp), %esi
movq %r12, %rdi
callq 0x3e50
jmp 0x5400
movl $0x18, %edi
callq 0x2120
movq %rax, %r12
movq -0x38(%rbp), %rdi
callq 0x37ae
movb %al, -0x29(%rbp)
leaq -0x58(%rbp), %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x292a
movq -0x58(%rbp), %rdx
movzbl -0x29(%rbp), %esi
movq %r12, %rdi
callq 0x3630
jmp 0x5400
movl $0x18, %edi
callq 0x2120
movq %rax, %r12
movq -0x38(%rbp), %rdi
callq 0x37ae
movb %al, -0x29(%rbp)
leaq -0x48(%rbp), %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x292a
movq -0x48(%rbp), %rdx
movzbl -0x29(%rbp), %esi
movq %r12, %rdi
callq 0x2b44
jmp 0x5400
movl $0x18, %edi
callq 0x2120
movq %rax, %r12
movq -0x38(%rbp), %rdi
callq 0x37ae
movb %al, -0x29(%rbp)
leaq -0x50(%rbp), %rdi
movl %r13d, %esi
movl %r15d, %edx
callq 0x292a
movq -0x50(%rbp), %rdx
movzbl -0x29(%rbp), %esi
movq %r12, %rdi
callq 0x29a0
movq (%r14), %rax
movslq %r13d, %rcx
movq (%rax,%rcx,8), %rax
movslq %r15d, %rcx
movq %r12, (%rax,%rcx,8)
movq 0x30(%r14), %r12
movq 0x10(%r12), %r15
decq 0x38(%r14)
movq %r12, %rdi
callq 0x21b0
movq %r12, %rdi
callq 0x2100
testq %r15, %r15
je 0x543b
movq %r15, %rdi
callq 0x40c0
movq %r15, %rdi
callq 0x2100
movl $0x20, %edi
callq 0x2120
movq %rax, %r12
movq %rax, %rdi
movq %rbx, %rsi
callq 0x4074
leaq 0x28(%r14), %r15
movl $0x18, %edi
callq 0x2120
movq %r12, 0x10(%rax)
movq %rax, %rdi
movq %r15, %rsi
callq 0x2050
incq 0x38(%r14)
leaq 0x10(%r14), %r15
movl $0x18, %edi
callq 0x2120
movq -0x38(%rbp), %rcx
movq %rcx, 0x10(%rax)
movq %rax, %rdi
movq %r15, %rsi
callq 0x2050
incq 0x20(%r14)
movq %rbx, %rdi
callq 0x40c0
movq %rbx, %rdi
callq 0x2100
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x54c8
jmp 0x54c8
jmp 0x54c8
jmp 0x54c8
movq %rax, %rbx
movq %r12, %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x21d0
nop