// File: /workspace/github_cpp_makefile_star2_O2/niekh1234[P]nnchesslib/board.cpp
// Function: nnchesslib::ChessBoard::convertToFen[abi:cxx11]()
std::string ChessBoard::convertToFen()
{
    std::string fen = "";
    for (int y = 0; y <= 7; y++)
    {
        int spaces = 0;
        for (int x = 0; x <= 7; x++)
        {
            std::string c = getPieceChar((7-y)*8 + x);
            if (c != "0")
            {
                if (spaces > 0)
                {
                    fen += std::to_string(spaces);
                    spaces = 0;
                }
                fen += c;
            }
            else
            {
                spaces++;
            }
        }
        if (spaces > 0)
        {
            fen += std::to_string(spaces);
            spaces = 0;
        }
        fen += "/";
    }
    fen.pop_back();
    fen += " ";

    // Add side to move
    boardinfo.whiteToMove ? fen += "w " : fen += "b ";
    
    // Add castling rights
    if (!(boardinfo.whiteCastleLong || boardinfo.whiteCastleShort || boardinfo.blackCastleLong || boardinfo.blackCastleShort))
        fen += "- ";
    else
    {
        if (boardinfo.whiteCastleShort) fen += "K";
        if (boardinfo.whiteCastleLong) fen += "Q";
        if (boardinfo.blackCastleShort) fen += "k";
        if (boardinfo.blackCastleLong) fen += "q";
        fen += " ";
    }

    // Add en passant
    fen += "- ";


    // Add halfmove clock and fullmove number
    fen += std::to_string(boardinfo.fiftyMoveRule) + " ";
    fen += std::to_string(boardinfo.plyCount);

    return fen;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, -0x38(%rbp)
leaq 0x3673(%rip), %rsi      # 0x878f
leaq -0x60(%rbp), %r15
movq %rdi, -0x30(%rbp)
movq %r15, %rdx
callq 0x2f52
xorl %r14d, %r14d
pushq $0x38
popq %r12
cmpl $0x8, %r14d
je 0x51f6
movl %r14d, -0x3c(%rbp)
xorl %ebx, %ebx
xorl %r14d, %r14d
cmpl $0x8, %r14d
je 0x51b4
leal (%r12,%r14), %edx
movq %r15, %rdi
movq -0x38(%rbp), %rsi
callq 0x4ec8
movq %r15, %rdi
leaq 0x36f1(%rip), %rsi      # 0x8857
callq 0x5720
testb %al, %al
je 0x51a5
testl %ebx, %ebx
jle 0x5197
leaq -0x80(%rbp), %r13
movq %r13, %rdi
movl %ebx, %esi
callq 0x5775
movq -0x30(%rbp), %rdi
movq %r13, %rsi
callq 0x22e0
movq %r13, %rdi
callq 0x2308
xorl %ebx, %ebx
movq -0x30(%rbp), %rdi
movq %r15, %rsi
callq 0x22e0
jmp 0x51a7
incl %ebx
movq %r15, %rdi
callq 0x2308
incl %r14d
jmp 0x5146
testl %ebx, %ebx
movl -0x3c(%rbp), %r14d
jle 0x51da
movq %r15, %rdi
movl %ebx, %esi
callq 0x5775
movq -0x30(%rbp), %rdi
movq %r15, %rsi
callq 0x22e0
movq %r15, %rdi
callq 0x2308
movq -0x30(%rbp), %rdi
leaq 0x3674(%rip), %rsi      # 0x8859
callq 0x22b0
incl %r14d
addl $-0x8, %r12d
jmp 0x5133
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
callq 0x21d0
leaq 0x359e(%rip), %r15      # 0x87a7
movq %rbx, %rdi
movq %r15, %rsi
callq 0x22b0
leaq 0x3640(%rip), %rax      # 0x885b
leaq 0x3541(%rip), %rsi      # 0x8763
movq -0x38(%rbp), %rcx
cmpb $0x0, 0x40(%rcx)
cmovneq %rax, %rsi
movq -0x30(%rbp), %rdi
callq 0x22b0
movq -0x38(%rbp), %rax
movb 0x41(%rax), %cl
movb 0x42(%rax), %al
testb %al, %al
jne 0x5262
testb $0x1, %cl
jne 0x5262
movq -0x38(%rbp), %rdx
cmpb $0x0, 0x44(%rdx)
jne 0x5262
movq -0x38(%rbp), %rdx
cmpb $0x0, 0x43(%rdx)
je 0x5360
testb $0x1, %cl
je 0x527e
leaq 0x355a(%rip), %rsi      # 0x87c8
movq -0x30(%rbp), %rdi
callq 0x22b0
movq -0x38(%rbp), %rax
movb 0x42(%rax), %al
testb $0x1, %al
je 0x5292
leaq 0x345e(%rip), %rsi      # 0x86e7
movq -0x30(%rbp), %rdi
callq 0x22b0
movq -0x38(%rbp), %rax
cmpb $0x1, 0x43(%rax)
jne 0x52ac
leaq 0x343a(%rip), %rsi      # 0x86dd
movq -0x30(%rbp), %rdi
callq 0x22b0
movq -0x38(%rbp), %rax
cmpb $0x1, 0x44(%rax)
jne 0x52c6
leaq 0x3427(%rip), %rsi      # 0x86e4
movq -0x30(%rbp), %rdi
callq 0x22b0
movq -0x30(%rbp), %rdi
movq %r15, %rsi
callq 0x22b0
leaq 0x34cd(%rip), %rsi      # 0x87a6
movq -0x30(%rbp), %rdi
callq 0x22b0
movq -0x38(%rbp), %rax
movl 0x48(%rax), %esi
leaq -0x80(%rbp), %rdi
callq 0x5775
leaq 0x34ae(%rip), %rdx      # 0x87a7
leaq -0x60(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x57d5
leaq -0x60(%rbp), %rsi
movq -0x30(%rbp), %rdi
callq 0x22e0
leaq -0x60(%rbp), %rdi
callq 0x2308
leaq -0x80(%rbp), %rdi
callq 0x2308
movq -0x38(%rbp), %rax
movl 0x4c(%rax), %esi
leaq -0x60(%rbp), %rdi
callq 0x5775
leaq -0x60(%rbp), %rsi
movq -0x30(%rbp), %rbx
movq %rbx, %rdi
callq 0x22e0
leaq -0x60(%rbp), %rdi
callq 0x2308
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x343f(%rip), %r15      # 0x87a6
jmp 0x52c6
jmp 0x53a6
jmp 0x53a1
movq %rax, %r14
leaq -0x60(%rbp), %rdi
callq 0x2308
jmp 0x5381
movq %rax, %r14
leaq -0x80(%rbp), %rdi
jmp 0x53ad
jmp 0x53a1
jmp 0x53a1
jmp 0x53a1
jmp 0x53a6
jmp 0x53a1
movq %rax, %r14
leaq -0x80(%rbp), %rdi
callq 0x2308
jmp 0x53a9
jmp 0x53a6
movq %rax, %r14
jmp 0x53b2
movq %rax, %r14
leaq -0x60(%rbp), %rdi
callq 0x2308
movq -0x30(%rbp), %rdi
callq 0x2308
movq %r14, %rdi
callq 0x2290
nop