// File: /workspace/github_cpp_makefile_star2_O1/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)
movb $0x30, %bpl
movl $0x7, %ebx
leaq 0x39db59(%rip), %r13    # 0x3bb2f0
testq %rbx, %rbx
js 0x1d850
movq %rbx, 0x18(%rsp)
leaq (,%rbx,8), %r15
xorl %ebx, %ebx
leaq (%rbx,%r15), %r12
cmpl $0x10, (%r14,%r12,4)
jne 0x1d7bf
incb %bpl
jmp 0x1d80d
cmpb $0x30, %bpl
je 0x1d7d6
movsbl %bpl, %esi
movq 0x8(%rsp), %rdi
callq 0x5330
movb $0x30, %bpl
movq 0x39db23(%rip), %rax    # 0x3bb300
cmpq %r13, %rax
je 0x1d7f9
movl (%r14,%r12,4), %r12d
cmpl %r12d, 0x24(%rax)
je 0x1d7fd
movq %rax, %rdi
callq 0x5470
cmpq %r13, %rax
jne 0x1d7e6
xorl %eax, %eax
jmp 0x1d800
movb 0x20(%rax), %al
movsbl %al, %esi
movq 0x8(%rsp), %rdi
callq 0x5330
incq %rbx
cmpq $0x8, %rbx
jne 0x1d7af
cmpb $0x30, %bpl
jne 0x1d823
movq 0x18(%rsp), %rbx
jmp 0x1d839
movsbl %bpl, %esi
movq 0x8(%rsp), %rdi
callq 0x5330
movb $0x30, %bpl
movq 0x18(%rsp), %rbx
decq %rbx
movq 0x8(%rsp), %rdi
movl $0x2f, %esi
callq 0x5330
jmp 0x1d797
cmpl $0x0, 0x1090(%r14)
leaq 0x14977(%rip), %rax     # 0x321d6
leaq 0x14974(%rip), %rsi     # 0x321da
cmoveq %rax, %rsi
movq 0x8(%rsp), %rdi
callq 0x5820
movq 0x1938(%r14), %rax
movl 0x10(%rax), %eax
testl %eax, %eax
je 0x1d94c
testb $0x1, %al
je 0x1d8b4
movb $0x4b, %al
cmpb $0x1, 0x1924(%r14)
jne 0x1d8a7
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
testb $0x4, 0x10(%rax)
je 0x1d8eb
movb $0x51, %al
cmpb $0x1, 0x1924(%r14)
jne 0x1d8de
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
testb $0x2, 0x10(%rax)
je 0x1d921
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
testb $0x8, 0x10(%rax)
je 0x1d95b
movb 0x1920(%r14), %al
addb $0x61, %al
cmpb $0x0, 0x1924(%r14)
movzbl %al, %ecx
movl $0x71, %eax
cmovnel %ecx, %eax
jmp 0x1d94e
movb $0x2d, %al
movsbl %al, %esi
movq 0x8(%rsp), %rdi
callq 0x5330
movq 0x1938(%r14), %rax
movl 0x20(%rax), %r12d
cmpl $0x40, %r12d
setne %bpl
je 0x1d9ce
movl %r12d, %eax
andb $0x7, %al
addb $0x61, %al
leaq 0x15(%rsp), %r14
movb %al, (%r14)
movl %r12d, %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 0xa7de
leaq 0x12c83(%rip), %rsi     # 0x30640
leaq 0x20(%rsp), %rdi
leaq 0x48(%rsp), %rdx
callq 0x20db4
jmp 0x1d9ef
leaq 0x30(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x13118(%rip), %rsi     # 0x30af6
leaq 0x13113(%rip), %rdx     # 0x30af8
leaq 0x20(%rsp), %rdi
callq 0xa7de
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 0x1da1e
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5400
cmpl $0x40, %r12d
je 0x1da3f
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1da3f
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
movb $0x1, %bpl
jmp 0x1da83
jmp 0x1daac
movq %rax, %r14
movb $0x1, %bpl
jmp 0x1daa3
movq %rax, %r14
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1da83
movq 0x30(%rsp), %rsi
incq %rsi
callq 0x5400
testb %bpl, %bpl
je 0x1daa3
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x1daa3
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x5400
testb %bpl, %bpl
jmp 0x1daaf
jmp 0x1daac
jmp 0x1daac
movq %rax, %r14
movq 0x8(%rsp), %rax
movq (%rax), %rdi
movq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x1dacc
movq (%rax), %rsi
incq %rsi
callq 0x5400
movq %r14, %rdi
callq 0x5790