// File: /workspace/github_cpp_makefile_star2_O3/tewalds[P]morat/hex/gtpgeneral.cpp
// Function: Morat::Hex::GTP::gtp_load_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_load_sgf(vecstr args){
	if(args.size() == 0)
		return GTPResponse(true, "load_sgf <filename>");

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

	if(!infile) {
		return GTPResponse(false, "Error opening file " + args[0] + " for reading");
	}

	SGFParser<Move> sgf(infile);
	if(sgf.game() != Board::name){
		infile.close();
		return GTPResponse(false, "File is for the wrong game: " + sgf.game());
	}

	auto size = sgf.size();
	if(size != hist->size()){
		if(hist.len() == 0){
			hist = History<Board>(Board(size));
			set_board();
			time_control.new_game();
		}else{
			infile.close();
			return GTPResponse(false, "File has the wrong boardsize to match the existing game");
		}
	}

	Side s = Side::P1;

	while(sgf.next_node()){
		Move m = sgf.move();
		move(m); // push the game forward
		s = ~s;
	}

	if(sgf.has_children())
		agent->load_sgf(sgf);

	assert(sgf.done_child());
	infile.close();
	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3d8, %rsp            # imm = 0x3D8
movq (%rdx), %rax
movq %rdi, %rbx
cmpq %rax, 0x8(%rdx)
je 0x2c11b
movq %rsi, %r14
movq (%rax), %rsi
movq %rdx, %r15
leaq 0x1d0(%rsp), %r12
movl $0x8, %edx
movq %r12, %rdi
callq 0x56b0
movq (%r12), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x1f0(%rsp,%rax)
je 0x2c170
movq (%r15), %rdx
leaq 0x9b4f(%rip), %rsi      # 0x35c1c
movq %rsp, %rdi
callq 0x98b3
leaq 0x9b54(%rip), %rsi      # 0x35c30
movq %rsp, %rdi
callq 0x56e0
leaq 0xf8(%rsp), %r14
movq %rax, %rcx
addq $0x10, %rcx
movq %r14, -0x10(%r14)
movq (%rax), %rdx
cmpq %rcx, %rdx
je 0x2c230
movq %rdx, 0xe8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xf8(%rsp)
jmp 0x2c239
leaq 0x178(%rsp), %r15
leaq 0x168(%rsp), %r14
leaq 0x9ad6(%rip), %rsi      # 0x35c08
leaq 0x9ae2(%rip), %rdx      # 0x35c1b
movq %r14, %rdi
movq %r15, -0x10(%r15)
callq 0xb1dc
movl $0x1, %esi
movq %rbx, %rdi
movq %r14, %rdx
callq 0xa8ba
movq 0x168(%rsp), %rdi
cmpq %r15, %rdi
je 0x2c353
callq 0x52e0
jmp 0x2c353
leaq 0xa8(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x2d118
leaq 0xa8(%rsp), %rsi
movq %rsp, %rdi
callq 0x2d168
leaq 0x99b9(%rip), %rsi      # 0x35b55
movq %rsp, %r15
movq %r15, %rdi
callq 0x50b0
movq (%r15), %rdi
leaq 0x10(%rsp), %r12
movl %eax, %ebp
cmpq %r12, %rdi
je 0x2c1bb
callq 0x52e0
testl %ebp, %ebp
je 0x2c290
leaq 0x1d0(%rsp), %rdi
callq 0x5070
leaq 0xa8(%rsp), %rsi
movq %rsp, %rdi
callq 0x2d168
leaq 0x9a56(%rip), %rcx      # 0x35c3d
movl $0x1c, %r8d
movq %rsp, %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5380
leaq 0x98(%rsp), %r14
movq %rax, %rcx
addq $0x10, %rcx
movq %r14, -0x10(%r14)
movq (%rax), %rdx
cmpq %rcx, %rdx
je 0x2c2e7
movq %rdx, 0x88(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x98(%rsp)
jmp 0x2c2f0
vmovups (%rcx), %xmm0
vmovups %xmm0, (%r14)
movq 0x8(%rax), %rsi
leaq 0xe8(%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 0xe8(%rsp), %rdi
cmpq %r14, %rdi
je 0x2c274
callq 0x52e0
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c346
callq 0x52e0
jmp 0x2c346
leaq 0x68(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x2d1fe
movsbl 0x80(%r14), %esi
movq %rsp, %rdi
callq 0x1131a
movq 0x70(%rsp), %rdx
cmpq 0x8(%rsp), %rdx
jne 0x2c368
movq (%rsp), %r15
testq %rdx, %rdx
je 0x2c371
movq 0x68(%rsp), %rdi
movq %r15, %rsi
callq 0x5330
testl %eax, %eax
setne %bpl
jmp 0x2c373
vmovups (%rcx), %xmm0
vmovups %xmm0, (%r14)
movq 0x8(%rax), %rsi
leaq 0x88(%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 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x2c32b
callq 0x52e0
movq (%rsp), %rdi
cmpq %r12, %rdi
je 0x2c339
callq 0x52e0
leaq 0xb0(%rsp), %rdi
callq 0x13554
leaq 0x1d0(%rsp), %rdi
callq 0x5090
movq %rbx, %rax
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rsp), %r15
movb $0x1, %bpl
jmp 0x2c373
xorl %ebp, %ebp
cmpq %r12, %r15
je 0x2c380
movq %r15, %rdi
callq 0x52e0
testb %bpl, %bpl
je 0x2c57f
movq 0x70(%r14), %rax
subq 0x68(%r14), %rax
shrq %rax
testl %eax, %eax
je 0x2c3eb
leaq 0x1d0(%rsp), %rdi
callq 0x5070
leaq 0x138(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x98a2(%rip), %rsi      # 0x35c5a
leaq 0x98d2(%rip), %rdx      # 0x35c91
leaq 0x128(%rsp), %rdi
callq 0xb1dc
leaq 0x128(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xa8ba
movq 0x128(%rsp), %rdi
jmp 0x2c667
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
leaq 0x158(%rsp), %r12
movq %r12, -0x10(%r12)
addq %rsi, %rdx
leaq 0x148(%rsp), %rdi
callq 0xa930
leaq 0x188(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x9c30
leaq 0x188(%rsp), %rsi
movq %rsp, %rdi
callq 0x9d0c
vmovaps (%rsp), %xmm0
movq 0x68(%r14), %rdi
leaq 0x80(%r14), %r15
vxorps %xmm1, %xmm1, %xmm1
vmovups %xmm0, 0x68(%r14)
movq 0x10(%rsp), %rax
movq %rax, 0x78(%r14)
vmovaps %xmm1, (%rsp)
movq $0x0, 0x10(%rsp)
testq %rdi, %rdi
je 0x2c476
callq 0x52e0
vxorps %xmm1, %xmm1, %xmm1
movzwl 0x20(%rsp), %eax
movw %ax, 0x8(%r15)
movq 0x18(%rsp), %rax
movq %rax, (%r15)
vmovups 0x28(%rsp), %xmm0
movq 0x90(%r14), %rdi
vmovups %xmm0, 0x90(%r14)
movq 0x38(%rsp), %rax
movq %rax, 0xa0(%r14)
vmovups %xmm1, 0x28(%rsp)
movq $0x0, 0x38(%rsp)
testq %rdi, %rdi
je 0x2c4c3
callq 0x52e0
vmovaps 0x40(%rsp), %xmm0
vxorps %xmm1, %xmm1, %xmm1
vmovups %xmm0, 0xa8(%r14)
vmovaps 0x50(%rsp), %xmm0
vmovaps %xmm1, 0x50(%rsp)
movq 0xc0(%r14), %rdi
vmovups %xmm0, 0xb8(%r14)
testq %rdi, %rdi
je 0x2c50b
callq 0xb272
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x2c50b
callq 0xb272
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2c51a
callq 0x52e0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2c528
callq 0x52e0
movq 0x1c8(%rsp), %rdi
testq %rdi, %rdi
je 0x2c53a
callq 0xb272
movq 0x198(%rsp), %rdi
testq %rdi, %rdi
je 0x2c54c
callq 0x52e0
movq 0x148(%rsp), %rdi
cmpq %r12, %rdi
je 0x2c55e
callq 0x52e0
movq 0xd8(%r14), %rdi
movq (%rdi), %rax
movl $0x1, %edx
movq %r15, %rsi
callq *0x20(%rax)
vmovsd 0x40(%r14), %xmm0
vmovsd %xmm0, 0x60(%r14)
leaq 0x68(%r14), %r15
leaq 0xa8(%rsp), %r12
movq %rsp, %r13
movq %r12, %rdi
callq 0x15bde
testb %al, %al
je 0x2c5c3
movq %r12, %rdi
callq 0x13204
movw %ax, (%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x290d4
movq 0xd8(%r14), %rdi
movq (%rdi), %rax
movq %r13, %rsi
callq *0x28(%rax)
jmp 0x2c58e
movq 0xa8(%rsp), %rdi
callq 0x2d6bb
movq 0xa8(%rsp), %rdi
callq 0x5110
cmpl $0x28, %eax
jne 0x2c5f7
movq 0xd8(%r14), %rdi
movq (%rdi), %rax
leaq 0xa8(%rsp), %rsi
callq *0x68(%rax)
movq 0xa8(%rsp), %rdi
callq 0x2d6bb
movq 0xa8(%rsp), %rdi
movl $0x29, %esi
callq 0x2d71b
testb %al, %al
je 0x2c688
leaq 0x1d0(%rsp), %rdi
callq 0x5070
leaq 0x118(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x52cd(%rip), %rdx      # 0x31907
leaq 0x108(%rsp), %rdi
movq %rdx, %rsi
callq 0xb1dc
leaq 0x108(%rsp), %rdx
movl $0x1, %esi
movq %rbx, %rdi
callq 0xa8ba
movq 0x108(%rsp), %rdi
cmpq %r14, %rdi
je 0x2c671
callq 0x52e0
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x2c334
jmp 0x2c339
leaq 0x60da(%rip), %rdi      # 0x32769
leaq 0x95fc(%rip), %rsi      # 0x35c92
leaq 0x9608(%rip), %rcx      # 0x35ca5
movl $0x137, %edx            # imm = 0x137
callq 0x51d0
leaq 0x188(%rsp), %rdi
movq %rax, %rbx
callq 0x9d96
jmp 0x2c6bc
movq %rax, %rbx
movq 0x148(%rsp), %rdi
cmpq %r12, %rdi
jne 0x2c6fb
jmp 0x2c793
jmp 0x2c790
movq 0x128(%rsp), %rdi
jmp 0x2c6ef
jmp 0x2c790
jmp 0x2c790
movq 0x108(%rsp), %rdi
movq %rax, %rbx
cmpq %r14, %rdi
je 0x2c793
callq 0x52e0
jmp 0x2c793
jmp 0x2c790
jmp 0x2c790
jmp 0x2c73a
movq 0x88(%rsp), %rdi
movq %rax, %rbx
cmpq %r14, %rdi
je 0x2c72b
callq 0x52e0
jmp 0x2c72b
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r12, %rdi
jne 0x2c7a1
jmp 0x2c7a6
jmp 0x2c73a
jmp 0x2c73a
movq %rax, %rbx
jmp 0x2c7a6
jmp 0x2c789
jmp 0x2c790
movq 0x168(%rsp), %rdi
movq %rax, %rbx
cmpq %r15, %rdi
je 0x2c7c0
callq 0x52e0
jmp 0x2c7c0
movq 0xe8(%rsp), %rdi
movq %rax, %rbx
cmpq %r14, %rdi
je 0x2c774
callq 0x52e0
jmp 0x2c774
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c7b3
callq 0x52e0
jmp 0x2c7b3
movq %rax, %rbx
jmp 0x2c7b3
jmp 0x2c790
movq %rax, %rbx
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c7a6
callq 0x52e0
leaq 0xb0(%rsp), %rdi
callq 0x13554
leaq 0x1d0(%rsp), %rdi
callq 0x5090
movq %rbx, %rdi
callq 0x5670