// File: /workspace/github_cpp_makefile_star2_O3/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, -0x30(%rbp)
movq %rdi, %rbx
leaq 0x10(%rdi), %rax
movq %rax, -0x38(%rbp)
movq %rax, (%rdi)
leaq 0x3aa9(%rip), %rdx      # 0x976f
movq %rdx, %rsi
callq 0x667e
xorl %eax, %eax
leaq -0x58(%rbp), %r15
movq %rbx, -0x60(%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 -0x30(%rbp), %rsi
callq 0x59b8
movq %r15, %rdi
leaq 0x3b2b(%rip), %rsi      # 0x9837
callq 0x2050
testl %eax, %eax
je 0x5d64
testl %r13d, %r13d
jle 0x5dc6
movl $0x1, %ebx
cmpl $0xa, %r13d
jb 0x5d70
movl $0x4, %ebx
movl %r13d, %eax
cmpl $0x63, %eax
jbe 0x5d69
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x5d6e
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x5d70
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 0x5d31
addl $-0x3, %ebx
jmp 0x5d70
incl %r13d
jmp 0x5dd6
addl $-0x2, %ebx
jmp 0x5d70
decl %ebx
movl %ebx, %esi
leaq -0x70(%rbp), %rax
movq %rax, -0x80(%rbp)
leaq -0x80(%rbp), %rdi
movl $0x2d, %edx
callq 0x2190
movq -0x80(%rbp), %rdi
movl %ebx, %esi
movl %r13d, %edx
callq 0x660b
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
movq -0x60(%rbp), %rbx
movq %rbx, %rdi
callq 0x2060
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x5dc3
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2150
xorl %r13d, %r13d
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq %rbx, %rdi
callq 0x2060
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x5def
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2150
incl %r12d
cmpl $0x8, %r12d
jne 0x5ced
testl %r13d, %r13d
leaq -0x48(%rbp), %r14
jle 0x5ea0
movl $0x1, %ebx
cmpl $0xa, %r13d
jb 0x5e56
movl $0x4, %ebx
movl %r13d, %eax
cmpl $0x63, %eax
jbe 0x5e4f
cmpl $0x3e7, %eax            # imm = 0x3E7
jbe 0x5e54
cmpl $0x2710, %eax           # imm = 0x2710
jb 0x5e56
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 0x5e1c
addl $-0x3, %ebx
jmp 0x5e56
addl $-0x2, %ebx
jmp 0x5e56
decl %ebx
movl %ebx, %esi
movq %r14, -0x58(%rbp)
movq %r15, %rdi
movl $0x2d, %edx
callq 0x2190
movq -0x58(%rbp), %rdi
movl %ebx, %esi
movl %r13d, %edx
callq 0x660b
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq -0x60(%rbp), %rbx
movq %rbx, %rdi
callq 0x2060
movq -0x58(%rbp), %rdi
cmpq %r14, %rdi
je 0x5ea0
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2150
movq %rbx, %rdi
leaq 0x398f(%rip), %rsi      # 0x9839
callq 0x22a0
movq -0x88(%rbp), %rax
incl %eax
cmpl $0x8, %eax
jne 0x5cd8
movq %rbx, %rdi
callq 0x21a0
leaq 0x38b7(%rip), %r15      # 0x9787
movq %rbx, %rdi
movq %r15, %rsi
callq 0x22a0
leaq 0x3959(%rip), %rax      # 0x983b
leaq 0x385a(%rip), %rsi      # 0x9743
movq -0x30(%rbp), %rcx
cmpb $0x0, 0x40(%rcx)
cmovneq %rax, %rsi
movq %rbx, %rdi
callq 0x22a0
movq -0x30(%rbp), %rax
movb 0x41(%rax), %cl
movb 0x42(%rax), %al
testb %al, %al
jne 0x5f28
testb $0x1, %cl
jne 0x5f28
movq -0x30(%rbp), %rdx
cmpb $0x0, 0x44(%rdx)
jne 0x5f28
movq -0x30(%rbp), %rdx
cmpb $0x0, 0x43(%rdx)
je 0x619d
testb $0x1, %cl
je 0x5f43
leaq 0x3874(%rip), %rsi      # 0x97a8
movq %rbx, %rdi
callq 0x22a0
movq -0x30(%rbp), %rax
movb 0x42(%rax), %al
testb $0x1, %al
je 0x5f56
leaq 0x3779(%rip), %rsi      # 0x96c7
movq %rbx, %rdi
callq 0x22a0
movq -0x30(%rbp), %rax
cmpb $0x1, 0x43(%rax)
jne 0x5f6f
leaq 0x3756(%rip), %rsi      # 0x96bd
movq %rbx, %rdi
callq 0x22a0
movq -0x30(%rbp), %rax
cmpb $0x1, 0x44(%rax)
jne 0x5f88
leaq 0x3744(%rip), %rsi      # 0x96c4
movq %rbx, %rdi
callq 0x22a0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x22a0
leaq 0x37ec(%rip), %rsi      # 0x9786
movq %rbx, %rdi
callq 0x22a0
movq -0x30(%rbp), %rax
movl 0x48(%rax), %r15d
movl %r15d, %r12d
negl %r12d
cmovsl %r15d, %r12d
movl $0x1, %r13d
cmpl $0xa, %r12d
jb 0x600a
movl $0x4, %r13d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r12d, %ecx
cmpl $0x63, %ecx
jbe 0x6001
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x6007
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x600a
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r13d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x5fce
addl $-0x3, %r13d
jmp 0x600a
addl $-0x2, %r13d
jmp 0x600a
decl %r13d
shrl $0x1f, %r15d
leal (%r15,%r13), %esi
leaq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
movq %rax, (%rdi)
movl $0x2d, %edx
callq 0x2190
leaq -0x80(%rbp), %rbx
addq (%rbx), %r15
movq %r15, %rdi
movl %r13d, %esi
movl %r12d, %edx
callq 0x660b
leaq 0x3744(%rip), %rsi      # 0x9787
movq %rbx, %rdi
callq 0x22a0
movq %r14, -0x58(%rbp)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
movq -0x60(%rbp), %rbx
je 0x606f
movq %rdx, -0x58(%rbp)
movq (%rcx), %rdx
movq %rdx, -0x48(%rbp)
jmp 0x6076
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
movq %rdx, -0x50(%rbp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq %rbx, %rdi
callq 0x2060
movq -0x58(%rbp), %rdi
cmpq %r14, %rdi
je 0x60b2
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2150
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x60cb
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2150
movq -0x30(%rbp), %rax
movl 0x4c(%rax), %r14d
movl %r14d, %r15d
negl %r15d
cmovsl %r14d, %r15d
movl $0x1, %r12d
cmpl $0xa, %r15d
jb 0x6133
movl $0x4, %r12d
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %r15d, %ecx
cmpl $0x63, %ecx
jbe 0x612a
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0x6130
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0x6133
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %r12d
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0x60f7
addl $-0x3, %r12d
jmp 0x6133
addl $-0x2, %r12d
jmp 0x6133
decl %r12d
shrl $0x1f, %r14d
leal (%r12,%r14), %esi
leaq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
movq %rax, (%rdi)
movl $0x2d, %edx
callq 0x2190
addq -0x58(%rbp), %r14
movq %r14, %rdi
movl %r12d, %esi
movl %r15d, %edx
callq 0x660b
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq %rbx, %rdi
callq 0x2060
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x618b
movq -0x48(%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 0x35e2(%rip), %r15      # 0x9786
jmp 0x5f88
movq %rax, %r14
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
jne 0x6208
jmp 0x6214
jmp 0x61f4
movq %r14, %rcx
movq %rax, %r14
movq -0x58(%rbp), %rdi
cmpq %rcx, %rdi
je 0x61dd
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2150
jmp 0x61dd
movq %rax, %r14
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x6214
movq -0x70(%rbp), %rsi
jmp 0x620c
jmp 0x61f4
jmp 0x6269
movq %rax, %r14
jmp 0x6214
movq %r14, %rcx
movq %rax, %r14
movq -0x58(%rbp), %rdi
cmpq %rcx, %rdi
je 0x6214
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2150
movq -0x60(%rbp), %rbx
jmp 0x626c
jmp 0x6269
movq %rax, %r14
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
movq -0x38(%rbp), %r15
je 0x624e
movq -0x70(%rbp), %rsi
incq %rsi
callq 0x2150
jmp 0x624e
movq %rax, %r14
movq -0x60(%rbp), %rbx
jmp 0x624a
movq %rax, %r14
movq -0x38(%rbp), %r15
movq -0x58(%rbp), %rdi
leaq -0x48(%rbp), %rax
cmpq %rax, %rdi
je 0x6270
movq -0x48(%rbp), %rsi
incq %rsi
callq 0x2150
jmp 0x6270
movq %rax, %r14
movq -0x38(%rbp), %r15
movq (%rbx), %rdi
cmpq %r15, %rdi
je 0x6283
movq (%r15), %rsi
incq %rsi
callq 0x2150
movq %r14, %rdi
callq 0x2270
nop