// File: /workspace/github_cpp_makefile_star2_O1/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 0x37c6
testb %al, %al
jne 0x3bce
movq -0x40(%rbp), %rax
leaq 0x10(%rax), %rbx
movq %rbx, %rdi
callq 0x2956
movl %eax, %r14d
movq %rbx, %rdi
callq 0x295e
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 0x3aaa
leaq -0x130(%rbp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x291e
movq -0x130(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c3c
testq %rax, %rax
je 0x3a1f
leaq -0x128(%rbp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x291e
movq -0x128(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c3c
movq %rax, %rdi
callq 0x37b2
movl %eax, %r15d
movq -0x40(%rbp), %rdi
callq 0x37b2
cmpb %al, %r15b
je 0x3a1f
leaq -0x120(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl %r13d, %edx
callq 0x291e
leaq -0x118(%rbp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x291e
movq -0x120(%rbp), %rsi
movq -0x118(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x4058
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
leaq -0x68(%rbp), %r15
movq %r15, %rsi
callq 0x2e78
jmp 0x3a93
leaq -0x110(%rbp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x291e
movq -0x110(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c3c
testq %rax, %rax
jne 0x3aaa
leaq -0x108(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl %r13d, %edx
callq 0x291e
leaq -0x100(%rbp), %rdi
movl %r14d, %esi
movl %ebx, %edx
callq 0x291e
movq -0x108(%rbp), %rsi
movq -0x100(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x4058
movq -0x38(%rbp), %rbx
movq %rbx, %rdi
leaq -0x68(%rbp), %r15
movq %r15, %rsi
callq 0x2e78
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2050
incq 0x10(%rbx)
movq %r15, %rdi
callq 0x40d8
incl %r12d
cmpl $0x2, %r12d
jne 0x394f
movq -0x70(%rbp), %rax
incl %eax
cmpl $0x2, %eax
movq -0x48(%rbp), %r14
jne 0x3942
testl %r14d, %r14d
sete %al
cmpl $0x7, %r14d
sete %cl
orb %al, %cl
cmpl $0x4, %r13d
sete %al
testb %al, %cl
je 0x3bce
movq -0x40(%rbp), %rdi
callq 0x386a
testb %al, %al
jne 0x3bce
leaq -0xf8(%rbp), %rdi
movl %r14d, %esi
movl $0x5, %edx
callq 0x291e
movq -0xf8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c3c
testq %rax, %rax
jne 0x3b4f
leaq -0xf0(%rbp), %rdi
movl %r14d, %esi
movl $0x6, %edx
callq 0x291e
movq -0xf0(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c3c
testq %rax, %rax
je 0x3be4
leaq -0xb8(%rbp), %rdi
movl %r14d, %esi
movl $0x3, %edx
callq 0x291e
movq -0xb8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c3c
testq %rax, %rax
jne 0x3bce
leaq -0xb0(%rbp), %rdi
movl %r14d, %esi
movl $0x2, %edx
callq 0x291e
movq -0xb0(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c3c
testq %rax, %rax
jne 0x3bce
leaq -0xa8(%rbp), %rdi
movl %r14d, %esi
movl $0x1, %edx
callq 0x291e
movq -0xa8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c3c
testq %rax, %rax
je 0x3d0d
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 0x291e
movq -0xe8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c3c
testq %rax, %rax
je 0x3b4f
leaq -0xe0(%rbp), %rdi
movl %r14d, %esi
movl $0x7, %edx
callq 0x291e
movq -0xe0(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c3c
movq %rax, %rdi
callq 0x3848
cmpl $0x4, %eax
jne 0x3b4f
leaq -0xd8(%rbp), %rdi
movl %r14d, %esi
movl $0x7, %edx
callq 0x291e
movq -0xd8(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c3c
movq %rax, %rdi
callq 0x37b2
movq -0x40(%rbp), %rcx
cmpb %al, 0x8(%rcx)
jne 0x3b4f
leaq -0xd0(%rbp), %rdi
movl %r14d, %esi
movl $0x7, %edx
callq 0x291e
movq -0xd0(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c3c
movq %rax, %rdi
callq 0x386a
testb %al, %al
jne 0x3b4f
leaq -0xc8(%rbp), %rdi
movl %r14d, %esi
movl $0x4, %edx
callq 0x291e
leaq -0xc0(%rbp), %rdi
movl %r14d, %esi
movl $0x6, %edx
callq 0x291e
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x4058
leaq -0x68(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x35fc
leaq -0x68(%rbp), %rdi
callq 0x40d8
jmp 0x3b4f
leaq -0xa0(%rbp), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x291e
movq -0xa0(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c3c
testq %rax, %rax
je 0x3bce
leaq -0x98(%rbp), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x291e
movq -0x98(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c3c
movq %rax, %rdi
callq 0x3848
cmpl $0x4, %eax
jne 0x3bce
leaq -0x90(%rbp), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x291e
movq -0x90(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c3c
movq %rax, %rdi
callq 0x37b2
movq -0x40(%rbp), %rcx
cmpb %al, 0x8(%rcx)
jne 0x3bce
leaq -0x88(%rbp), %rdi
movl %r14d, %esi
xorl %edx, %edx
callq 0x291e
movq -0x88(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x4c3c
movq %rax, %rdi
callq 0x386a
testb %al, %al
jne 0x3bce
leaq -0x80(%rbp), %rdi
movl %r14d, %esi
movl $0x4, %edx
callq 0x291e
leaq -0x78(%rbp), %rdi
movl %r14d, %esi
movl $0x2, %edx
callq 0x291e
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
leaq -0x68(%rbp), %rdi
callq 0x4058
leaq -0x68(%rbp), %rsi
movq -0x38(%rbp), %rdi
callq 0x35fc
leaq -0x68(%rbp), %rdi
callq 0x40d8
jmp 0x3bce
jmp 0x3e2e
jmp 0x3e2e
jmp 0x3e40
jmp 0x3e40
jmp 0x3e40
jmp 0x3e40
jmp 0x3e40
jmp 0x3e2e
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x40d8
jmp 0x3e43
jmp 0x3e40
jmp 0x3e40
movq %rax, %rbx
movq -0x38(%rbp), %rdi
callq 0x2b00
movq %rbx, %rdi
callq 0x21d0