// File: /workspace/github_cpp_makefile_star2_O2/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 %r12
pushq %rbx
subq $0x3d0, %rsp            # imm = 0x3D0
movq (%rdx), %rax
movq %rdi, %rbx
cmpq %rax, 0x8(%rdx)
je 0x1ea96
movq %rsi, %r14
movq (%rax), %rsi
movq %rdx, %r15
leaq 0x1c8(%rsp), %r12
pushq $0x8
popq %rdx
movq %r12, %rdi
callq 0x5690
movq (%r12), %rax
movq -0x18(%rax), %rax
testb $0x5, 0x1e8(%rsp,%rax)
je 0x1ead7
movq (%r15), %rdx
leaq 0x7cd1(%rip), %rsi      # 0x2671c
movq %rsp, %rdi
callq 0x8070
leaq 0x7cd6(%rip), %rdx      # 0x26730
leaq 0x140(%rsp), %rdi
movq %rsp, %rsi
callq 0x8051
leaq 0x140(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8d00
leaq 0x140(%rsp), %rdi
callq 0x5150
movq %rsp, %rdi
callq 0x5150
jmp 0x1ed46
leaq 0x7c6b(%rip), %rsi      # 0x26708
leaq 0x160(%rsp), %rdi
leaq 0x1c8(%rsp), %rdx
callq 0x5110
pushq $0x1
popq %rsi
leaq 0x160(%rsp), %rdx
movq %rbx, %rdi
callq 0x8d00
leaq 0x160(%rsp), %rdi
callq 0x5150
jmp 0x1ed53
leaq 0x60(%rsp), %rdi
leaq 0x1c8(%rsp), %rsi
callq 0x1f614
leaq 0x60(%rsp), %rsi
movq %rsp, %rdi
callq 0x1f66e
leaq 0x7b58(%rip), %rsi      # 0x26655
movq %rsp, %r15
movq %r15, %rdi
callq 0x1f664
movq %r15, %rdi
movl %eax, %ebp
callq 0x5150
testb %bpl, %bpl
je 0x1eb6f
leaq 0x1c8(%rsp), %rdi
callq 0x5070
leaq 0x60(%rsp), %rsi
movq %rsp, %rdi
callq 0x1f66e
leaq 0x7c05(%rip), %rsi      # 0x2673d
leaq 0x120(%rsp), %rdi
movq %rsp, %rdx
callq 0xcf8b
leaq 0x120(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8d00
leaq 0x120(%rsp), %rdi
callq 0x5150
movq %rsp, %rdi
jmp 0x1ed37
leaq 0xa0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0x1f6dc
leaq 0x80(%r14), %r15
movq %rsp, %rdi
movq %r15, %rsi
callq 0x1ef62
leaq 0xa0(%rsp), %rdi
movq %rsp, %r12
movq %r12, %rsi
callq 0x1f74a
movq %r12, %rdi
movl %eax, %ebp
callq 0x5150
testb %bpl, %bpl
je 0x1ec95
movq 0x70(%r14), %rax
subq 0x68(%r14), %rax
shrq %rax
testl %eax, %eax
je 0x1ec0b
leaq 0x1c8(%rsp), %rdi
callq 0x5070
leaq 0x7b7e(%rip), %rsi      # 0x2675a
leaq 0xe0(%rsp), %rdi
movq %rsp, %rdx
callq 0x5110
leaq 0xe0(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x8d00
leaq 0xe0(%rsp), %rdi
jmp 0x1ed2a
leaq 0x100(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x5490
leaq 0x180(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x82d2
leaq 0x180(%rsp), %rsi
movq %rsp, %rdi
callq 0x8384
leaq 0x68(%r14), %rdi
movq %rsp, %r12
movq %r12, %rsi
callq 0x1ef74
movq %r12, %rdi
callq 0x8570
leaq 0x180(%rsp), %rdi
callq 0x83bc
leaq 0x100(%rsp), %rdi
callq 0x5150
movq 0xd8(%r14), %rdi
movq (%rdi), %rax
pushq $0x1
popq %rdx
movq %r15, %rsi
callq *0x20(%rax)
vmovsd 0x40(%r14), %xmm0
vmovsd %xmm0, 0x60(%r14)
leaq 0x60(%rsp), %rdi
callq 0x10e86
testb %al, %al
je 0x1ecbd
leaq 0x60(%rsp), %rdi
callq 0xe86e
movq %rsp, %rsi
movw %ax, (%rsi)
movq %r14, %rdi
callq 0x1c9fa
jmp 0x1ec95
leaq 0x60(%rsp), %rdi
callq 0xe82a
testb %al, %al
je 0x1ecdd
movq 0xd8(%r14), %rdi
movq (%rdi), %rax
leaq 0x60(%rsp), %rsi
callq *0x68(%rax)
leaq 0x60(%rsp), %rdi
callq 0xe9fc
testb %al, %al
je 0x1ed66
leaq 0x1c8(%rsp), %rdi
callq 0x5070
leaq 0x3bde(%rip), %rsi      # 0x228dd
leaq 0xc0(%rsp), %rdi
movq %rsp, %rdx
callq 0x5110
pushq $0x1
popq %rsi
leaq 0xc0(%rsp), %rdx
movq %rbx, %rdi
callq 0x8d00
leaq 0xc0(%rsp), %rdi
callq 0x5150
leaq 0xa0(%rsp), %rdi
callq 0x5150
leaq 0x68(%rsp), %rdi
callq 0xeb22
leaq 0x1c8(%rsp), %rdi
callq 0x50a0
movq %rbx, %rax
addq $0x3d0, %rsp            # imm = 0x3D0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4858(%rip), %rdi      # 0x235c5
leaq 0x7a1e(%rip), %rsi      # 0x26792
leaq 0x7a2a(%rip), %rcx      # 0x267a5
movl $0x137, %edx            # imm = 0x137
callq 0x51f0
leaq 0x180(%rsp), %rdi
movq %rax, %rbx
callq 0x83bc
jmp 0x1ed9a
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
jmp 0x1edc2
jmp 0x1ee33
leaq 0xe0(%rsp), %rdi
jmp 0x1edbf
jmp 0x1ee33
jmp 0x1ee33
leaq 0xc0(%rsp), %rdi
movq %rax, %rbx
callq 0x5150
jmp 0x1ee36
jmp 0x1ee33
leaq 0x120(%rsp), %rdi
movq %rax, %rbx
callq 0x5150
jmp 0x1ede0
movq %rax, %rbx
movq %rsp, %rdi
jmp 0x1ee3e
jmp 0x1ee33
jmp 0x1eded
jmp 0x1eded
jmp 0x1eded
movq %rax, %rbx
jmp 0x1ee43
jmp 0x1ee2c
jmp 0x1ee33
leaq 0x160(%rsp), %rdi
movq %rax, %rbx
callq 0x5150
jmp 0x1ee5a
movq %rax, %rbx
jmp 0x1ee5a
leaq 0x140(%rsp), %rdi
movq %rax, %rbx
callq 0x5150
jmp 0x1ee22
movq %rax, %rbx
movq %rsp, %rdi
callq 0x5150
jmp 0x1ee4d
movq %rax, %rbx
jmp 0x1ee4d
jmp 0x1ee33
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x5150
leaq 0x68(%rsp), %rdi
callq 0xeb22
leaq 0x1c8(%rsp), %rdi
callq 0x50a0
movq %rbx, %rdi
callq 0x5650