// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movq %rsi, -0x80(%rbp)
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, -0x30(%rbp)
movq %rax, (%rdi)
leaq 0x3a87(%rip), %rdx      # 0x976f
movq %rdx, %rsi
callq 0x6688
xorl %eax, %eax
leaq -0x50(%rbp), %r15
movq %rbx, -0x58(%rbp)
movq %rax, -0x88(%rbp)
leal (,%rax,8), %r14d
xorl %r12d, %r12d
xorl %r13d, %r13d
movl %r12d, %edx
subl %r14d, %edx
addl $0x38, %edx
movq %r15, %rdi
movq -0x80(%rbp), %rsi
callq 0x59da
movq %r15, %rdi
leaq 0x3b09(%rip), %rsi      # 0x9837
callq 0x2050
testl %eax, %eax
je 0x5d86
testl %r13d, %r13d
jle 0x5de8
movl $0x1, %ebx
cmpl $0xa, %r13d
jb 0x5d92
movl $0x4, %ebx
movl %r13d, %eax
cmpl $0x63, %eax
jbe 0x5d8b
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x5d90
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x5d92
movl %eax, %ecx
movl $0xd1b71759, %edx       # imm = 0xD1B71759
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %ebx
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x5d53
addl $-0x3, %ebx
jmp 0x5d92
incl %r13d
jmp 0x5df8
addl $-0x2, %ebx
jmp 0x5d92
decl %ebx
movl %ebx, %esi
leaq -0x68(%rbp), %rax
movq %rax, -0x78(%rbp)
leaq -0x78(%rbp), %rdi
movl $0x2d, %edx
callq 0x2190
movq -0x78(%rbp), %rdi
movl %ebx, %esi
movl %r13d, %edx
callq 0x6615
movq -0x78(%rbp), %rsi
movq -0x70(%rbp), %rdx
movq -0x58(%rbp), %rbx
movq %rbx, %rdi
callq 0x2060
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x5de5
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2150
xorl %r13d, %r13d
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %rbx, %rdi
callq 0x2060
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x5e11
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
incl %r12d
cmpl $0x8, %r12d
jne 0x5d0f
testl %r13d, %r13d
leaq -0x40(%rbp), %r14
jle 0x5ec2
movl $0x1, %ebx
cmpl $0xa, %r13d
jb 0x5e78
movl $0x4, %ebx
movl %r13d, %eax
cmpl $0x63, %eax
jbe 0x5e71
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x5e76
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x5e78
movl %eax, %ecx
movl $0xd1b71759, %edx       # imm = 0xD1B71759
imulq %rdx, %rcx
shrq $0x2d, %rcx
addl $0x4, %ebx
cmpl $0x1869f, %eax          # imm = 0x1869F
movl %ecx, %eax
ja 0x5e3e
addl $-0x3, %ebx
jmp 0x5e78
addl $-0x2, %ebx
jmp 0x5e78
decl %ebx
movl %ebx, %esi
movq %r14, -0x50(%rbp)
movq %r15, %rdi
movl $0x2d, %edx
callq 0x2190
movq -0x50(%rbp), %rdi
movl %ebx, %esi
movl %r13d, %edx
callq 0x6615
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq -0x58(%rbp), %rbx
movq %rbx, %rdi
callq 0x2060
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x5ec2
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
movq %rbx, %rdi
leaq 0x396d(%rip), %rsi      # 0x9839
callq 0x22a0
movq -0x88(%rbp), %rax
incl %eax
cmpl $0x8, %eax
jne 0x5cfa
movq %rbx, %rdi
callq 0x21a0
leaq 0x3895(%rip), %r15      # 0x9787
movq %rbx, %rdi
movq %r15, %rsi
callq 0x22a0
movq -0x80(%rbp), %r12
leaq 0x3933(%rip), %rax      # 0x983b
leaq 0x3834(%rip), %rsi      # 0x9743
cmpb $0x0, 0x40(%r12)
cmovneq %rax, %rsi
movq %rbx, %rdi
callq 0x22a0
cmpb $0x0, 0x42(%r12)
jne 0x5f45
cmpb $0x0, 0x41(%r12)
jne 0x5f45
cmpb $0x0, 0x44(%r12)
jne 0x5f45
cmpb $0x0, 0x43(%r12)
je 0x61b3
cmpb $0x1, 0x41(%r12)
jne 0x5f5c
leaq 0x3854(%rip), %rsi      # 0x97a8
movq %rbx, %rdi
callq 0x22a0
cmpb $0x1, 0x42(%r12)
jne 0x5f73
leaq 0x375c(%rip), %rsi      # 0x96c7
movq %rbx, %rdi
callq 0x22a0
cmpb $0x1, 0x43(%r12)
jne 0x5f8a
leaq 0x373b(%rip), %rsi      # 0x96bd
movq %rbx, %rdi
callq 0x22a0
cmpb $0x1, 0x44(%r12)
jne 0x5fa1
leaq 0x372b(%rip), %rsi      # 0x96c4
movq %rbx, %rdi
callq 0x22a0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x22a0
leaq 0x37d3(%rip), %rsi      # 0x9786
movq %rbx, %rdi
callq 0x22a0
movl 0x48(%r12), %r15d
movl %r15d, %r12d
negl %r12d
cmovsl %r15d, %r12d
movl $0x1, %r13d
cmpl $0xa, %r12d
jb 0x6020
movl $0x4, %r13d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r12d, %ecx
cmpl $0x63, %ecx
jbe 0x6017
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x601d
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x6020
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r13d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x5fe4
addl $-0x3, %r13d
jmp 0x6020
addl $-0x2, %r13d
jmp 0x6020
decl %r13d
shrl $0x1f, %r15d
leal (%r15,%r13), %esi
leaq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
movq %rax, (%rdi)
movl $0x2d, %edx
callq 0x2190
leaq -0x78(%rbp), %rbx
addq (%rbx), %r15
movq %r15, %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x6615
leaq 0x372e(%rip), %rsi      # 0x9787
movq %rbx, %rdi
callq 0x22a0
movq %r14, -0x50(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
movq -0x58(%rbp), %rbx
movq -0x80(%rbp), %r15
je 0x6089
movq %rdx, -0x50(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x40(%rbp)
jmp 0x6090
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
movq %rdx, -0x48(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %rbx, %rdi
callq 0x2060
movq -0x50(%rbp), %rdi
cmpq %r14, %rdi
je 0x60cc
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x60e5
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2150
movl 0x4c(%r15), %r14d
movl %r14d, %r15d
negl %r15d
cmovsl %r14d, %r15d
movl $0x1, %r12d
cmpl $0xa, %r15d
jb 0x6149
movl $0x4, %r12d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r15d, %ecx
cmpl $0x63, %ecx
jbe 0x6140
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x6146
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x6149
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r12d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x610d
addl $-0x3, %r12d
jmp 0x6149
addl $-0x2, %r12d
jmp 0x6149
decl %r12d
shrl $0x1f, %r14d
leal (%r12,%r14), %esi
leaq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
movq %rax, (%rdi)
movl $0x2d, %edx
callq 0x2190
addq -0x50(%rbp), %r14
movq %r14, %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x6615
movq -0x50(%rbp), %rsi
movq -0x48(%rbp), %rdx
movq %rbx, %rdi
callq 0x2060
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x61a1
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x35cc(%rip), %r15      # 0x9786
jmp 0x5fa1
movq %rax, %r14
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
jne 0x621e
jmp 0x622a
jmp 0x620a
movq %r14, %rcx
movq %rax, %r14
movq -0x50(%rbp), %rdi
cmpq %rcx, %rdi
je 0x61f3
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
jmp 0x61f3
movq %rax, %r14
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
je 0x622a
movq -0x68(%rbp), %rsi
jmp 0x6222
jmp 0x620a
jmp 0x627f
movq %rax, %r14
jmp 0x622a
movq %r14, %rcx
movq %rax, %r14
movq -0x50(%rbp), %rdi
cmpq %rcx, %rdi
je 0x622a
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
movq -0x58(%rbp), %rbx
jmp 0x6282
jmp 0x627f
movq %rax, %r14
movq -0x78(%rbp), %rdi
leaq -0x68(%rbp), %rax
cmpq %rax, %rdi
movq -0x30(%rbp), %r15
je 0x6264
movq -0x68(%rbp), %rsi
incq %rsi
callq 0x2150
jmp 0x6264
movq %rax, %r14
movq -0x58(%rbp), %rbx
jmp 0x6260
movq %rax, %r14
movq -0x30(%rbp), %r15
movq -0x50(%rbp), %rdi
leaq -0x40(%rbp), %rax
cmpq %rax, %rdi
je 0x6286
movq -0x40(%rbp), %rsi
incq %rsi
callq 0x2150
jmp 0x6286
movq %rax, %r14
movq -0x30(%rbp), %r15
movq (%rbx), %rdi
cmpq %r15, %rdi
je 0x6299
movq (%r15), %rsi
incq %rsi
callq 0x2150
movq %r14, %rdi
callq 0x2270
nop