// File: /workspace/github_cpp_makefile_star2_O2/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)
andq $0x0, 0x10(%rdi)
movq %rsi, -0x40(%rbp)
movq %rsi, %rdi
callq 0x37ae
testb %al, %al
jne 0x3b92
movq -0x40(%rbp), %rax
leaq 0x10(%rax), %rbx
movq %rbx, %rdi
callq 0x28a6
movl %eax, %r14d
movq %rbx, %rdi
callq 0x28ae
movl %eax, %r13d
pushq $-0x1
popq %rax
movq %r14, -0x48(%rbp)
cmpl $0x2, %eax
je 0x3a98
movq %rax, -0x70(%rbp)
addl %eax, %r14d
pushq $-0x1
popq %rax
movl %eax, %r12d
cmpl $0x2, %r12d
je 0x3a89
cmpl $0x8, %r14d
setb %al
leal (%r12,%r13), %ebx
cmpl $0x8, %ebx
setb %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x3a81
leaq -0x130(%rbp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x286e
movq -0x130(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a86
testq %rax, %rax
je 0x3a08
leaq -0x128(%rbp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x286e
movq -0x128(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a86
movq %rax, %rdi
callq 0x379a
movl %eax, %r15d
movq -0x40(%rbp), %rdi
callq 0x379a
cmpb %al, %r15b
je 0x3a08
leaq -0x120(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl %r13d, %edx
callq 0x286e
leaq -0x118(%rbp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x286e
movq -0x120(%rbp), %rsi
movq -0x118(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x3ffc
movq -0x38(%rbp), %rdi
leaq -0x68(%rbp), %rbx
movq %rbx, %rsi
callq 0x2cfa
jmp 0x3a79
leaq -0x110(%rbp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x286e
movq -0x110(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a86
testq %rax, %rax
jne 0x3a81
leaq -0x108(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl %r13d, %edx
callq 0x286e
leaq -0x100(%rbp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x286e
movq -0x108(%rbp), %rsi
movq -0x100(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x3ffc
movq -0x38(%rbp), %rdi
leaq -0x68(%rbp), %rbx
movq %rbx, %rsi
callq 0x2cfa
movq %rbx, %rdi
callq 0x4072
incl %r12d
jmp 0x3931
movq -0x70(%rbp), %rax
incl %eax
movq -0x48(%rbp), %r14
jmp 0x391b
testl %r14d, %r14d
sete %al
cmpl $0x7, %r14d
sete %cl
orb %al, %cl
cmpl $0x4, %r13d
sete %al
testb %al, %cl
je 0x3b92
movq -0x40(%rbp), %rdi
callq 0x3852
testb %al, %al
jne 0x3b92
leaq -0xf8(%rbp), %rdi
pushq $0x5
popq %rdx
movl %r14d, %esi
callq 0x286e
movq -0xf8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a86
testq %rax, %rax
jne 0x3b19
leaq -0xf0(%rbp), %rdi
pushq $0x6
popq %rdx
movl %r14d, %esi
callq 0x286e
movq -0xf0(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a86
testq %rax, %rax
je 0x3ba8
leaq -0xb8(%rbp), %rdi
pushq $0x3
popq %rdx
movl %r14d, %esi
callq 0x286e
movq -0xb8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a86
testq %rax, %rax
jne 0x3b92
leaq -0xb0(%rbp), %rdi
pushq $0x2
popq %rdx
movl %r14d, %esi
callq 0x286e
movq -0xb0(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a86
testq %rax, %rax
jne 0x3b92
leaq -0xa8(%rbp), %rdi
pushq $0x1
popq %rdx
movl %r14d, %esi
callq 0x286e
movq -0xa8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a86
testq %rax, %rax
je 0x3cc5
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
pushq $0x7
popq %rdx
movl %r14d, %esi
callq 0x286e
movq -0xe8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a86
testq %rax, %rax
je 0x3b19
leaq -0xe0(%rbp), %rdi
pushq $0x7
popq %rdx
movl %r14d, %esi
callq 0x286e
movq -0xe0(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a86
movq %rax, %rdi
callq 0x3830
cmpl $0x4, %eax
jne 0x3b19
leaq -0xd8(%rbp), %rdi
pushq $0x7
popq %rdx
movl %r14d, %esi
callq 0x286e
movq -0xd8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a86
movq %rax, %rdi
callq 0x379a
movq -0x40(%rbp), %rcx
cmpb %al, 0x8(%rcx)
jne 0x3b19
leaq -0xd0(%rbp), %rdi
pushq $0x7
popq %rdx
movl %r14d, %esi
callq 0x286e
movq -0xd0(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a86
movq %rax, %rdi
callq 0x3852
testb %al, %al
jne 0x3b19
leaq -0xc8(%rbp), %rdi
pushq $0x4
popq %rdx
movl %r14d, %esi
callq 0x286e
leaq -0xc0(%rbp), %rdi
pushq $0x6
popq %rdx
movl %r14d, %esi
callq 0x286e
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x3ffc
leaq -0x68(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x2cfa
leaq -0x68(%rbp), %rdi
callq 0x4072
jmp 0x3b19
leaq -0xa0(%rbp), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x286e
movq -0xa0(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a86
testq %rax, %rax
je 0x3b92
leaq -0x98(%rbp), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x286e
movq -0x98(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a86
movq %rax, %rdi
callq 0x3830
cmpl $0x4, %eax
jne 0x3b92
leaq -0x90(%rbp), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x286e
movq -0x90(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a86
movq %rax, %rdi
callq 0x379a
movq -0x40(%rbp), %rcx
cmpb %al, 0x8(%rcx)
jne 0x3b92
leaq -0x88(%rbp), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x286e
movq -0x88(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4a86
movq %rax, %rdi
callq 0x3852
testb %al, %al
jne 0x3b92
leaq -0x80(%rbp), %rdi
pushq $0x4
popq %rdx
movl %r14d, %esi
callq 0x286e
leaq -0x78(%rbp), %rdi
pushq $0x2
popq %rdx
movl %r14d, %esi
callq 0x286e
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x3ffc
leaq -0x68(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x2cfa
leaq -0x68(%rbp), %rdi
callq 0x4072
jmp 0x3b92
jmp 0x3de2
jmp 0x3de2
jmp 0x3df4
jmp 0x3df4
jmp 0x3df4
jmp 0x3df4
jmp 0x3df4
jmp 0x3de2
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x4072
jmp 0x3df7
jmp 0x3df4
jmp 0x3df4
movq %rax, %rbx
movq -0x38(%rbp), %rdi
callq 0x2a40
movq %rbx, %rdi
callq 0x21d0