// File: /workspace/github_cpp_makefile_star2_O1/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 %rdi, %rbx
movq (%rdx), %rax
cmpq %rax, 0x8(%rdx)
je 0x2c201
movq %rdx, %r15
movq %rsi, %r14
movq (%rax), %rsi
leaq 0x1d0(%rsp), %r12
movq %r12, %rdi
movl $0x8, %edx
callq 0x56b0
movq (%r12), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x1f0(%rsp,%rax)
je 0x2c256
movq (%r15), %rdx
leaq 0x9a69(%rip), %rsi      # 0x35c1c
movq %rsp, %rdi
callq 0x9805
leaq 0x9a6e(%rip), %rsi      # 0x35c30
movq %rsp, %rdi
callq 0x56e0
leaq 0xf8(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2c316
movq %rdx, 0xe8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xf8(%rsp)
jmp 0x2c31f
leaq 0x178(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x99f4(%rip), %rsi      # 0x35c08
leaq 0x9a00(%rip), %rdx      # 0x35c1b
leaq 0x168(%rsp), %r14
movq %r14, %rdi
callq 0xb0e0
movq %rbx, %rdi
movl $0x1, %esi
movq %r14, %rdx
callq 0xa7f0
movq 0x168(%rsp), %rdi
cmpq %r15, %rdi
je 0x2c439
callq 0x52e0
jmp 0x2c439
leaq 0xa8(%rsp), %rdi
leaq 0x1d0(%rsp), %rsi
callq 0x2d1fe
movq %rsp, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x2d24e
leaq 0x98d3(%rip), %rsi      # 0x35b55
movq %rsp, %r15
movq %r15, %rdi
callq 0x50b0
movl %eax, %ebp
movq (%r15), %rdi
leaq 0x10(%rsp), %r15
cmpq %r15, %rdi
je 0x2c2a1
callq 0x52e0
testl %ebp, %ebp
je 0x2c376
leaq 0x1d0(%rsp), %rdi
callq 0x5070
movq %rsp, %rdi
leaq 0xa8(%rsp), %rsi
callq 0x2d24e
leaq 0x9970(%rip), %rcx      # 0x35c3d
movq %rsp, %rdi
movl $0x1c, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x5380
leaq 0x98(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x2c3cd
movq %rdx, 0x88(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x98(%rsp)
jmp 0x2c3d6
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 0xa7f0
movq 0xe8(%rsp), %rdi
cmpq %r14, %rdi
je 0x2c35a
callq 0x52e0
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c42c
callq 0x52e0
jmp 0x2c42c
leaq 0x68(%rsp), %rdi
leaq 0xa8(%rsp), %rsi
callq 0x2d2e4
movsbl 0x80(%r14), %esi
movq %rsp, %rdi
callq 0x11187
movq 0x70(%rsp), %rdx
movb $0x1, %bpl
cmpq 0x8(%rsp), %rdx
jne 0x2c450
testq %rdx, %rdx
je 0x2c44e
movq (%rsp), %rsi
movq 0x68(%rsp), %rdi
callq 0x5330
testl %eax, %eax
setne %bpl
jmp 0x2c450
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 0xa7f0
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x2c411
callq 0x52e0
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x2c41f
callq 0x52e0
leaq 0xb0(%rsp), %rdi
callq 0x1344e
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
xorl %ebp, %ebp
movq (%rsp), %rdi
cmpq %r15, %rdi
je 0x2c45e
callq 0x52e0
testb %bpl, %bpl
je 0x2c65d
movq 0x70(%r14), %rax
subq 0x68(%r14), %rax
shrq %rax
testl %eax, %eax
je 0x2c4c9
leaq 0x1d0(%rsp), %rdi
callq 0x5070
leaq 0x138(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x97c4(%rip), %rsi      # 0x35c5a
leaq 0x97f4(%rip), %rdx      # 0x35c91
leaq 0x128(%rsp), %rdi
callq 0xb0e0
leaq 0x128(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0xa7f0
movq 0x128(%rsp), %rdi
jmp 0x2c745
leaq 0x158(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
addq %rsi, %rdx
leaq 0x148(%rsp), %rdi
callq 0xa866
leaq 0x188(%rsp), %rdi
leaq 0x148(%rsp), %rsi
callq 0x9b7a
movq %rsp, %rdi
leaq 0x188(%rsp), %rsi
callq 0x9c56
leaq 0x80(%r14), %r15
vmovaps (%rsp), %xmm0
movq 0x10(%rsp), %rax
movq %rax, 0x78(%r14)
movq 0x68(%r14), %rdi
vmovups %xmm0, 0x68(%r14)
vxorps %xmm1, %xmm1, %xmm1
vmovaps %xmm1, (%rsp)
movq $0x0, 0x10(%rsp)
testq %rdi, %rdi
je 0x2c554
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 0x38(%rsp), %rax
movq %rax, 0xa0(%r14)
movq 0x90(%r14), %rdi
vmovups %xmm0, 0x90(%r14)
vmovups %xmm1, 0x28(%rsp)
movq $0x0, 0x38(%rsp)
testq %rdi, %rdi
je 0x2c5a1
callq 0x52e0
vmovaps 0x40(%rsp), %xmm0
vmovups %xmm0, 0xa8(%r14)
vmovaps 0x50(%rsp), %xmm0
vxorps %xmm1, %xmm1, %xmm1
vmovaps %xmm1, 0x50(%rsp)
movq 0xc0(%r14), %rdi
vmovups %xmm0, 0xb8(%r14)
testq %rdi, %rdi
je 0x2c5da
callq 0xb170
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x2c5e9
callq 0xb170
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2c5f8
callq 0x52e0
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x2c606
callq 0x52e0
movq 0x1c8(%rsp), %rdi
testq %rdi, %rdi
je 0x2c618
callq 0xb170
movq 0x198(%rsp), %rdi
testq %rdi, %rdi
je 0x2c62a
callq 0x52e0
movq 0x148(%rsp), %rdi
cmpq %r12, %rdi
je 0x2c63c
callq 0x52e0
movq 0xd8(%r14), %rdi
movq (%rdi), %rax
movq %r15, %rsi
movl $0x1, %edx
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 0x15ae0
testb %al, %al
je 0x2c6a1
movq %r12, %rdi
callq 0x130fe
movw %ax, (%rsp)
movq %r15, %rdi
movq %r13, %rsi
callq 0x291d8
movq 0xd8(%r14), %rdi
movq (%rdi), %rax
movq %r13, %rsi
callq *0x28(%rax)
jmp 0x2c66c
movq 0xa8(%rsp), %rdi
callq 0x2d7a7
movq 0xa8(%rsp), %rdi
callq 0x5110
cmpl $0x28, %eax
jne 0x2c6d5
movq 0xd8(%r14), %rdi
movq (%rdi), %rax
leaq 0xa8(%rsp), %rsi
callq *0x68(%rax)
movq 0xa8(%rsp), %rdi
callq 0x2d7a7
movq 0xa8(%rsp), %rdi
movl $0x29, %esi
callq 0x2d807
testb %al, %al
je 0x2c766
leaq 0x1d0(%rsp), %rdi
callq 0x5070
leaq 0x118(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x51ef(%rip), %rdx      # 0x31907
leaq 0x108(%rsp), %rdi
movq %rdx, %rsi
callq 0xb0e0
leaq 0x108(%rsp), %rdx
movq %rbx, %rdi
movl $0x1, %esi
callq 0xa7f0
movq 0x108(%rsp), %rdi
cmpq %r14, %rdi
je 0x2c74f
callq 0x52e0
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x2c41a
jmp 0x2c41f
leaq 0x5ffc(%rip), %rdi      # 0x32769
leaq 0x951e(%rip), %rsi      # 0x35c92
leaq 0x952a(%rip), %rcx      # 0x35ca5
movl $0x137, %edx            # imm = 0x137
callq 0x51d0
movq %rax, %rbx
leaq 0x188(%rsp), %rdi
callq 0x9ce0
jmp 0x2c79a
movq %rax, %rbx
movq 0x148(%rsp), %rdi
cmpq %r12, %rdi
jne 0x2c7dc
jmp 0x2c874
jmp 0x2c871
movq %rax, %rbx
movq 0x128(%rsp), %rdi
jmp 0x2c7d3
jmp 0x2c871
jmp 0x2c871
movq %rax, %rbx
movq 0x108(%rsp), %rdi
cmpq %r14, %rdi
je 0x2c874
callq 0x52e0
jmp 0x2c874
jmp 0x2c871
jmp 0x2c871
jmp 0x2c81b
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %r14, %rdi
je 0x2c80c
callq 0x52e0
jmp 0x2c80c
movq %rax, %rbx
movq (%rsp), %rdi
cmpq %r15, %rdi
jne 0x2c882
jmp 0x2c887
jmp 0x2c81b
jmp 0x2c81b
movq %rax, %rbx
jmp 0x2c887
jmp 0x2c86a
jmp 0x2c871
movq %rax, %rbx
movq 0x168(%rsp), %rdi
cmpq %r15, %rdi
je 0x2c8a1
callq 0x52e0
jmp 0x2c8a1
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
cmpq %r14, %rdi
je 0x2c855
callq 0x52e0
jmp 0x2c855
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c894
callq 0x52e0
jmp 0x2c894
movq %rax, %rbx
jmp 0x2c894
jmp 0x2c871
movq %rax, %rbx
leaq 0x78(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c887
callq 0x52e0
leaq 0xb0(%rsp), %rdi
callq 0x1344e
leaq 0x1d0(%rsp), %rdi
callq 0x5090
movq %rbx, %rdi
callq 0x5670
nop