// File: codeandkey[P]neocortex/src/position.cpp
// Function: neocortex::Position::to_fen[abi:cxx11]()
std::string Position::to_fen() {
	assert(ply.size());

	std::string output;

	output += board.to_uci() + ' ';
	output += piece::color_to_uci(color_to_move);
	output += ' ';

	if (!ply.back().castle_rights) {
		output += '-';
	} else {
		if (ply.back().castle_rights & CASTLE_WHITE_K) output += 'K';
		if (ply.back().castle_rights & CASTLE_WHITE_Q) output += 'Q';
		if (ply.back().castle_rights & CASTLE_BLACK_K) output += 'k';
		if (ply.back().castle_rights & CASTLE_BLACK_Q) output += 'q';
	}

	output += ' ';

	output += square::to_uci(ply.back().en_passant_square) + ' ';
	output += std::to_string(ply.back().halfmove_clock) + ' ';
	output += std::to_string(ply.back().fullmove_number);

	return output;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x120(%rbp)
movq %rdi, %rax
movq %rax, -0x118(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x110(%rbp)
addq $0x158, %rdi            # imm = 0x158
callq 0x14c10
cmpq $0x0, %rax
je 0xcd83
jmp 0xcda2
leaq 0x1aa30(%rip), %rdi     # 0x277ba
leaq 0x1aa34(%rip), %rsi     # 0x277c5
movl $0x69, %edx
leaq 0x1aa39(%rip), %rcx     # 0x277d6
callq 0x5290
movq -0x120(%rbp), %rdi
movb $0x0, -0x11(%rbp)
callq 0x5540
movq -0x110(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x8110
jmp 0xcdc4
leaq -0x38(%rbp), %rdi
leaq -0x58(%rbp), %rsi
movl $0x20, %edx
callq 0x14c40
jmp 0xcdd8
movq -0x120(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x54f0
jmp 0xcdea
leaq -0x38(%rbp), %rdi
callq 0x5230
leaq -0x58(%rbp), %rdi
callq 0x5230
movq -0x110(%rbp), %rax
movl 0x170(%rax), %edi
callq 0xc0a0
movb %al, -0x121(%rbp)
jmp 0xce16
movq -0x120(%rbp), %rdi
movb -0x121(%rbp), %al
movsbl %al, %esi
callq 0x5250
jmp 0xce2d
movq -0x120(%rbp), %rdi
movl $0x20, %esi
callq 0x5250
jmp 0xce40
movq -0x110(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0xbce0
cmpl $0x0, 0x10(%rax)
jne 0xceb3
movq -0x120(%rbp), %rdi
movl $0x2d, %esi
callq 0x5250
jmp 0xce6c
jmp 0xcf81
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0xd160
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0xcea5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x5230
leaq -0x58(%rbp), %rdi
callq 0x5230
jmp 0xd160
movq -0x110(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0xbce0
movl 0x10(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xcee6
movq -0x120(%rbp), %rdi
movl $0x4b, %esi
callq 0x5250
jmp 0xcee4
jmp 0xcee6
movq -0x110(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0xbce0
movl 0x10(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
je 0xcf19
movq -0x120(%rbp), %rdi
movl $0x51, %esi
callq 0x5250
jmp 0xcf17
jmp 0xcf19
movq -0x110(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0xbce0
movl 0x10(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xcf4c
movq -0x120(%rbp), %rdi
movl $0x6b, %esi
callq 0x5250
jmp 0xcf4a
jmp 0xcf4c
movq -0x110(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0xbce0
movl 0x10(%rax), %eax
andl $0x8, %eax
cmpl $0x0, %eax
je 0xcf7f
movq -0x120(%rbp), %rdi
movl $0x71, %esi
callq 0x5250
jmp 0xcf7d
jmp 0xcf7f
jmp 0xcf81
movq -0x120(%rbp), %rdi
movl $0x20, %esi
callq 0x5250
jmp 0xcf94
movq -0x110(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0xbce0
movl 0xc(%rax), %esi
leaq -0xa8(%rbp), %rdi
callq 0x1be70
jmp 0xcfb8
leaq -0x88(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
movl $0x20, %edx
callq 0x14c40
jmp 0xcfd2
movq -0x120(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0x54f0
jmp 0xcfe7
leaq -0x88(%rbp), %rdi
callq 0x5230
leaq -0xa8(%rbp), %rdi
callq 0x5230
movq -0x110(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0xbce0
movl 0x1c(%rax), %esi
leaq -0xe8(%rbp), %rdi
callq 0x14c90
jmp 0xd023
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
movl $0x20, %edx
callq 0x14c40
jmp 0xd03d
movq -0x120(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x54f0
jmp 0xd052
leaq -0xc8(%rbp), %rdi
callq 0x5230
leaq -0xe8(%rbp), %rdi
callq 0x5230
movq -0x110(%rbp), %rdi
addq $0x158, %rdi            # imm = 0x158
callq 0xbce0
movl 0x20(%rax), %esi
leaq -0x108(%rbp), %rdi
callq 0x14c90
jmp 0xd08e
movq -0x120(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x54f0
jmp 0xd0a3
leaq -0x108(%rbp), %rdi
callq 0x5230
movb $0x1, -0x11(%rbp)
testb $0x1, -0x11(%rbp)
jne 0xd150
jmp 0xd144
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0xd0e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x5230
leaq -0xa8(%rbp), %rdi
callq 0x5230
jmp 0xd160
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0xd11c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x5230
leaq -0xe8(%rbp), %rdi
callq 0x5230
jmp 0xd160
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x5230
jmp 0xd160
movq -0x120(%rbp), %rdi
callq 0x5230
movq -0x118(%rbp), %rax
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
movq -0x120(%rbp), %rdi
callq 0x5230
movq -0x60(%rbp), %rdi
callq 0x56c0
nopw %cs:(%rax,%rax)