// File: /workspace/github_cpp_makefile_star2_O3/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 (%rdx), %rax
movq %rdi, %rbx
cmpq %rax, 0x8(%rdx)
je 0x2ba17
movq %rsi, %r14
movq (%rax), %rsi
movq %rdx, %r15
leaq 0x3f0(%rsp), %r12
movl $0x8, %edx
movq %r12, %rdi
callq 0x56b0
movq (%r12), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x410(%rsp,%rax)
je 0x2ba6c
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 0x2badb
movq (%r15), %rdx
leaq 0xa221(%rip), %rsi      # 0x35be6
leaq 0x48(%rsp), %rdi
callq 0x98b3
leaq 0xa21e(%rip), %rsi      # 0x35bf4
leaq 0x48(%rsp), %rdi
callq 0x56e0
leaq 0xc0(%rsp), %r14
movq %rax, %rcx
addq $0x10, %rcx
movq %r14, -0x10(%r14)
movq (%rax), %rdx
cmpq %rcx, %rdx
je 0x2bbb3
movq %rdx, 0xb0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xc0(%rsp)
jmp 0x2bbbc
leaq 0x1e0(%rsp), %r15
leaq 0x1d0(%rsp), %r14
leaq 0xa181(%rip), %rsi      # 0x35baf
leaq 0xa19a(%rip), %rdx      # 0x35bcf
movq %r14, %rdi
movq %r15, -0x10(%r15)
callq 0xb1dc
movl $0x1, %esi
movq %rbx, %rdi
movq %r14, %rdx
callq 0xa8ba
movq 0x1d0(%rsp), %rdi
cmpq %r15, %rdi
je 0x2bcab
callq 0x52e0
jmp 0x2bcab
leaq 0x3f0(%rsp), %rdi
callq 0x5070
movq (%r15), %rdx
leaq 0xa14d(%rip), %rsi      # 0x35bd0
leaq 0x1f0(%rsp), %rdi
callq 0x98b3
leaq 0xa13f(%rip), %rsi      # 0x35bd6
leaq 0x1f0(%rsp), %rdi
callq 0x56e0
leaq 0xe0(%rsp), %r14
movq %rax, %rcx
addq $0x10, %rcx
movq %r14, -0x10(%r14)
movq (%rax), %rdx
cmpq %rcx, %rdx
je 0x2bc44
movq %rdx, 0xd0(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xe0(%rsp)
jmp 0x2bc4d
movq (%r15), %rdi
movq 0x8(%r15), %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
subq %rdi, %rcx
cmpq $0x21, %rcx
jb 0x2baf9
addq $0x20, %rdi
callq 0x1bf54
leaq 0x10(%rsp), %rdi
leaq 0x1f0(%rsp), %rsi
movl %eax, 0xc(%rsp)
callq 0x2cbd6
leaq 0x158(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xa033(%rip), %rsi      # 0x35b55
leaq 0xa02f(%rip), %rdx      # 0x35b58
leaq 0x148(%rsp), %rdi
callq 0xb1dc
leaq 0x10(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x2cce2
movq 0x148(%rsp), %rdi
cmpq %r15, %rdi
je 0x2bb5a
callq 0x52e0
vxorps %xmm0, %xmm0, %xmm0
movq $0x0, 0x120(%rsp)
vmovaps %xmm0, 0x110(%rsp)
leaq 0x48(%rsp), %rdi
callq 0x2ab70
leaq 0x80(%rsp), %r12
leaq 0x38(%rsp), %r15
movq -0x10(%r12), %rax
movq %r15, -0x10(%r15)
cmpq %r12, %rax
je 0x2bcc0
movq 0x80(%rsp), %rcx
movq %rax, 0x28(%rsp)
movq %rcx, 0x38(%rsp)
jmp 0x2bccb
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 0xa8ba
movq 0xb0(%rsp), %rdi
cmpq %r14, %rdi
je 0x2bbf7
callq 0x52e0
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2bc0a
callq 0x52e0
movq 0x1d39f(%rip), %rax     # 0x48fb0
leaq 0x1f8(%rsp), %rdi
movq (%rax), %rcx
movq 0x18(%rax), %rax
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x1f0(%rsp,%rcx)
callq 0x5280
leaq 0x2e8(%rsp), %rdi
callq 0x50d0
jmp 0x2bc9e
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 0xa8ba
movq 0xd0(%rsp), %rdi
cmpq %r14, %rdi
je 0x2bc88
callq 0x52e0
leaq 0x200(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2bc9e
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
vxorps %xmm0, %xmm0, %xmm0
movq %r12, 0x70(%rsp)
vmovaps %xmm0, 0xf0(%rsp)
movq %rax, 0x30(%rsp)
xorl %eax, %eax
movq %rax, 0x78(%rsp)
movb $0x0, 0x80(%rsp)
movq %rax, 0x100(%rsp)
leaq 0x168(%rsp), %rdi
callq 0x2ac5c
leaq 0x1a0(%rsp), %r13
leaq 0xa0(%rsp), %rbp
movq -0x10(%r13), %rax
movq %rbp, -0x10(%rbp)
cmpq %r13, %rax
je 0x2bd42
movq 0x1a0(%rsp), %rcx
movq %rax, 0x90(%rsp)
movq %rcx, 0xa0(%rsp)
jmp 0x2bd4d
vmovups (%r13), %xmm0
vmovups %xmm0, (%rbp)
movq 0x198(%rsp), %rax
leaq 0x90(%rsp), %rdx
movq %r13, 0x190(%rsp)
movq $0x0, 0x198(%rsp)
movb $0x0, 0x1a0(%rsp)
movq %rax, 0x8(%rdx)
leaq 0x10(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x2cdc6
movq 0x90(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2bd9e
callq 0x52e0
movq 0x190(%rsp), %rdi
cmpq %r13, %rdi
je 0x2bdb0
callq 0x52e0
leaq 0x180(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2bdc6
callq 0x52e0
leaq 0xf0(%rsp), %rdi
callq 0xaa7e
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x2bde2
callq 0x52e0
movq 0x70(%rsp), %rdi
cmpq %r12, %rdi
je 0x2bdf1
callq 0x52e0
leaq 0x60(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2be04
callq 0x52e0
leaq 0x110(%rsp), %rdi
callq 0xaa7e
movsbl 0x80(%r14), %esi
leaq 0x1b0(%rsp), %rdi
callq 0x1131a
leaq 0x10(%rsp), %rdi
leaq 0x1b0(%rsp), %rsi
callq 0x2cf36
leaq 0x1c0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2be4e
callq 0x52e0
leaq 0x10(%rsp), %rdi
callq 0x2d01a
movq 0x68(%r14), %r12
movq 0x70(%r14), %r13
cmpq %r13, %r12
je 0x2be95
leaq 0xa53e(%rip), %rax      # 0x363aa
leaq 0x10(%rsp), %r15
movb (%rax), %bpl
movzwl (%r12), %edx
movzbl %bpl, %esi
movq %r15, %rdi
callq 0x12d00
movb $0x3, %al
addq $0x2, %r12
subb %bpl, %al
movl %eax, %ebp
cmpq %r13, %r12
jne 0x2be74
movq 0xd8(%r14), %rdi
movq (%rdi), %rax
movl 0xc(%rsp), %edx
leaq 0x10(%rsp), %rsi
callq *0x60(%rax)
leaq 0x10(%rsp), %rdi
callq 0x2d0ae
leaq 0x1f0(%rsp), %rdi
callq 0x5480
leaq 0x138(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x5a32(%rip), %rdx      # 0x31907
leaq 0x128(%rsp), %rdi
movq %rdx, %rsi
callq 0xb1dc
leaq 0x128(%rsp), %rdx
movl $0x1, %esi
movq %rbx, %rdi
callq 0xa8ba
movq 0x128(%rsp), %rdi
cmpq %r14, %rdi
jne 0x2bc05
jmp 0x2bc0a
jmp 0x2c048
movq 0x128(%rsp), %rdi
movq %rax, %rbx
cmpq %r14, %rdi
jne 0x2c01f
jmp 0x2c04b
jmp 0x2c048
movq %rax, %rbx
leaq 0x1c0(%rsp), %rax
jmp 0x2c016
movq 0x90(%rsp), %rdi
movq %rax, %rbx
cmpq %rbp, %rdi
je 0x2bf58
callq 0x52e0
leaq 0x168(%rsp), %rdi
callq 0x96d6
jmp 0x2bf6a
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0xaa7e
movq 0x28(%rsp), %rdi
cmpq %r15, %rdi
je 0x2bf86
callq 0x52e0
leaq 0x48(%rsp), %rdi
callq 0x96d6
jmp 0x2bf95
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0xaa7e
jmp 0x2c04b
movq 0x148(%rsp), %rdi
movq %rax, %rbx
cmpq %r15, %rdi
jne 0x2c01f
jmp 0x2c04b
jmp 0x2c048
movq 0xd0(%rsp), %rdi
movq %rax, %rbx
cmpq %r14, %rdi
je 0x2bfdb
callq 0x52e0
jmp 0x2bfdb
movq %rax, %rbx
leaq 0x200(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c058
callq 0x52e0
jmp 0x2c058
jmp 0x2c03f
jmp 0x2c03f
movq 0xb0(%rsp), %rdi
movq %rax, %rbx
cmpq %r14, %rdi
je 0x2c011
callq 0x52e0
jmp 0x2c011
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c04b
callq 0x52e0
jmp 0x2c04b
jmp 0x2c048
movq 0x1d0(%rsp), %rdi
movq %rax, %rbx
cmpq %r15, %rdi
je 0x2c065
callq 0x52e0
jmp 0x2c065
movq %rax, %rbx
jmp 0x2c058
jmp 0x2c048
jmp 0x2c048
movq %rax, %rbx
leaq 0x1f0(%rsp), %rdi
callq 0x54e0
leaq 0x3f0(%rsp), %rdi
callq 0x5090
movq %rbx, %rdi
callq 0x5670
nop