// File: /workspace/github_cpp_makefile_star2_O3/ATOMIC-LICHESS[P]ATOMKRAFT/position.cpp
// Function: Position::to_fen[abi:cxx11]() const
const string Position::to_fen() const {

  string fen;
  Square sq;
  char emptyCnt = '0';

  for (Rank rank = RANK_8; rank >= RANK_1; rank--, fen += '/')
  {
      for (File file = FILE_A; file <= FILE_H; file++)
      {
          sq = make_square(file, rank);

          if (square_is_occupied(sq))
          {
              if (emptyCnt != '0')
              {
                  fen += emptyCnt;
                  emptyCnt = '0';
              }
              fen += pieceLetters.from_piece(piece_on(sq));
          } else
              emptyCnt++;
      }

      if (emptyCnt != '0')
      {
          fen += emptyCnt;
          emptyCnt = '0';
      }
  }

  fen += (sideToMove == WHITE ? " w " : " b ");

  if (st->castleRights != CASTLES_NONE)
  {
      if (can_castle_kingside(WHITE))
          fen += chess960 ? char(toupper(file_to_char(initialKRFile))) : 'K';

      if (can_castle_queenside(WHITE))
          fen += chess960 ? char(toupper(file_to_char(initialQRFile))) : 'Q';

      if (can_castle_kingside(BLACK))
          fen += chess960 ? file_to_char(initialKRFile) : 'k';

      if (can_castle_queenside(BLACK))
          fen += chess960 ? file_to_char(initialQRFile) : 'q';
  } else
      fen += '-';

  fen += (ep_square() == SQ_NONE ? " -" : " " + square_to_string(ep_square()));
  return fen;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rsi, %r14
leaq 0x10(%rdi), %rax
movq %rax, 0x40(%rsp)
movq %rax, (%rdi)
movq $0x0, 0x8(%rdi)
movq %rdi, 0x8(%rsp)
movb $0x0, 0x10(%rdi)
movl $0x7, %eax
movq %rax, 0x18(%rsp)
leaq 0x39e61d(%rip), %r13    # 0x3bc2f0
movq 0x18(%rsp), %rax
testq %rax, %rax
js 0x1dd83
leaq (,%rax,8), %rbp
movb $0x30, %al
xorl %r15d, %r15d
leaq (%r15,%rbp), %r12
movl (%r14,%r12,4), %ebx
cmpl $0x10, %ebx
jne 0x1dd08
incb %al
incq %r15
cmpq $0x8, %r15
jne 0x1dcee
jmp 0x1dd59
cmpb $0x30, %al
je 0x1dd1d
movsbl %al, %esi
movq 0x8(%rsp), %rdi
callq 0x5330
movl (%r14,%r12,4), %ebx
movq 0x39e5dc(%rip), %rax    # 0x3bc300
cmpq %r13, %rax
je 0x1dd38
cmpl %ebx, 0x24(%rax)
je 0x1dd3c
movq %rax, %rdi
callq 0x5470
jmp 0x1dd24
xorl %eax, %eax
jmp 0x1dd3f
movb 0x20(%rax), %al
movsbl %al, %esi
movq 0x8(%rsp), %rdi
callq 0x5330
incq %r15
movb $0x30, %al
cmpq $0x8, %r15
jne 0x1dcee
jmp 0x1dd6a
cmpb $0x30, %al
je 0x1dd6a
movsbl %al, %esi
movq 0x8(%rsp), %rdi
callq 0x5330
decq 0x18(%rsp)
movq 0x8(%rsp), %rdi
movl $0x2f, %esi
callq 0x5330
jmp 0x1dcd3
cmpl $0x0, 0x1090(%r14)
leaq 0x154c4(%rip), %rax     # 0x33256
leaq 0x154c1(%rip), %rsi     # 0x3325a
cmoveq %rax, %rsi
movq 0x8(%rsp), %rdi
callq 0x5820
movq 0x1938(%r14), %rax
movl 0x10(%rax), %eax
testl %eax, %eax
je 0x1de82
testb $0x1, %al
je 0x1ddf1
movb $0x4b, %al
cmpb $0x1, 0x1924(%r14)
jne 0x1ddda
movb 0x191c(%r14), %al
addb $0x61, %al
movsbl %al, %edi
callq 0x57f0
movsbl %al, %esi
movq 0x8(%rsp), %rdi
callq 0x5330
movq 0x1938(%r14), %rax
movl 0x10(%rax), %eax
testb $0x4, %al
je 0x1de29
movb $0x51, %al
cmpb $0x1, 0x1924(%r14)
jne 0x1de12
movb 0x1920(%r14), %al
addb $0x61, %al
movsbl %al, %edi
callq 0x57f0
movsbl %al, %esi
movq 0x8(%rsp), %rdi
callq 0x5330
movq 0x1938(%r14), %rax
movl 0x10(%rax), %eax
testb $0x2, %al
je 0x1de60
movb 0x191c(%r14), %al
addb $0x61, %al
movzbl %al, %eax
cmpb $0x0, 0x1924(%r14)
movl $0x6b, %ecx
cmovnel %eax, %ecx
movsbl %cl, %esi
movq 0x8(%rsp), %rdi
callq 0x5330
movq 0x1938(%r14), %rax
movl 0x10(%rax), %eax
testb $0x8, %al
je 0x1de91
movb 0x1920(%r14), %al
addb $0x61, %al
cmpb $0x0, 0x1924(%r14)
movzbl %al, %ecx
movl $0x71, %eax
cmovnel %ecx, %eax
jmp 0x1de84
movb $0x2d, %al
movsbl %al, %esi
movq 0x8(%rsp), %rdi
callq 0x5330
movq 0x1938(%r14), %rax
movl 0x20(%rax), %ebp
cmpl $0x40, %ebp
jne 0x1dec3
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x13cc6(%rip), %rsi     # 0x31b76
leaq 0x13cc1(%rip), %rdx     # 0x31b78
leaq 0x20(%rsp), %rdi
callq 0xad16
jmp 0x1df1d
movl %ebp, %eax
andb $0x7, %al
addb $0x61, %al
leaq 0x15(%rsp), %r14
movb %al, (%r14)
movl %ebp, %eax
shrl $0x3, %eax
addb $0x31, %al
movb %al, 0x1(%r14)
movb $0x0, 0x2(%r14)
leaq 0x58(%rsp), %rax
movq %rax, -0x10(%rax)
movq %r14, %rdi
callq 0x5190
leaq (%rsp,%rax), %rdx
addq $0x15, %rdx
leaq 0x48(%rsp), %rdi
movq %r14, %rsi
callq 0xad16
leaq 0x137b2(%rip), %rsi     # 0x316c0
leaq 0x20(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x212a3
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
movq 0x8(%rsp), %rdi
callq 0x5130
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1df4c
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5400
cmpl $0x40, %ebp
je 0x1df6c
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1df6c
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5400
movq 0x8(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x1dfac
jmp 0x1dfcd
jmp 0x1dfcd
movq %rax, %r14
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1dfa7
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5400
cmpl $0x40, %ebp
je 0x1dfd0
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1dfd0
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5400
jmp 0x1dfd0
jmp 0x1dfcd
jmp 0x1dfcd
movq %rax, %r14
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x1dfed
movq (%rax), %rsi
incq %rsi
callq 0x5400
movq %r14, %rdi
callq 0x5790
nop