// File: /workspace/github_cpp_makefile_star2_O3/IncredibleHannes[P]QMUL-ChessGame/src/Model/Chessman/King.cpp
// Function: King::getPossibleMoves[abi:cxx11](Board const&) const
std::list<Move> King::getPossibleMoves(const Board &board) const {
  std::list<Move> moves;
  if (!isCaptured()) {
    int x = this->position.getX();
    int y = this->position.getY();
    for (int i = -1; i < 2; i++) {
      for (int j = -1; j < 2; j ++) {
        int targetx = x + i;
        int targety = y + j;
        if (targetx >= 0 && targetx < 8 && targety >= 0 && targety < 8) {
          if (board.getChessman(Position(targetx, targety)) != nullptr
              && board.getChessman(Position(targetx, targety))->getColour() != this->getColour()) {
            moves.push_back(Move(Position(x, y), Position(targetx, targety)));
          } else if (board.getChessman(Position(targetx, targety)) == nullptr) {
            moves.push_back(Move(Position(x, y), Position(targetx, targety)));
          }
        }
      }
    }
    // Castling
    if ((x == 0 || x == 7) && y == 4 && !this->wasMoved()) {
      if (board.getChessman(Position(x, y + 1)) == nullptr
          && board.getChessman(Position(x, y + 2)) == nullptr
          && board.getChessman(Position(x, y + 3)) != nullptr
          && board.getChessman(Position(x, y + 3))->getType() == Chessman::FigureType::Rook
          && board.getChessman(Position(x, y + 3))->getColour() == this->colour
          && !board.getChessman(Position(x, y + 3))->wasMoved()) {
        moves.push_back(Move(Position(x, y), Position(x, y + 2)));

      }
      if (board.getChessman(Position(x, y - 1)) == nullptr
          && board.getChessman(Position(x, y - 2)) == nullptr
          && board.getChessman(Position(x, y - 3)) == nullptr
          && board.getChessman(Position(x, y - 4)) != nullptr
          && board.getChessman(Position(x, y - 4))->getType() == Chessman::FigureType::Rook
          && board.getChessman(Position(x, y - 4))->getColour() == this->colour
          && !board.getChessman(Position(x, y - 4))->wasMoved()) {
        moves.push_back(Move(Position(x, y), Position(x, y - 2)));

      }

    }
  }
  return moves;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdx, -0x30(%rbp)
movq %rdi, 0x8(%rdi)
movq %rdi, (%rdi)
movq %rdi, -0x38(%rbp)
movq $0x0, 0x10(%rdi)
movq %rsi, -0x40(%rbp)
movq %rsi, %rdi
callq 0x37c2
testb %al, %al
jne 0x3bc0
movq -0x40(%rbp), %rax
leaq 0x10(%rax), %rbx
movq %rbx, %rdi
callq 0x2962
movl %eax, %r14d
movq %rbx, %rdi
callq 0x296a
movl %eax, %r13d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %r14, -0x48(%rbp)
movq %rax, -0x70(%rbp)
addl %eax, %r14d
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpl $0x8, %r14d
setb %al
leal (%r12,%r13), %ebx
cmpl $0x8, %ebx
setb %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x3a9c
leaq -0x130(%rbp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x292a
movq -0x130(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c22
testq %rax, %rax
je 0x3a11
leaq -0x128(%rbp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x292a
movq -0x128(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c22
movq %rax, %rdi
callq 0x37ae
movl %eax, %r15d
movq -0x40(%rbp), %rdi
callq 0x37ae
cmpb %al, %r15b
je 0x3a11
leaq -0x120(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl %r13d, %edx
callq 0x292a
leaq -0x118(%rbp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x292a
movq -0x120(%rbp), %rsi
movq -0x118(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x4040
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
leaq -0x68(%rbp), %r15
movq %r15, %rsi
callq 0x2e84
jmp 0x3a85
leaq -0x110(%rbp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x292a
movq -0x110(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c22
testq %rax, %rax
jne 0x3a9c
leaq -0x108(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl %r13d, %edx
callq 0x292a
leaq -0x100(%rbp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x292a
movq -0x108(%rbp), %rsi
movq -0x100(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x4040
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
leaq -0x68(%rbp), %r15
movq %r15, %rsi
callq 0x2e84
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2050
incq 0x10(%rbx)
movq %r15, %rdi
callq 0x40c0
incl %r12d
cmpl $0x2, %r12d
jne 0x3941
movq -0x70(%rbp), %rax
incl %eax
cmpl $0x2, %eax
movq -0x48(%rbp), %r14
jne 0x3934
testl %r14d, %r14d
sete %al
cmpl $0x7, %r14d
sete %cl
orb %al, %cl
cmpl $0x4, %r13d
sete %al
testb %al, %cl
je 0x3bc0
movq -0x40(%rbp), %rdi
callq 0x3866
testb %al, %al
jne 0x3bc0
leaq -0xf8(%rbp), %rdi
movl %r14d, %esi
movl $0x5, %edx
callq 0x292a
movq -0xf8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c22
testq %rax, %rax
jne 0x3b41
leaq -0xf0(%rbp), %rdi
movl %r14d, %esi
movl $0x6, %edx
callq 0x292a
movq -0xf0(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c22
testq %rax, %rax
je 0x3bd6
leaq -0xb8(%rbp), %rdi
movl %r14d, %esi
movl $0x3, %edx
callq 0x292a
movq -0xb8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c22
testq %rax, %rax
jne 0x3bc0
leaq -0xb0(%rbp), %rdi
movl %r14d, %esi
movl $0x2, %edx
callq 0x292a
movq -0xb0(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c22
testq %rax, %rax
jne 0x3bc0
leaq -0xa8(%rbp), %rdi
movl %r14d, %esi
movl $0x1, %edx
callq 0x292a
movq -0xa8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c22
testq %rax, %rax
je 0x3cff
movq -0x38(%rbp), %rax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0xe8(%rbp), %rdi
movl %r14d, %esi
movl $0x7, %edx
callq 0x292a
movq -0xe8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c22
testq %rax, %rax
je 0x3b41
leaq -0xe0(%rbp), %rdi
movl %r14d, %esi
movl $0x7, %edx
callq 0x292a
movq -0xe0(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c22
movq %rax, %rdi
callq 0x3844
cmpl $0x4, %eax
jne 0x3b41
leaq -0xd8(%rbp), %rdi
movl %r14d, %esi
movl $0x7, %edx
callq 0x292a
movq -0xd8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c22
movq %rax, %rdi
callq 0x37ae
movq -0x40(%rbp), %rcx
cmpb %al, 0x8(%rcx)
jne 0x3b41
leaq -0xd0(%rbp), %rdi
movl %r14d, %esi
movl $0x7, %edx
callq 0x292a
movq -0xd0(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c22
movq %rax, %rdi
callq 0x3866
testb %al, %al
jne 0x3b41
leaq -0xc8(%rbp), %rdi
movl %r14d, %esi
movl $0x4, %edx
callq 0x292a
leaq -0xc0(%rbp), %rdi
movl %r14d, %esi
movl $0x6, %edx
callq 0x292a
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x4040
leaq -0x68(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x3600
leaq -0x68(%rbp), %rdi
callq 0x40c0
jmp 0x3b41
leaq -0xa0(%rbp), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x292a
movq -0xa0(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c22
testq %rax, %rax
je 0x3bc0
leaq -0x98(%rbp), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x292a
movq -0x98(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c22
movq %rax, %rdi
callq 0x3844
cmpl $0x4, %eax
jne 0x3bc0
leaq -0x90(%rbp), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x292a
movq -0x90(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c22
movq %rax, %rdi
callq 0x37ae
movq -0x40(%rbp), %rcx
cmpb %al, 0x8(%rcx)
jne 0x3bc0
leaq -0x88(%rbp), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x292a
movq -0x88(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c22
movq %rax, %rdi
callq 0x3866
testb %al, %al
jne 0x3bc0
leaq -0x80(%rbp), %rdi
movl %r14d, %esi
movl $0x4, %edx
callq 0x292a
leaq -0x78(%rbp), %rdi
movl %r14d, %esi
movl $0x2, %edx
callq 0x292a
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x4040
leaq -0x68(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x3600
leaq -0x68(%rbp), %rdi
callq 0x40c0
jmp 0x3bc0
jmp 0x3e20
jmp 0x3e20
jmp 0x3e32
jmp 0x3e32
jmp 0x3e32
jmp 0x3e32
jmp 0x3e32
jmp 0x3e20
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x40c0
jmp 0x3e35
jmp 0x3e32
jmp 0x3e32
movq %rax, %rbx
movq -0x38(%rbp), %rdi
callq 0x2b06
movq %rbx, %rdi
callq 0x21d0