// File: 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
subq $0x310, %rsp            # imm = 0x310
movq %rdi, -0x1a8(%rbp)
movq %rdi, %rax
movq %rax, -0x1a0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x198(%rbp)
movb $0x0, -0x19(%rbp)
callq 0x3220
movq -0x198(%rbp), %rdi
callq 0x57d0
movb %al, -0x189(%rbp)
jmp 0x5b30
movb -0x189(%rbp), %al
testb $0x1, %al
jne 0x648f
jmp 0x5b40
movq -0x198(%rbp), %rdi
addq $0x10, %rdi
callq 0x2ee0
movl %eax, -0x1ac(%rbp)
jmp 0x5b58
movq -0x198(%rbp), %rdi
movl -0x1ac(%rbp), %eax
movl %eax, -0x30(%rbp)
addq $0x10, %rdi
callq 0x2ef0
movl %eax, -0x1b0(%rbp)
jmp 0x5b79
movl -0x1b0(%rbp), %eax
movl %eax, -0x34(%rbp)
movl $0xffffffff, -0x38(%rbp) # imm = 0xFFFFFFFF
cmpl $0x2, -0x38(%rbp)
jge 0x5e41
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
cmpl $0x2, -0x3c(%rbp)
jge 0x5e31
movl -0x30(%rbp), %eax
addl -0x38(%rbp), %eax
movl %eax, -0x40(%rbp)
movl -0x34(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x40(%rbp)
jl 0x5e21
cmpl $0x8, -0x40(%rbp)
jge 0x5e21
cmpl $0x0, -0x44(%rbp)
jl 0x5e21
cmpl $0x8, -0x44(%rbp)
jge 0x5e21
movq -0x18(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movl -0x40(%rbp), %esi
movl -0x44(%rbp), %edx
leaq -0x4c(%rbp), %rdi
callq 0x2e50
jmp 0x5bfa
movq -0x1b8(%rbp), %rdi
movq -0x4c(%rbp), %rsi
callq 0x7de0
movq %rax, -0x1c0(%rbp)
jmp 0x5c13
movq -0x1c0(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x1c1(%rbp)
je 0x5cb8
movq -0x18(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movl -0x40(%rbp), %esi
movl -0x44(%rbp), %edx
leaq -0x54(%rbp), %rdi
callq 0x2e50
jmp 0x5c48
movq -0x1d0(%rbp), %rdi
movq -0x54(%rbp), %rsi
callq 0x7de0
movq %rax, -0x1d8(%rbp)
jmp 0x5c61
movq -0x1d8(%rbp), %rdi
callq 0x5790
movb %al, -0x1d9(%rbp)
jmp 0x5c75
movq -0x198(%rbp), %rdi
movb -0x1d9(%rbp), %al
movzbl %al, %eax
andl $0x1, %eax
movl %eax, -0x1e0(%rbp)
callq 0x5790
movb %al, -0x1da(%rbp)
jmp 0x5c9b
movl -0x1e0(%rbp), %eax
movb -0x1da(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
setne %al
movb %al, -0x1c1(%rbp)
movb -0x1c1(%rbp), %al
testb $0x1, %al
jne 0x5cc7
jmp 0x5d4d
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
leaq -0x80(%rbp), %rdi
callq 0x2e50
jmp 0x5cd8
movl -0x40(%rbp), %esi
movl -0x44(%rbp), %edx
leaq -0x88(%rbp), %rdi
callq 0x2e50
jmp 0x5cec
movq -0x80(%rbp), %rsi
movq -0x88(%rbp), %rdx
leaq -0x78(%rbp), %rdi
callq 0x68b0
jmp 0x5d02
movq -0x1a8(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x3ca0
jmp 0x5d14
leaq -0x78(%rbp), %rdi
callq 0x69d0
jmp 0x5e1f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
jmp 0x64b5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x69d0
jmp 0x64b5
movq -0x18(%rbp), %rax
movq %rax, -0x1e8(%rbp)
movl -0x40(%rbp), %esi
movl -0x44(%rbp), %edx
leaq -0x90(%rbp), %rdi
callq 0x2e50
jmp 0x5d6c
movq -0x1e8(%rbp), %rdi
movq -0x90(%rbp), %rsi
callq 0x7de0
movq %rax, -0x1f0(%rbp)
jmp 0x5d88
movq -0x1f0(%rbp), %rax
cmpq $0x0, %rax
jne 0x5e1d
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
leaq -0xb8(%rbp), %rdi
callq 0x2e50
jmp 0x5dad
movl -0x40(%rbp), %esi
movl -0x44(%rbp), %edx
leaq -0xc0(%rbp), %rdi
callq 0x2e50
jmp 0x5dc1
movq -0xb8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
leaq -0xb0(%rbp), %rdi
callq 0x68b0
jmp 0x5ddd
movq -0x1a8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3ca0
jmp 0x5df2
leaq -0xb0(%rbp), %rdi
callq 0x69d0
jmp 0x5e1d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x69d0
jmp 0x64b5
jmp 0x5e1f
jmp 0x5e21
jmp 0x5e23
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x5b9a
jmp 0x5e33
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x5b89
cmpl $0x0, -0x30(%rbp)
je 0x5e51
cmpl $0x7, -0x30(%rbp)
jne 0x648d
cmpl $0x4, -0x34(%rbp)
jne 0x648d
movq -0x198(%rbp), %rdi
callq 0x5950
movb %al, -0x1f1(%rbp)
jmp 0x5e6f
movb -0x1f1(%rbp), %al
testb $0x1, %al
jne 0x648d
jmp 0x5e7f
movq -0x18(%rbp), %rax
movq %rax, -0x200(%rbp)
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
incl %edx
leaq -0xc8(%rbp), %rdi
callq 0x2e50
jmp 0x5ea0
movq -0x200(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x7de0
movq %rax, -0x208(%rbp)
jmp 0x5ebc
movq -0x208(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x209(%rbp)
jne 0x60c5
movq -0x18(%rbp), %rax
movq %rax, -0x218(%rbp)
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
addl $0x2, %edx
leaq -0xd0(%rbp), %rdi
callq 0x2e50
jmp 0x5ef7
movq -0x218(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x7de0
movq %rax, -0x220(%rbp)
jmp 0x5f13
movq -0x220(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x209(%rbp)
jne 0x60c5
movq -0x18(%rbp), %rax
movq %rax, -0x228(%rbp)
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
addl $0x3, %edx
leaq -0xd8(%rbp), %rdi
callq 0x2e50
jmp 0x5f4e
movq -0x228(%rbp), %rdi
movq -0xd8(%rbp), %rsi
callq 0x7de0
movq %rax, -0x230(%rbp)
jmp 0x5f6a
movq -0x230(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x209(%rbp)
je 0x60c5
movq -0x18(%rbp), %rax
movq %rax, -0x238(%rbp)
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
addl $0x3, %edx
leaq -0xe0(%rbp), %rdi
callq 0x2e50
jmp 0x5fa5
movq -0x238(%rbp), %rdi
movq -0xe0(%rbp), %rsi
callq 0x7de0
movq %rax, -0x240(%rbp)
jmp 0x5fc1
movq -0x240(%rbp), %rdi
callq 0x58f0
movl %eax, -0x244(%rbp)
jmp 0x5fd5
movl -0x244(%rbp), %ecx
xorl %eax, %eax
cmpl $0x4, %ecx
movb %al, -0x209(%rbp)
jne 0x60c5
movq -0x18(%rbp), %rax
movq %rax, -0x250(%rbp)
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
addl $0x3, %edx
leaq -0xe8(%rbp), %rdi
callq 0x2e50
jmp 0x600e
movq -0x250(%rbp), %rdi
movq -0xe8(%rbp), %rsi
callq 0x7de0
movq %rax, -0x258(%rbp)
jmp 0x602a
movq -0x258(%rbp), %rdi
callq 0x5790
movb %al, -0x259(%rbp)
jmp 0x603e
movq -0x198(%rbp), %rax
movb -0x259(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
movb 0x8(%rax), %al
andb $0x1, %al
movzbl %al, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x209(%rbp)
jne 0x60c5
movq -0x18(%rbp), %rax
movq %rax, -0x268(%rbp)
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
addl $0x3, %edx
leaq -0xf0(%rbp), %rdi
callq 0x2e50
jmp 0x6087
movq -0x268(%rbp), %rdi
movq -0xf0(%rbp), %rsi
callq 0x7de0
movq %rax, -0x270(%rbp)
jmp 0x60a3
movq -0x270(%rbp), %rdi
callq 0x5950
movb %al, -0x271(%rbp)
jmp 0x60b7
movb -0x271(%rbp), %al
xorb $-0x1, %al
movb %al, -0x209(%rbp)
movb -0x209(%rbp), %al
testb $0x1, %al
jne 0x60d4
jmp 0x615b
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
leaq -0x118(%rbp), %rdi
callq 0x2e50
jmp 0x60e8
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
addl $0x2, %edx
leaq -0x120(%rbp), %rdi
callq 0x2e50
jmp 0x60ff
movq -0x118(%rbp), %rsi
movq -0x120(%rbp), %rdx
leaq -0x110(%rbp), %rdi
callq 0x68b0
jmp 0x611b
movq -0x1a8(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x3ca0
jmp 0x6130
leaq -0x110(%rbp), %rdi
callq 0x69d0
jmp 0x615b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x69d0
jmp 0x64b5
movq -0x18(%rbp), %rax
movq %rax, -0x280(%rbp)
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
decl %edx
leaq -0x128(%rbp), %rdi
callq 0x2e50
jmp 0x617c
movq -0x280(%rbp), %rdi
movq -0x128(%rbp), %rsi
callq 0x7de0
movq %rax, -0x288(%rbp)
jmp 0x6198
movq -0x288(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x289(%rbp)
jne 0x63f8
movq -0x18(%rbp), %rax
movq %rax, -0x298(%rbp)
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
addl $-0x2, %edx
leaq -0x130(%rbp), %rdi
callq 0x2e50
jmp 0x61d3
movq -0x298(%rbp), %rdi
movq -0x130(%rbp), %rsi
callq 0x7de0
movq %rax, -0x2a0(%rbp)
jmp 0x61ef
movq -0x2a0(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x289(%rbp)
jne 0x63f8
movq -0x18(%rbp), %rax
movq %rax, -0x2a8(%rbp)
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
addl $-0x3, %edx
leaq -0x138(%rbp), %rdi
callq 0x2e50
jmp 0x622a
movq -0x2a8(%rbp), %rdi
movq -0x138(%rbp), %rsi
callq 0x7de0
movq %rax, -0x2b0(%rbp)
jmp 0x6246
movq -0x2b0(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x289(%rbp)
jne 0x63f8
movq -0x18(%rbp), %rax
movq %rax, -0x2b8(%rbp)
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
addl $-0x4, %edx
leaq -0x140(%rbp), %rdi
callq 0x2e50
jmp 0x6281
movq -0x2b8(%rbp), %rdi
movq -0x140(%rbp), %rsi
callq 0x7de0
movq %rax, -0x2c0(%rbp)
jmp 0x629d
movq -0x2c0(%rbp), %rcx
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x289(%rbp)
je 0x63f8
movq -0x18(%rbp), %rax
movq %rax, -0x2c8(%rbp)
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
addl $-0x4, %edx
leaq -0x148(%rbp), %rdi
callq 0x2e50
jmp 0x62d8
movq -0x2c8(%rbp), %rdi
movq -0x148(%rbp), %rsi
callq 0x7de0
movq %rax, -0x2d0(%rbp)
jmp 0x62f4
movq -0x2d0(%rbp), %rdi
callq 0x58f0
movl %eax, -0x2d4(%rbp)
jmp 0x6308
movl -0x2d4(%rbp), %ecx
xorl %eax, %eax
cmpl $0x4, %ecx
movb %al, -0x289(%rbp)
jne 0x63f8
movq -0x18(%rbp), %rax
movq %rax, -0x2e0(%rbp)
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
addl $-0x4, %edx
leaq -0x150(%rbp), %rdi
callq 0x2e50
jmp 0x6341
movq -0x2e0(%rbp), %rdi
movq -0x150(%rbp), %rsi
callq 0x7de0
movq %rax, -0x2e8(%rbp)
jmp 0x635d
movq -0x2e8(%rbp), %rdi
callq 0x5790
movb %al, -0x2e9(%rbp)
jmp 0x6371
movq -0x198(%rbp), %rax
movb -0x2e9(%rbp), %cl
andb $0x1, %cl
movzbl %cl, %ecx
movb 0x8(%rax), %al
andb $0x1, %al
movzbl %al, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x289(%rbp)
jne 0x63f8
movq -0x18(%rbp), %rax
movq %rax, -0x2f8(%rbp)
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
addl $-0x4, %edx
leaq -0x158(%rbp), %rdi
callq 0x2e50
jmp 0x63ba
movq -0x2f8(%rbp), %rdi
movq -0x158(%rbp), %rsi
callq 0x7de0
movq %rax, -0x300(%rbp)
jmp 0x63d6
movq -0x300(%rbp), %rdi
callq 0x5950
movb %al, -0x301(%rbp)
jmp 0x63ea
movb -0x301(%rbp), %al
xorb $-0x1, %al
movb %al, -0x289(%rbp)
movb -0x289(%rbp), %al
testb $0x1, %al
jne 0x6407
jmp 0x648b
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
leaq -0x180(%rbp), %rdi
callq 0x2e50
jmp 0x641b
movl -0x30(%rbp), %esi
movl -0x34(%rbp), %edx
addl $-0x2, %edx
leaq -0x188(%rbp), %rdi
callq 0x2e50
jmp 0x6432
movq -0x180(%rbp), %rsi
movq -0x188(%rbp), %rdx
leaq -0x178(%rbp), %rdi
callq 0x68b0
jmp 0x644e
movq -0x1a8(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x3ca0
jmp 0x6463
leaq -0x178(%rbp), %rdi
callq 0x69d0
jmp 0x648b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x28(%rbp)
movl %eax, -0x2c(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x69d0
jmp 0x64b5
jmp 0x648d
jmp 0x648f
movb $0x1, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
jne 0x64a5
movq -0x1a8(%rbp), %rdi
callq 0x3240
movq -0x1a0(%rbp), %rax
addq $0x310, %rsp            # imm = 0x310
popq %rbp
retq
movq -0x1a8(%rbp), %rdi
callq 0x3240
movq -0x28(%rbp), %rdi
callq 0x2260
nopw (%rax,%rax)