// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, (%rdi)
andq $0x0, 0x8(%rdi)
movb $0x0, 0x10(%rdi)
movq %rsi, (%rsp)
leaq 0xe0(%rsi), %r15
pushq $0x7
popq %r12
pushq $0x2f
popq %rbp
testq %r12, %r12
js 0x1810d
movb $0x30, %r14b
xorl %r13d, %r13d
movsbl %r14b, %esi
cmpq $0x8, %r13
je 0x180ec
movl (%r15,%r13,4), %edi
cmpl $0x10, %edi
jne 0x180c2
incb %r14b
jmp 0x180e7
cmpb $0x30, %r14b
je 0x180d4
movq %rbx, %rdi
callq 0x5320
movl (%r15,%r13,4), %edi
callq 0x182d0
movb $0x30, %r14b
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5320
incq %r13
jmp 0x180aa
cmpb $0x30, %r14b
je 0x180fa
movq %rbx, %rdi
callq 0x5320
decq %r12
addq $-0x20, %r15
movq %rbx, %rdi
movl %ebp, %esi
callq 0x5320
jmp 0x1809f
movq (%rsp), %r14
cmpl $0x0, 0x1090(%r14)
leaq 0x11fa6(%rip), %rax     # 0x2a0c6
leaq 0x11fa3(%rip), %rsi     # 0x2a0ca
cmoveq %rax, %rsi
movq %rbx, %rdi
callq 0x57f0
movq 0x1938(%r14), %rax
movl 0x10(%rax), %eax
testl %eax, %eax
je 0x18204
testb $0x1, %al
je 0x1817b
movb $0x4b, %al
cmpb $0x1, 0x1924(%r14)
jne 0x18166
movb 0x191c(%r14), %al
addb $0x61, %al
movsbl %al, %edi
callq 0x57d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5320
movq 0x1938(%r14), %rax
movl 0x10(%rax), %eax
testb $0x4, %al
je 0x181b1
movb $0x51, %al
cmpb $0x1, 0x1924(%r14)
jne 0x1819c
movb 0x1920(%r14), %al
addb $0x61, %al
movsbl %al, %edi
callq 0x57d0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5320
movq 0x1938(%r14), %rax
movl 0x10(%rax), %eax
testb $0x2, %al
je 0x181e4
movb 0x191c(%r14), %al
addb $0x61, %al
movzbl %al, %eax
cmpb $0x0, 0x1924(%r14)
pushq $0x6b
popq %rcx
cmovnel %eax, %ecx
movsbl %cl, %esi
movq %rbx, %rdi
callq 0x5320
movq 0x1938(%r14), %rax
movl 0x10(%rax), %eax
testb $0x8, %al
je 0x18211
movb 0x1920(%r14), %al
addb $0x61, %al
cmpb $0x0, 0x1924(%r14)
movzbl %al, %ecx
pushq $0x71
popq %rax
cmovnel %ecx, %eax
jmp 0x18206
movb $0x2d, %al
movsbl %al, %esi
movq %rbx, %rdi
callq 0x5320
movq 0x1938(%r14), %rax
movl 0x20(%rax), %ebp
cmpl $0x40, %ebp
jne 0x18238
leaq 0x107ef(%rip), %rsi     # 0x28a16
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x9c42
jmp 0x1825a
leaq 0x8(%rsp), %rdi
movl %ebp, %esi
callq 0x13fec
leaq 0x10315(%rip), %rsi     # 0x28560
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x1ab28
leaq 0x28(%rsp), %rsi
movq %rbx, %rdi
callq 0x5830
leaq 0x28(%rsp), %rdi
callq 0x5858
cmpl $0x40, %ebp
je 0x18280
leaq 0x8(%rsp), %rdi
callq 0x5858
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r14
jmp 0x182ad
jmp 0x182bd
jmp 0x182bd
movq %rax, %r14
leaq 0x28(%rsp), %rdi
callq 0x5858
cmpl $0x40, %ebp
je 0x182c0
leaq 0x8(%rsp), %rdi
callq 0x5858
jmp 0x182c0
jmp 0x182bd
jmp 0x182bd
movq %rax, %r14
movq %rbx, %rdi
callq 0x5858
movq %r14, %rdi
callq 0x5780