// File: tewalds[P]morat/hex/gtpagent.cpp
// Function: Morat::Hex::GTP::gtp_solve(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_solve(vecstr args){
	if(hist->outcome() >= 0)
		return GTPResponse(true, "resign");

	double use_time = (args.size() >= 1 ? from_str<double>(args[0]) : 0);
	if (use_time == 0)
		use_time = time_control.get_time(hist.len(), hist->moves_remain(), agent->gamelen());


	if(verbose)
		logerr("time remain: " + to_str(time_control.remain, 1) + ", time: " + to_str(use_time, 3) + ", sims: " + to_str(time_control.max_sims) + "\n");

	Time start;
	agent->search(use_time, time_control.max_sims, verbose);
	time_control.use(Time() - start);


	//TODO: find the outcome, not the best move...

	Move best = agent->return_move(verbose);

	if(verbose >= 2)
		logerr(hist->to_s(colorboard) + "\n");

	return GTPResponse(true, best.to_s());
}

// Assembly:
subq $0x258, %rsp            # imm = 0x258
movq %rdx, 0x40(%rsp)
movq %rdi, 0x48(%rsp)
movq %rdi, %rax
movq %rax, 0x50(%rsp)
movq %rdi, 0x250(%rsp)
movq %rsi, 0x248(%rsp)
movq %rdx, 0x240(%rsp)
movq 0x248(%rsp), %rdi
movq %rdi, 0x58(%rsp)
addq $0x68, %rdi
callq 0x3ea90
movq %rax, %rdi
callq 0x1a900
movb %al, 0x23f(%rsp)
movb $0x0, 0x23d(%rsp)
leaq 0x23e(%rsp), %rdi
leaq 0x23d(%rsp), %rsi
callq 0x1a870
leaq 0x23f(%rsp), %rdi
leaq 0x23e(%rsp), %rsi
callq 0x1a8c0
testb $0x1, %al
jne 0x37e91
jmp 0x37f3f
leaq 0x217(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x5770
movq 0x38(%rsp), %rdx
leaq 0x156fd(%rip), %rsi     # 0x4d5ac
leaq 0x218(%rsp), %rdi
callq 0x5590
jmp 0x37ebe
movq 0x48(%rsp), %rdi
movl $0x1, %esi
leaq 0x218(%rsp), %rdx
callq 0xd9a0
jmp 0x37ed7
leaq 0x218(%rsp), %rdi
callq 0x5260
leaq 0x217(%rsp), %rdi
callq 0x5450
jmp 0x384af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
jmp 0x37f2d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
leaq 0x218(%rsp), %rdi
callq 0x5260
leaq 0x217(%rsp), %rdi
callq 0x5450
jmp 0x384bc
movq 0x40(%rsp), %rdi
callq 0x13c80
cmpq $0x1, %rax
jb 0x37f6d
movq 0x40(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x13ca0
movq %rax, %rdi
callq 0x3eaa0
vmovsd %xmm0, 0x30(%rsp)
jmp 0x37f79
vpxor %xmm0, %xmm0, %xmm0
vmovsd %xmm0, 0x30(%rsp)
jmp 0x37f79
vmovsd 0x30(%rsp), %xmm0
vmovsd %xmm0, 0x1f8(%rsp)
vmovsd 0x1f8(%rsp), %xmm0
vpxor %xmm1, %xmm1, %xmm1
vucomisd %xmm1, %xmm0
jne 0x38008
jp 0x38008
movq 0x58(%rsp), %rdi
movq %rdi, %rax
addq $0x30, %rax
movq %rax, 0x20(%rsp)
addq $0x68, %rdi
callq 0x3ec40
movq 0x58(%rsp), %rdi
movl %eax, 0x28(%rsp)
addq $0x68, %rdi
callq 0x3ea90
movq %rax, %rdi
callq 0x28e80
movl %eax, %ecx
movq 0x58(%rsp), %rax
movl %ecx, 0x2c(%rsp)
movq 0xd8(%rax), %rdi
movq (%rdi), %rax
callq *0x50(%rax)
movq 0x20(%rsp), %rdi
movl 0x28(%rsp), %esi
movl 0x2c(%rsp), %edx
vcvttsd2si %xmm0, %ecx
callq 0x3eb30
vmovsd %xmm0, 0x1f8(%rsp)
movq 0x58(%rsp), %rax
cmpl $0x0, 0xc8(%rax)
je 0x382f9
movq 0x58(%rsp), %rax
vmovsd 0x60(%rax), %xmm0
leaq 0x118(%rsp), %rdi
movq %rdi, 0x18(%rsp)
movl $0x1, %esi
callq 0x48780
movq 0x18(%rsp), %rdx
leaq 0x1769b(%rip), %rsi     # 0x4f6e2
leaq 0x138(%rsp), %rdi
callq 0x19f30
jmp 0x38056
leaq 0x17693(%rip), %rdx     # 0x4f6f0
leaq 0x158(%rsp), %rdi
leaq 0x138(%rsp), %rsi
callq 0xb910
jmp 0x38074
vmovsd 0x1f8(%rsp), %xmm0
leaq 0xf8(%rsp), %rdi
movl $0x3, %esi
callq 0x48780
jmp 0x38091
leaq 0x178(%rsp), %rdi
leaq 0x158(%rsp), %rsi
leaq 0xf8(%rsp), %rdx
callq 0x19e40
jmp 0x380b0
leaq 0x17642(%rip), %rdx     # 0x4f6f9
leaq 0x198(%rsp), %rdi
leaq 0x178(%rsp), %rsi
callq 0xb910
jmp 0x380ce
movq 0x58(%rsp), %rax
movq 0x58(%rax), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x3ec50
jmp 0x380e6
leaq 0x1b8(%rsp), %rdi
leaq 0x198(%rsp), %rsi
leaq 0xd8(%rsp), %rdx
callq 0x19e40
jmp 0x38105
leaq 0x147dc(%rip), %rdx     # 0x4c8e8
leaq 0x1d8(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
callq 0xb910
jmp 0x38123
leaq 0x1d8(%rsp), %rdi
callq 0x1a9b0
jmp 0x38132
leaq 0x1d8(%rsp), %rdi
callq 0x5260
leaq 0x1b8(%rsp), %rdi
callq 0x5260
leaq 0xd8(%rsp), %rdi
callq 0x5260
leaq 0x198(%rsp), %rdi
callq 0x5260
leaq 0x178(%rsp), %rdi
callq 0x5260
leaq 0xf8(%rsp), %rdi
callq 0x5260
leaq 0x158(%rsp), %rdi
callq 0x5260
leaq 0x138(%rsp), %rdi
callq 0x5260
leaq 0x118(%rsp), %rdi
callq 0x5260
jmp 0x382f9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
jmp 0x382e7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
jmp 0x382da
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
jmp 0x382cd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
jmp 0x382c0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
jmp 0x382b3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
jmp 0x382a6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
jmp 0x38299
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
jmp 0x3828c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
leaq 0x1d8(%rsp), %rdi
callq 0x5260
leaq 0x1b8(%rsp), %rdi
callq 0x5260
leaq 0xd8(%rsp), %rdi
callq 0x5260
leaq 0x198(%rsp), %rdi
callq 0x5260
leaq 0x178(%rsp), %rdi
callq 0x5260
leaq 0xf8(%rsp), %rdi
callq 0x5260
leaq 0x158(%rsp), %rdi
callq 0x5260
leaq 0x138(%rsp), %rdi
callq 0x5260
leaq 0x118(%rsp), %rdi
callq 0x5260
jmp 0x384bc
leaq 0xd0(%rsp), %rdi
callq 0x6780
movq 0x58(%rsp), %rax
movq 0xd8(%rax), %rdi
vmovsd 0x1f8(%rsp), %xmm0
movq 0x58(%rax), %rsi
movl 0xc8(%rax), %edx
movq (%rdi), %rax
callq *0x10(%rax)
movq 0x58(%rsp), %rax
addq $0x30, %rax
movq %rax, 0x10(%rsp)
leaq 0xc8(%rsp), %rdi
callq 0x6780
leaq 0xc8(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x1ad50
movq 0x10(%rsp), %rdi
callq 0x3ece0
movq 0x58(%rsp), %rax
movq 0xd8(%rax), %rdi
movl 0xc8(%rax), %esi
movq (%rdi), %rax
callq *0x18(%rax)
movw %ax, %cx
movq 0x58(%rsp), %rax
movw %cx, 0xc6(%rsp)
cmpl $0x2, 0xc8(%rax)
jl 0x38458
movq 0x58(%rsp), %rdi
addq $0x68, %rdi
callq 0x3ea90
movq %rax, %rsi
movq 0x58(%rsp), %rax
movzbl 0xcd(%rax), %edx
andl $0x1, %edx
leaq 0x80(%rsp), %rdi
movq %rdi, 0x8(%rsp)
callq 0x35f30
movq 0x8(%rsp), %rsi
leaq 0x14510(%rip), %rdx     # 0x4c8e8
leaq 0xa0(%rsp), %rdi
callq 0xb910
jmp 0x383e7
leaq 0xa0(%rsp), %rdi
callq 0x1a9b0
jmp 0x383f6
leaq 0xa0(%rsp), %rdi
callq 0x5260
leaq 0x80(%rsp), %rdi
callq 0x5260
jmp 0x38458
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
jmp 0x38449
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
leaq 0xa0(%rsp), %rdi
callq 0x5260
leaq 0x80(%rsp), %rdi
callq 0x5260
jmp 0x384bc
leaq 0x60(%rsp), %rdi
movq %rdi, (%rsp)
leaq 0xc6(%rsp), %rsi
callq 0x19f80
movq 0x48(%rsp), %rdi
movq (%rsp), %rdx
movl $0x1, %esi
callq 0xd9a0
jmp 0x38483
leaq 0x60(%rsp), %rdi
callq 0x5260
jmp 0x384af
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x208(%rsp)
movl %eax, 0x204(%rsp)
leaq 0x60(%rsp), %rdi
callq 0x5260
jmp 0x384bc
movq 0x50(%rsp), %rax
addq $0x258, %rsp            # imm = 0x258
retq
movq 0x208(%rsp), %rdi
callq 0x5760
nopl (%rax)