// File: 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
subq $0x120, %rsp            # imm = 0x120
movq %rdi, -0x100(%rbp)
movq %rdi, %rax
movq %rax, -0x110(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x108(%rbp)
movb $0x0, -0x11(%rbp)
leaq -0x12(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x3420
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rdx
leaq 0x5927(%rip), %rsi      # 0xe8ef
callq 0x4850
jmp 0x8fcf
leaq -0x12(%rbp), %rdi
callq 0x32b0
movl $0x0, -0x28(%rbp)
cmpl $0x7, -0x28(%rbp)
jg 0x919f
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
cmpl $0x7, -0x30(%rbp)
jg 0x911c
movq -0x108(%rbp), %rsi
movl -0x28(%rbp), %eax
movl $0x7, %edx
subl %eax, %edx
movl -0x30(%rbp), %ecx
movl %ecx, %eax
movl %edx, %ecx
leal (%rax,%rcx,8), %edx
leaq -0x50(%rbp), %rdi
callq 0x88a0
jmp 0x9027
leaq 0x5989(%rip), %rsi      # 0xe9b7
leaq -0x50(%rbp), %rdi
callq 0x9a50
movb %al, -0x111(%rbp)
jmp 0x903f
movb -0x111(%rbp), %al
testb $0x1, %al
jne 0x904e
jmp 0x90ee
cmpl $0x0, -0x2c(%rbp)
jle 0x90da
movl -0x2c(%rbp), %esi
leaq -0x70(%rbp), %rdi
callq 0x9c90
jmp 0x9066
movq -0x100(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x3330
jmp 0x9078
leaq -0x70(%rbp), %rdi
callq 0x34a8
movl $0x0, -0x2c(%rbp)
jmp 0x90da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x12(%rbp), %rdi
callq 0x32b0
jmp 0x9421
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x9415
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x910e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x34a8
jmp 0x910e
movq -0x100(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3330
jmp 0x90ec
jmp 0x90f7
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x34a8
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x8ff7
leaq -0x50(%rbp), %rdi
callq 0x34a8
jmp 0x9415
cmpl $0x0, -0x2c(%rbp)
jle 0x917a
movl -0x2c(%rbp), %esi
leaq -0x90(%rbp), %rdi
callq 0x9c90
jmp 0x9133
movq -0x100(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x3330
jmp 0x9148
leaq -0x90(%rbp), %rdi
callq 0x34a8
movl $0x0, -0x2c(%rbp)
jmp 0x917a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x34a8
jmp 0x9415
movq -0x100(%rbp), %rdi
leaq 0x5831(%rip), %rsi      # 0xe9b9
callq 0x3240
jmp 0x918f
jmp 0x9191
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x8fdf
movq -0x100(%rbp), %rdi
callq 0x32f0
movq -0x100(%rbp), %rdi
leaq 0x574e(%rip), %rsi      # 0xe907
callq 0x3240
jmp 0x91c0
movq -0x108(%rbp), %rax
testb $0x1, 0x40(%rax)
je 0x91e4
movq -0x100(%rbp), %rdi
leaq 0x57e0(%rip), %rsi      # 0xe9bb
callq 0x3240
jmp 0x91e2
jmp 0x91fb
movq -0x100(%rbp), %rdi
leaq 0x56d1(%rip), %rsi      # 0xe8c3
callq 0x3240
jmp 0x91f9
jmp 0x91fb
movq -0x108(%rbp), %rax
testb $0x1, 0x42(%rax)
jne 0x9249
movq -0x108(%rbp), %rax
testb $0x1, 0x41(%rax)
jne 0x9249
movq -0x108(%rbp), %rax
testb $0x1, 0x44(%rax)
jne 0x9249
movq -0x108(%rbp), %rax
testb $0x1, 0x43(%rax)
jne 0x9249
movq -0x100(%rbp), %rdi
leaq 0x56c9(%rip), %rsi      # 0xe906
callq 0x3240
jmp 0x9244
jmp 0x92f0
movq -0x108(%rbp), %rax
testb $0x1, 0x41(%rax)
je 0x926d
movq -0x100(%rbp), %rdi
leaq 0x56c4(%rip), %rsi      # 0xe928
callq 0x3240
jmp 0x926b
jmp 0x926d
movq -0x108(%rbp), %rax
testb $0x1, 0x42(%rax)
je 0x9291
movq -0x100(%rbp), %rdi
leaq 0x55bf(%rip), %rsi      # 0xe847
callq 0x3240
jmp 0x928f
jmp 0x9291
movq -0x108(%rbp), %rax
testb $0x1, 0x43(%rax)
je 0x92b5
movq -0x100(%rbp), %rdi
leaq 0x5591(%rip), %rsi      # 0xe83d
callq 0x3240
jmp 0x92b3
jmp 0x92b5
movq -0x108(%rbp), %rax
testb $0x1, 0x44(%rax)
je 0x92d9
movq -0x100(%rbp), %rdi
leaq 0x5574(%rip), %rsi      # 0xe844
callq 0x3240
jmp 0x92d7
jmp 0x92d9
movq -0x100(%rbp), %rdi
leaq 0x5620(%rip), %rsi      # 0xe907
callq 0x3240
jmp 0x92ee
jmp 0x92f0
movq -0x100(%rbp), %rdi
leaq 0x5608(%rip), %rsi      # 0xe906
callq 0x3240
jmp 0x9305
movq -0x108(%rbp), %rax
movl 0x48(%rax), %esi
leaq -0xd0(%rbp), %rdi
callq 0x9c90
jmp 0x931d
leaq 0x55e3(%rip), %rdx      # 0xe907
leaq -0xb0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x9db0
jmp 0x9339
movq -0x100(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x3330
jmp 0x934e
leaq -0xb0(%rbp), %rdi
callq 0x34a8
leaq -0xd0(%rbp), %rdi
callq 0x34a8
movq -0x108(%rbp), %rax
movl 0x4c(%rax), %esi
leaq -0xf0(%rbp), %rdi
callq 0x9c90
jmp 0x937e
movq -0x100(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x3330
jmp 0x9393
leaq -0xf0(%rbp), %rdi
callq 0x34a8
movb $0x1, -0x11(%rbp)
testb $0x1, -0x11(%rbp)
jne 0x9405
jmp 0x93f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
jmp 0x93d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x34a8
leaq -0xd0(%rbp), %rdi
callq 0x34a8
jmp 0x9415
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x20(%rbp)
movl %eax, -0x24(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x34a8
jmp 0x9415
movq -0x100(%rbp), %rdi
callq 0x34a8
movq -0x110(%rbp), %rax
addq $0x120, %rsp            # imm = 0x120
popq %rbp
retq
movq -0x100(%rbp), %rdi
callq 0x34a8
movq -0x20(%rbp), %rdi
callq 0x3410
nopw (%rax,%rax)