// File: 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:
subq $0x4f8, %rsp            # imm = 0x4F8
movq %rdx, 0x40(%rsp)
movq %rdi, %rax
movq 0x40(%rsp), %rdi
movq %rax, 0x48(%rsp)
movq %rax, %rcx
movq %rcx, 0x50(%rsp)
movq %rax, 0x4f0(%rsp)
movq %rsi, 0x4e8(%rsp)
movq %rdi, 0x4e0(%rsp)
movq 0x4e8(%rsp), %rax
movq %rax, 0x58(%rsp)
callq 0x13c80
cmpq $0x0, %rax
jne 0x42d43
leaq 0x4bf(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x5770
movq 0x38(%rsp), %rdx
leaq 0xd9e9(%rip), %rsi      # 0x5069c
leaq 0x4c0(%rsp), %rdi
callq 0x5590
jmp 0x42cc2
movq 0x48(%rsp), %rdi
movl $0x1, %esi
leaq 0x4c0(%rsp), %rdx
callq 0xd9a0
jmp 0x42cdb
leaq 0x4c0(%rsp), %rdi
callq 0x5260
leaq 0x4bf(%rsp), %rdi
callq 0x5450
jmp 0x43478
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4b0(%rsp)
movl %eax, 0x4ac(%rsp)
jmp 0x42d31
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4b0(%rsp)
movl %eax, 0x4ac(%rsp)
leaq 0x4c0(%rsp), %rdi
callq 0x5260
leaq 0x4bf(%rsp), %rdi
callq 0x5450
jmp 0x43485
movq 0x40(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x13ca0
movq %rax, %rdi
callq 0x51a0
movq %rax, %rsi
leaq 0x2a0(%rsp), %rdi
movl $0x8, %edx
callq 0x57d0
movq 0x2a0(%rsp), %rax
movq -0x18(%rax), %rax
leaq 0x2a0(%rsp,%rax), %rdi
callq 0x51e0
movb %al, 0x37(%rsp)
jmp 0x42d8d
movb 0x37(%rsp), %al
testb $0x1, %al
jne 0x42d9a
jmp 0x42e81
movq 0x40(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x13ca0
movq %rax, %rdx
leaq 0xd8fe(%rip), %rsi      # 0x506b0
leaq 0x260(%rsp), %rdi
callq 0xb960
jmp 0x42dc1
leaq 0xd8fc(%rip), %rdx      # 0x506c4
leaq 0x280(%rsp), %rdi
leaq 0x260(%rsp), %rsi
callq 0xb910
jmp 0x42ddf
movq 0x48(%rsp), %rdi
xorl %esi, %esi
leaq 0x280(%rsp), %rdx
callq 0xd9a0
jmp 0x42df5
leaq 0x280(%rsp), %rdi
callq 0x5260
leaq 0x260(%rsp), %rdi
callq 0x5260
movl $0x1, 0x25c(%rsp)
jmp 0x4345a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4b0(%rsp)
movl %eax, 0x4ac(%rsp)
jmp 0x43469
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4b0(%rsp)
movl %eax, 0x4ac(%rsp)
jmp 0x42e6f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4b0(%rsp)
movl %eax, 0x4ac(%rsp)
leaq 0x280(%rsp), %rdi
callq 0x5260
leaq 0x260(%rsp), %rdi
callq 0x5260
jmp 0x43469
leaq 0x218(%rsp), %rdi
leaq 0x2a0(%rsp), %rsi
callq 0x44370
jmp 0x42e98
leaq 0x1f8(%rsp), %rdi
leaq 0x218(%rsp), %rsi
callq 0x44410
jmp 0x42eaf
leaq 0xd733(%rip), %rsi      # 0x505e9
leaq 0x1f8(%rsp), %rdi
callq 0x443e0
movb %al, 0x36(%rsp)
jmp 0x42ec9
leaq 0x1f8(%rsp), %rdi
callq 0x5260
movb 0x36(%rsp), %al
testb $0x1, %al
jne 0x42ee3
jmp 0x42fef
leaq 0x2a0(%rsp), %rdi
callq 0x50c0
jmp 0x42ef2
leaq 0x1b8(%rsp), %rdi
leaq 0x218(%rsp), %rsi
callq 0x44410
jmp 0x42f09
leaq 0xd7c1(%rip), %rsi      # 0x506d1
leaq 0x1d8(%rsp), %rdi
leaq 0x1b8(%rsp), %rdx
callq 0x19f30
jmp 0x42f27
movq 0x48(%rsp), %rdi
xorl %esi, %esi
leaq 0x1d8(%rsp), %rdx
callq 0xd9a0
jmp 0x42f3d
leaq 0x1d8(%rsp), %rdi
callq 0x5260
leaq 0x1b8(%rsp), %rdi
callq 0x5260
movl $0x1, 0x25c(%rsp)
jmp 0x4343c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4b0(%rsp)
movl %eax, 0x4ac(%rsp)
jmp 0x4344b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4b0(%rsp)
movl %eax, 0x4ac(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x5260
jmp 0x4344b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4b0(%rsp)
movl %eax, 0x4ac(%rsp)
jmp 0x42fdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4b0(%rsp)
movl %eax, 0x4ac(%rsp)
leaq 0x1d8(%rsp), %rdi
callq 0x5260
leaq 0x1b8(%rsp), %rdi
callq 0x5260
jmp 0x4344b
leaq 0x198(%rsp), %rdi
leaq 0x218(%rsp), %rsi
callq 0x444f0
jmp 0x43006
movq 0x58(%rsp), %rdi
addq $0x68, %rdi
callq 0x3ea90
movq %rax, 0x28(%rsp)
jmp 0x4301b
movq 0x28(%rsp), %rsi
leaq 0x178(%rsp), %rdi
callq 0x43630
jmp 0x4302f
leaq 0x198(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0x445d0
movb %al, 0x27(%rsp)
leaq 0x178(%rsp), %rdi
callq 0x5260
movb 0x27(%rsp), %al
testb $0x1, %al
jne 0x43062
jmp 0x43256
movq 0x58(%rsp), %rdi
addq $0x68, %rdi
callq 0x3ec40
movl %eax, 0x20(%rsp)
jmp 0x43076
movl 0x20(%rsp), %eax
cmpl $0x0, %eax
jne 0x4318f
leaq 0xb0(%rsp), %rdi
leaq 0x198(%rsp), %rsi
callq 0x51b0
jmp 0x4309a
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0xbea0
jmp 0x430b1
leaq 0x118(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0xbfe0
jmp 0x430c8
movq 0x58(%rsp), %rdi
addq $0x68, %rdi
leaq 0x118(%rsp), %rsi
movq %rsi, 0x18(%rsp)
callq 0x43660
movq 0x18(%rsp), %rdi
callq 0xc450
leaq 0xd0(%rsp), %rdi
callq 0xc040
leaq 0xb0(%rsp), %rdi
callq 0x5260
movq 0x58(%rsp), %rdi
movl $0x1, %esi
callq 0xc080
jmp 0x43118
movq 0x58(%rsp), %rdi
addq $0x30, %rdi
callq 0x436a0
jmp 0x43128
jmp 0x43254
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4b0(%rsp)
movl %eax, 0x4ac(%rsp)
jmp 0x4342d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4b0(%rsp)
movl %eax, 0x4ac(%rsp)
jmp 0x4317d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4b0(%rsp)
movl %eax, 0x4ac(%rsp)
leaq 0xd0(%rsp), %rdi
callq 0xc040
leaq 0xb0(%rsp), %rdi
callq 0x5260
jmp 0x4342d
leaq 0x2a0(%rsp), %rdi
callq 0x50c0
jmp 0x4319e
leaq 0x8f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x5770
movq 0x10(%rsp), %rdx
leaq 0xd532(%rip), %rsi      # 0x506ee
leaq 0x90(%rsp), %rdi
callq 0x5590
jmp 0x431cb
movq 0x48(%rsp), %rdi
xorl %esi, %esi
leaq 0x90(%rsp), %rdx
callq 0xd9a0
jmp 0x431e1
leaq 0x90(%rsp), %rdi
callq 0x5260
leaq 0x8f(%rsp), %rdi
callq 0x5450
movl $0x1, 0x25c(%rsp)
jmp 0x4341e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4b0(%rsp)
movl %eax, 0x4ac(%rsp)
jmp 0x43242
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4b0(%rsp)
movl %eax, 0x4ac(%rsp)
leaq 0x90(%rsp), %rdi
callq 0x5260
leaq 0x8f(%rsp), %rdi
callq 0x5450
jmp 0x4342d
jmp 0x43256
leaq 0x2a25f(%rip), %rax     # 0x6d4bc
movb (%rax), %al
movb %al, 0x8e(%rsp)
leaq 0x218(%rsp), %rdi
callq 0x26020
movb %al, 0xf(%rsp)
jmp 0x43279
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x43283
jmp 0x432f7
leaq 0x218(%rsp), %rdi
callq 0x1d690
movw %ax, 0xc(%rsp)
jmp 0x43297
movq 0x58(%rsp), %rdi
movw 0xc(%rsp), %ax
movw %ax, 0x8c(%rsp)
leaq 0x8c(%rsp), %rsi
callq 0x3ed80
jmp 0x432b8
movb 0x8e(%rsp), %al
movb %al, 0x8a(%rsp)
movzbl 0x8a(%rsp), %edi
callq 0x1c680
movb %al, 0xb(%rsp)
jmp 0x432d9
movb 0xb(%rsp), %al
movb %al, 0x8b(%rsp)
movb 0x8b(%rsp), %al
movb %al, 0x8e(%rsp)
jmp 0x43266
leaq 0x218(%rsp), %rdi
callq 0x1d5f0
movb %al, 0xa(%rsp)
jmp 0x4330a
movb 0xa(%rsp), %al
testb $0x1, %al
jne 0x43314
jmp 0x43335
movq 0x58(%rsp), %rax
movq 0xd8(%rax), %rdi
movq (%rdi), %rax
movq 0x68(%rax), %rax
leaq 0x218(%rsp), %rsi
callq *%rax
jmp 0x43333
jmp 0x43335
leaq 0x218(%rsp), %rdi
callq 0x1dad0
movb %al, 0x9(%rsp)
jmp 0x43348
movb 0x9(%rsp), %al
testb $0x1, %al
jne 0x43352
jmp 0x43354
jmp 0x43373
leaq 0xa22e(%rip), %rdi      # 0x4d589
leaq 0xd3c4(%rip), %rsi      # 0x50726
movl $0x137, %edx            # imm = 0x137
leaq 0xd3cb(%rip), %rcx      # 0x50739
callq 0x52a0
leaq 0x2a0(%rsp), %rdi
callq 0x50c0
jmp 0x43382
leaq 0x67(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x5770
movq (%rsp), %rdx
leaq 0x954e(%rip), %rsi      # 0x4c8e9
leaq 0x68(%rsp), %rdi
callq 0x5590
jmp 0x433a7
movq 0x48(%rsp), %rdi
movl $0x1, %esi
leaq 0x68(%rsp), %rdx
callq 0xd9a0
jmp 0x433bd
leaq 0x68(%rsp), %rdi
callq 0x5260
leaq 0x67(%rsp), %rdi
callq 0x5450
movl $0x1, 0x25c(%rsp)
jmp 0x4341e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4b0(%rsp)
movl %eax, 0x4ac(%rsp)
jmp 0x43412
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x4b0(%rsp)
movl %eax, 0x4ac(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x5260
leaq 0x67(%rsp), %rdi
callq 0x5450
jmp 0x4342d
leaq 0x198(%rsp), %rdi
callq 0x5260
jmp 0x4343c
leaq 0x198(%rsp), %rdi
callq 0x5260
jmp 0x4344b
leaq 0x218(%rsp), %rdi
callq 0x44600
jmp 0x4345a
leaq 0x218(%rsp), %rdi
callq 0x44600
jmp 0x43469
leaq 0x2a0(%rsp), %rdi
callq 0x5100
jmp 0x43478
leaq 0x2a0(%rsp), %rdi
callq 0x5100
jmp 0x43485
movq 0x50(%rsp), %rax
addq $0x4f8, %rsp            # imm = 0x4F8
retq
movq 0x4b0(%rsp), %rdi
callq 0x5760
nopw %cs:(%rax,%rax)
nopl (%rax)