// File: /workspace/github_cpp_makefile_star2_O1/tewalds[P]morat/hex/gtpgeneral.cpp
// Function: Morat::Hex::GTP::gtp_save_sgf(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>)
GTPResponse GTP::gtp_save_sgf(vecstr args){
	int limit = -1;
	if(args.size() == 0)
		return GTPResponse(true, "save_sgf <filename> [work limit]");

	std::ifstream infile(args[0].c_str());

	if(infile) {
		infile.close();
		return GTPResponse(false, "File " + args[0] + " already exists");
	}

	std::ofstream outfile(args[0].c_str());

	if(!outfile)
		return GTPResponse(false, "Opening file " + args[0] + " for writing failed");

	if(args.size() > 1)
		limit = from_str<unsigned int>(args[1]);

	SGFPrinter<Move> sgf(outfile);
	sgf.game(Board::name);
	sgf.program(gtp_name(vecstr()).response, gtp_version(vecstr()).response);
	sgf.size(hist->size());

	sgf.end_root();

	Side s = Side::P1;
	for(auto m : hist){
		sgf.move(s, m);
		s = ~s;
	}

	agent->gen_sgf(sgf, limit);

	sgf.end();
	outfile.close();
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x5f8, %rsp            # imm = 0x5F8
movq %rdi, %rbx
movq (%rdx), %rax
cmpq %rax, 0x8(%rdx)
je 0x2bafd
movq %rdx, %r15
movq %rsi, %r14
movq (%rax), %rsi
leaq 0x3f0(%rsp), %r12
movq %r12, %rdi
movl $0x8, %edx
callq 0x56b0
movq (%r12), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x410(%rsp,%rax)
je 0x2bb52
movq (%r15), %rax
movq (%rax), %rsi
leaq 0x1f0(%rsp), %rdi
movl $0x10, %edx
callq 0x5360
movq 0x1f0(%rsp), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x210(%rsp,%rax)
je 0x2bbc1
movq (%r15), %rdx
leaq 0xa13b(%rip), %rsi      # 0x35be6
leaq 0x48(%rsp), %rdi
callq 0x9805
leaq 0xa138(%rip), %rsi      # 0x35bf4
leaq 0x48(%rsp), %rdi
callq 0x56e0
leaq 0xc0(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2bc99
movq %rdx, 0xb0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xc0(%rsp)
jmp 0x2bca2
leaq 0x1e0(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xa09f(%rip), %rsi      # 0x35baf
leaq 0xa0b8(%rip), %rdx      # 0x35bcf
leaq 0x1d0(%rsp), %r14
movq %r14, %rdi
callq 0xb0e0
movq %rbx, %rdi
movl $0x1, %esi
movq %r14, %rdx
callq 0xa7f0
movq 0x1d0(%rsp), %rdi
cmpq %r15, %rdi
je 0x2bd91
callq 0x52e0
jmp 0x2bd91
leaq 0x3f0(%rsp), %rdi
callq 0x5070
movq (%r15), %rdx
leaq 0xa067(%rip), %rsi      # 0x35bd0
leaq 0x1f0(%rsp), %rdi
callq 0x9805
leaq 0xa059(%rip), %rsi      # 0x35bd6
leaq 0x1f0(%rsp), %rdi
callq 0x56e0
leaq 0xe0(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2bd2a
movq %rdx, 0xd0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xe0(%rsp)
jmp 0x2bd33
movq (%r15), %rdi
movq 0x8(%r15), %rcx
subq %rdi, %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpq $0x21, %rcx
jb 0x2bbdf
addq $0x20, %rdi
callq 0x1bf9d
movl %eax, 0xc(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
callq 0x2ccbc
leaq 0x158(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x9f4d(%rip), %rsi      # 0x35b55
leaq 0x9f49(%rip), %rdx      # 0x35b58
leaq 0x148(%rsp), %rdi
callq 0xb0e0
leaq 0x10(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x2cdc8
movq 0x148(%rsp), %rdi
cmpq %r15, %rdi
je 0x2bc40
callq 0x52e0
vxorps %xmm0, %xmm0, %xmm0
vmovaps %xmm0, 0x110(%rsp)
movq $0x0, 0x120(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x2ac78
leaq 0x38(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x80(%rsp), %r12
movq -0x10(%r12), %rax
cmpq %r12, %rax
je 0x2bda6
movq %rax, 0x28(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x38(%rsp)
jmp 0x2bdb1
vmovups (%rcx), %xmm0
vmovups %xmm0, (%r14)
movq 0x8(%rax), %rsi
leaq 0xb0(%rsp), %rdx
movq %rsi, 0x8(%rdx)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rbx, %rdi
xorl %esi, %esi
callq 0xa7f0
movq 0xb0(%rsp), %rdi
cmpq %r14, %rdi
je 0x2bcdd
callq 0x52e0
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2bcf0
callq 0x52e0
movq 0x1e2b9(%rip), %rax     # 0x49fb0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x1f8(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x1f0(%rsp,%rcx)
callq 0x5280
leaq 0x2e8(%rsp), %rdi
callq 0x50d0
jmp 0x2bd84
vmovups (%rcx), %xmm0
vmovups %xmm0, (%r14)
movq 0x8(%rax), %rsi
leaq 0xd0(%rsp), %rdx
movq %rsi, 0x8(%rdx)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %rbx, %rdi
xorl %esi, %esi
callq 0xa7f0
movq 0xd0(%rsp), %rdi
cmpq %r14, %rdi
je 0x2bd6e
callq 0x52e0
leaq 0x200(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2bd84
callq 0x52e0
leaq 0x3f0(%rsp), %rdi
callq 0x5090
movq %rbx, %rax
addq $0x5f8, %rsp            # imm = 0x5F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
vmovups (%r12), %xmm0
vmovups %xmm0, (%r15)
movq 0x78(%rsp), %rax
movq %rax, 0x30(%rsp)
movq %r12, 0x70(%rsp)
xorl %eax, %eax
movq %rax, 0x78(%rsp)
movb $0x0, 0x80(%rsp)
vxorps %xmm0, %xmm0, %xmm0
vmovaps %xmm0, 0xf0(%rsp)
movq %rax, 0x100(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x2ad64
leaq 0xa0(%rsp), %rbp
movq %rbp, -0x10(%rbp)
leaq 0x1a0(%rsp), %r13
movq -0x10(%r13), %rax
cmpq %r13, %rax
je 0x2be28
movq %rax, 0x90(%rsp)
movq 0x1a0(%rsp), %rax
movq %rax, 0xa0(%rsp)
jmp 0x2be33
vmovups (%r13), %xmm0
vmovups %xmm0, (%rbp)
movq 0x198(%rsp), %rax
leaq 0x90(%rsp), %rdx
movq %rax, 0x8(%rdx)
movq %r13, 0x190(%rsp)
movq $0x0, 0x198(%rsp)
movb $0x0, 0x1a0(%rsp)
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x2ceac
movq 0x90(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2be84
callq 0x52e0
movq 0x190(%rsp), %rdi
cmpq %r13, %rdi
je 0x2be96
callq 0x52e0
leaq 0x180(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2beac
callq 0x52e0
leaq 0xf0(%rsp), %rdi
callq 0xa9ae
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x2bec8
callq 0x52e0
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0x2bed7
callq 0x52e0
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2beea
callq 0x52e0
leaq 0x110(%rsp), %rdi
callq 0xa9ae
movsbl 0x80(%r14), %esi
leaq 0x1b0(%rsp), %rdi
callq 0x11187
leaq 0x10(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
callq 0x2d01c
leaq 0x1c0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2bf34
callq 0x52e0
leaq 0x10(%rsp), %rdi
callq 0x2d100
movq 0x68(%r14), %r12
movq 0x70(%r14), %r13
cmpq %r13, %r12
je 0x2bf7b
leaq 0xa458(%rip), %rax      # 0x363aa
movb (%rax), %bpl
leaq 0x10(%rsp), %r15
movzwl (%r12), %edx
movzbl %bpl, %esi
movq %r15, %rdi
callq 0x12bfa
movb $0x3, %al
subb %bpl, %al
addq $0x2, %r12
movl %eax, %ebp
cmpq %r13, %r12
jne 0x2bf5a
movq 0xd8(%r14), %rdi
movq (%rdi), %rax
leaq 0x10(%rsp), %rsi
movl 0xc(%rsp), %edx
callq *0x60(%rax)
leaq 0x10(%rsp), %rdi
callq 0x2d194
leaq 0x1f0(%rsp), %rdi
callq 0x5480
leaq 0x138(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x594c(%rip), %rdx      # 0x31907
leaq 0x128(%rsp), %rdi
movq %rdx, %rsi
callq 0xb0e0
leaq 0x128(%rsp), %rdx
movq %rbx, %rdi
movl $0x1, %esi
callq 0xa7f0
movq 0x128(%rsp), %rdi
cmpq %r14, %rdi
jne 0x2bceb
jmp 0x2bcf0
jmp 0x2c12e
movq %rax, %rbx
movq 0x128(%rsp), %rdi
cmpq %r14, %rdi
jne 0x2c105
jmp 0x2c131
jmp 0x2c12e
movq %rax, %rbx
leaq 0x1c0(%rsp), %rax
jmp 0x2c0fc
movq %rax, %rbx
movq 0x90(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2c03e
callq 0x52e0
leaq 0x168(%rsp), %rdi
callq 0x9630
jmp 0x2c050
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0xa9ae
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x2c06c
callq 0x52e0
leaq 0x48(%rsp), %rdi
callq 0x9630
jmp 0x2c07b
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0xa9ae
jmp 0x2c131
movq %rax, %rbx
movq 0x148(%rsp), %rdi
cmpq %r15, %rdi
jne 0x2c105
jmp 0x2c131
jmp 0x2c12e
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
cmpq %r14, %rdi
je 0x2c0c1
callq 0x52e0
jmp 0x2c0c1
movq %rax, %rbx
leaq 0x200(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c13e
callq 0x52e0
jmp 0x2c13e
jmp 0x2c125
jmp 0x2c125
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
cmpq %r14, %rdi
je 0x2c0f7
callq 0x52e0
jmp 0x2c0f7
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c131
callq 0x52e0
jmp 0x2c131
jmp 0x2c12e
movq %rax, %rbx
movq 0x1d0(%rsp), %rdi
cmpq %r15, %rdi
je 0x2c14b
callq 0x52e0
jmp 0x2c14b
movq %rax, %rbx
jmp 0x2c13e
jmp 0x2c12e
jmp 0x2c12e
movq %rax, %rbx
leaq 0x1f0(%rsp), %rdi
callq 0x54e0
leaq 0x3f0(%rsp), %rdi
callq 0x5090
movq %rbx, %rdi
callq 0x5670
nop