// File: /workspace/github_cpp_makefile_star2_O2/tewalds[P]morat/pentago/agentmcts.cpp
// Function: Morat::Pentago::AgentMCTS::search(double, unsigned long, int)
void AgentMCTS::search(double time, uint64_t max_runs, int verbose){
	Side to_play = rootboard.to_play();

	if(rootboard.outcome() >= Outcome::DRAW || (time <= 0 && max_runs == 0))
		return;

	Time starttime;

	pool.pause();

	if(runs)
		logerr("Pondered " + to_str(runs) + " runs\n");

	runs = 0;
	maxruns = max_runs;
	pool.reset();

	//let them run!
	pool.resume();

	pool.wait_pause(time);

	double time_used = Time() - starttime;


	if(verbose){
		DepthStats gamelen, treelen;
		double times[4] = {0,0,0,0};
		for(auto & t : pool){
			gamelen += t->gamelen;
			treelen += t->treelen;

			for(int a = 0; a < 4; a++)
				times[a] += t->times[a];
		}

		logerr("Finished:    " + to_str(runs) + " runs in " + to_str(time_used*1000, 0) + " msec: " + to_str(runs/time_used, 0) + " Games/s\n");
		if(runs > 0){
			logerr("Game length: " + gamelen.to_s() + "\n");
			logerr("Tree depth:  " + treelen.to_s() + "\n");
			if(profile)
				logerr("Times:       " + to_str(times[0], 3) + ", " + to_str(times[1], 3) + ", " + to_str(times[2], 3) + ", " + to_str(times[3], 3) + "\n");
		}

		if(root.outcome != Outcome::UNKNOWN)
			logerr("Solved as a " + root.outcome.to_s_rel(to_play) + "\n");

		std::string pvstr;
		for(auto m : get_pv())
			pvstr += " " + m.to_s();
		logerr("PV:         " + pvstr + "\n");

		if(verbose >= 3 && !root.children.empty())
			logerr("Move stats:\n" + move_stats(vecmove()));
	}

	pool.reset();
	runs = 0;


	if(ponder && root.outcome < Outcome::DRAW)
		pool.resume();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x308, %rsp            # imm = 0x308
movq %rdi, %r13
movb 0x99(%r13), %bpl
addq $0x80, %rdi
movl %edx, %r14d
movq %rsi, %r15
vmovsd %xmm0, 0x48(%rsp)
callq 0xa9d0
leaq 0x1864f(%rip), %rbx     # 0x24c19
cmpb (%rbx), %al
jge 0xce1e
vxorpd %xmm0, %xmm0, %xmm0
vucomisd 0x48(%rsp), %xmm0
setae %al
testq %r15, %r15
sete %cl
testb %cl, %al
jne 0xce1e
leaq 0xe8(%rsp), %rdi
callq 0x5df0
leaq 0x14a8(%r13), %r12
movq %r12, %rdi
callq 0xe516
movq 0xd8(%r13), %rsi
testq %rsi, %rsi
je 0xc69e
movb %bpl, 0x50(%rsp)
movl %r14d, %ebp
leaq 0x170(%rsp), %r14
movq %r14, %rdi
callq 0xaba2
leaq 0x13fed(%rip), %rsi     # 0x20625
leaq 0x150(%rsp), %rdi
movq %r14, %rdx
callq 0xaac0
leaq 0x13fe0(%rip), %rdx     # 0x2062f
leaq 0x2e8(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x7b4d
leaq 0x2e8(%rsp), %r14
movq %r14, %rdi
callq 0xaaae
movq %r14, %rdi
callq 0x5170
leaq 0x150(%rsp), %rdi
callq 0x5170
leaq 0x170(%rsp), %rdi
callq 0x5170
movl %ebp, %r14d
movb 0x50(%rsp), %bpl
andq $0x0, 0xd8(%r13)
movq %r12, %rdi
movq %r15, 0xe0(%r13)
callq 0xe582
movq %r12, %rdi
callq 0xe5f8
vmovsd 0x48(%rsp), %xmm0
movq %r12, %rdi
callq 0xe636
leaq 0x150(%rsp), %rdi
callq 0x5df0
testl %r14d, %r14d
je 0xcdf4
leaq 0x150(%rsp), %r15
movq %r12, 0xc0(%rsp)
leaq 0x170(%rsp), %r12
movl $0x3b9aca00, %eax       # imm = 0x3B9ACA00
movl %r14d, 0x5c(%rsp)
movq %r13, 0x50(%rsp)
vmovsd (%r15), %xmm0
andl $0x0, 0x8(%r15)
andl $0x0, 0x8(%r12)
movq %rax, (%r15)
movq %rax, (%r12)
vsubsd 0xe8(%rsp), %xmm0, %xmm0
vmovsd %xmm0, 0x48(%rsp)
vxorpd %xmm0, %xmm0, %xmm0
vmovupd %xmm0, 0x10(%r15)
vmovupd %xmm0, 0x10(%r12)
vxorpd %xmm0, %xmm0, %xmm0
vmovupd %ymm0, 0xf0(%rsp)
movq 0x14b0(%r13), %rbx
movq 0x14b8(%r13), %r14
movl $0xa0, %r13d
cmpq %r14, %rbx
je 0xc7b6
movq (%rbx), %rsi
movq %r15, %rdi
addq %r13, %rsi
vzeroupper
callq 0xe702
movq (%rbx), %rsi
movq %r12, %rdi
subq $-0x80, %rsi
callq 0xe702
movq (%rbx), %rax
xorl %ecx, %ecx
cmpq $0x4, %rcx
je 0xc7b0
vmovsd 0xc0(%rax,%rcx,8), %xmm0
vaddsd 0xf0(%rsp,%rcx,8), %xmm0, %xmm0
vmovsd %xmm0, 0xf0(%rsp,%rcx,8)
incq %rcx
jmp 0xc78a
addq $0x8, %rbx
jmp 0xc760
movq 0x50(%rsp), %rbx
leaq 0x130(%rsp), %r14
movq %r14, %rdi
movq 0xd8(%rbx), %rsi
vzeroupper
callq 0xaba2
leaq 0x1398a(%rip), %rsi     # 0x20166
leaq 0x80(%rsp), %rdi
movq %r14, %rdx
callq 0xaac0
leaq 0x13e43(%rip), %rdx     # 0x20636
leaq 0x60(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x7b4d
vmovsd 0x48(%rsp), %xmm0
vmulsd 0x13905(%rip), %xmm0, %xmm0 # 0x20118
leaq 0xc8(%rsp), %rdi
xorl %esi, %esi
callq 0x1df78
leaq 0xa0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
callq 0xab3b
leaq 0x1393c(%rip), %rdx     # 0x2017f
leaq 0x8(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x7b4d
vcvtusi2sdq 0xd8(%rbx), %xmm1, %xmm0
vdivsd 0x48(%rsp), %xmm0, %xmm0
leaq 0x110(%rsp), %rdi
xorl %esi, %esi
callq 0x1df78
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x110(%rsp), %rdx
callq 0xab3b
leaq 0x13db1(%rip), %rdx     # 0x20640
leaq 0x2c8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x7b4d
leaq 0x2c8(%rsp), %r14
movq %r14, %rdi
callq 0xaaae
movq %r14, %rdi
callq 0x5170
leaq 0x28(%rsp), %rdi
callq 0x5170
leaq 0x110(%rsp), %rdi
callq 0x5170
leaq 0x8(%rsp), %rdi
callq 0x5170
leaq 0xa0(%rsp), %rdi
callq 0x5170
leaq 0xc8(%rsp), %rdi
callq 0x5170
leaq 0x60(%rsp), %rdi
callq 0x5170
leaq 0x80(%rsp), %rdi
callq 0x5170
leaq 0x130(%rsp), %rdi
callq 0x5170
cmpq $0x0, 0xd8(%rbx)
je 0xcbdd
leaq 0x8(%rsp), %r14
leaq 0x150(%rsp), %rsi
movq %r14, %rdi
callq 0xe72e
leaq 0x13d08(%rip), %rsi     # 0x2064a
leaq 0x28(%rsp), %rdi
movq %r14, %rdx
callq 0xaac0
leaq 0x12ec2(%rip), %rdx     # 0x1f818
leaq 0x2a8(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x7b4d
leaq 0x2a8(%rsp), %r14
movq %r14, %rdi
callq 0xaaae
movq %r14, %rdi
callq 0x5170
leaq 0x28(%rsp), %rdi
callq 0x5170
leaq 0x8(%rsp), %rdi
callq 0x5170
leaq 0x8(%rsp), %r14
leaq 0x170(%rsp), %rsi
movq %r14, %rdi
callq 0xe72e
leaq 0x13ca8(%rip), %rsi     # 0x20658
leaq 0x28(%rsp), %rdi
movq %r14, %rdx
callq 0xaac0
leaq 0x12e54(%rip), %rdx     # 0x1f818
leaq 0x288(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x7b4d
leaq 0x288(%rsp), %r14
movq %r14, %rdi
callq 0xaaae
movq %r14, %rdi
callq 0x5170
leaq 0x28(%rsp), %rdi
callq 0x5170
leaq 0x8(%rsp), %rdi
callq 0x5170
cmpb $0x1, 0x48(%rbx)
jne 0xcbdd
vmovsd 0xf0(%rsp), %xmm0
leaq 0x110(%rsp), %r14
pushq $0x3
popq %rsi
movq %r14, %rdi
callq 0x1df78
leaq 0x13c37(%rip), %rsi     # 0x20666
leaq 0xc8(%rsp), %rdi
movq %r14, %rdx
callq 0xaac0
leaq 0x1370e(%rip), %rdx     # 0x20154
leaq 0x130(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x7b4d
vmovsd 0xf8(%rsp), %xmm0
leaq 0x1e8(%rsp), %rdi
pushq $0x3
popq %rsi
callq 0x1df78
leaq 0x80(%rsp), %rdi
leaq 0x130(%rsp), %rsi
leaq 0x1e8(%rsp), %rdx
callq 0xab3b
leaq 0x136bc(%rip), %rdx     # 0x20154
leaq 0x60(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x7b4d
vmovsd 0x100(%rsp), %xmm0
leaq 0x1c8(%rsp), %rdi
pushq $0x3
popq %rsi
callq 0x1df78
leaq 0xa0(%rsp), %rdi
leaq 0x60(%rsp), %rsi
leaq 0x1c8(%rsp), %rdx
callq 0xab3b
leaq 0x13670(%rip), %rdx     # 0x20154
leaq 0x8(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x7b4d
vmovsd 0x108(%rsp), %xmm0
leaq 0x1a8(%rsp), %rdi
pushq $0x3
popq %rsi
callq 0x1df78
leaq 0x28(%rsp), %rdi
leaq 0x8(%rsp), %rsi
leaq 0x1a8(%rsp), %rdx
callq 0xab3b
leaq 0x12ceb(%rip), %rdx     # 0x1f818
leaq 0x268(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x7b4d
leaq 0x268(%rsp), %r14
movq %r14, %rdi
callq 0xaaae
movq %r14, %rdi
callq 0x5170
leaq 0x28(%rsp), %rdi
callq 0x5170
leaq 0x1a8(%rsp), %rdi
callq 0x5170
leaq 0x8(%rsp), %rdi
callq 0x5170
leaq 0xa0(%rsp), %rdi
callq 0x5170
leaq 0x1c8(%rsp), %rdi
callq 0x5170
leaq 0x60(%rsp), %rdi
callq 0x5170
leaq 0x80(%rsp), %rdi
callq 0x5170
leaq 0x1e8(%rsp), %rdi
callq 0x5170
leaq 0x130(%rsp), %rdi
callq 0x5170
leaq 0xc8(%rsp), %rdi
callq 0x5170
leaq 0x110(%rsp), %rdi
callq 0x5170
leaq 0x18032(%rip), %rcx     # 0x24c16
movb 0xba(%rbx), %al
cmpb (%rcx), %al
je 0xcc5f
leaq 0x8(%rsp), %r14
leaq 0xba(%rbx), %rsi
movzbl %bpl, %edx
movq %r14, %rdi
callq 0x1ded0
leaq 0x13a67(%rip), %rsi     # 0x20674
leaq 0x28(%rsp), %rdi
movq %r14, %rdx
callq 0xaac0
leaq 0x12bf7(%rip), %rdx     # 0x1f818
leaq 0x248(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x7b4d
leaq 0x248(%rsp), %r14
movq %r14, %rdi
callq 0xaaae
movq %r14, %rdi
callq 0x5170
leaq 0x28(%rsp), %rdi
callq 0x5170
leaq 0x8(%rsp), %rdi
callq 0x5170
leaq 0x38(%rsp), %rax
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movq (%rbx), %rax
leaq 0x60(%rsp), %rdi
movq %rbx, %rsi
callq *0x40(%rax)
movq 0x60(%rsp), %rbx
movq 0x68(%rsp), %r12
leaq 0xa0(%rsp), %r15
leaq 0x17212(%rip), %r13     # 0x23ea9
leaq 0x8(%rsp), %rbp
leaq 0x28(%rsp), %r14
cmpq %r12, %rbx
je 0xccf0
movzwl (%rbx), %eax
movw %ax, 0x80(%rsp)
leaq 0x80(%rsp), %rsi
movq %r15, %rdi
callq 0xabfe
movq %rbp, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0xaac0
movq %r14, %rdi
movq %rbp, %rsi
callq 0x5730
movq %rbp, %rdi
callq 0x5170
movq %r15, %rdi
callq 0x5170
addq $0x2, %rbx
jmp 0xcca1
leaq 0x60(%rsp), %rdi
callq 0x947e
leaq 0x13490(%rip), %rsi     # 0x20191
leaq 0x8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x7b6c
leaq 0x12b01(%rip), %rdx     # 0x1f818
leaq 0x228(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x7b4d
movq 0x50(%rsp), %r13
leaq 0x17ee4(%rip), %rbx     # 0x24c19
movq 0xc0(%rsp), %r12
leaq 0x228(%rsp), %r14
movq %r14, %rdi
callq 0xaaae
movq %r14, %rdi
callq 0x5170
leaq 0x8(%rsp), %rdi
callq 0x5170
cmpl $0x3, 0x5c(%rsp)
jl 0xcdea
movq 0xc0(%r13), %rax
cmpq $0x2, %rax
jb 0xcdea
cmpw $0x0, 0x6(%rax)
je 0xcdea
leaq 0x190(%rsp), %rdx
vxorpd %xmm0, %xmm0, %xmm0
vmovapd %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
movq (%r13), %rax
leaq 0x8(%rsp), %rdi
movq %r13, %rsi
callq *0x48(%rax)
leaq 0x133f5(%rip), %rsi     # 0x2019e
leaq 0x208(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0xaac0
leaq 0x208(%rsp), %r14
movq %r14, %rdi
callq 0xaaae
movq %r14, %rdi
callq 0x5170
leaq 0x8(%rsp), %rdi
callq 0x5170
leaq 0x190(%rsp), %rdi
callq 0x947e
leaq 0x28(%rsp), %rdi
callq 0x5170
movq %r12, %rdi
callq 0xe582
andq $0x0, 0xd8(%r13)
cmpb $0x1, 0x38(%r13)
jne 0xce1e
movb 0xba(%r13), %al
cmpb (%rbx), %al
jge 0xce1e
movq %r12, %rdi
callq 0xe5f8
addq $0x308, %rsp            # imm = 0x308
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8(%rsp), %rdi
movq %rax, %rbx
callq 0x5170
jmp 0xce42
movq %rax, %rbx
leaq 0x190(%rsp), %rdi
jmp 0xd014
leaq 0x28(%rsp), %rdi
movq %rax, %rbx
callq 0x5170
jmp 0xce61
movq %rax, %rbx
leaq 0x1a8(%rsp), %rdi
callq 0x5170
jmp 0xce73
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x5170
jmp 0xce82
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x5170
jmp 0xce94
movq %rax, %rbx
leaq 0x1c8(%rsp), %rdi
callq 0x5170
leaq 0x60(%rsp), %rdi
callq 0x5170
leaq 0x80(%rsp), %rdi
callq 0x5170
leaq 0x1e8(%rsp), %rdi
callq 0x5170
leaq 0x130(%rsp), %rdi
callq 0x5170
leaq 0xc8(%rsp), %rdi
callq 0x5170
leaq 0x110(%rsp), %rdi
jmp 0xd01e
movq %rax, %rbx
jmp 0xcea1
movq %rax, %rbx
jmp 0xceab
movq %rax, %rbx
jmp 0xceb8
movq %rax, %rbx
jmp 0xcec5
movq %rax, %rbx
jmp 0xced2
movq %rax, %rbx
jmp 0xcedf
jmp 0xcf12
jmp 0xcf21
jmp 0xcf12
jmp 0xcf21
leaq 0x28(%rsp), %rdi
movq %rax, %rbx
callq 0x5170
jmp 0xcf24
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
jmp 0xd01e
leaq 0x8(%rsp), %rdi
movq %rax, %rbx
callq 0x5170
jmp 0xd019
jmp 0xcf42
movq %rax, %rbx
jmp 0xd019
leaq 0x28(%rsp), %rdi
movq %rax, %rbx
callq 0x5170
jmp 0xcf5c
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x5170
jmp 0xcf6e
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x5170
jmp 0xcf7d
movq %rax, %rbx
leaq 0xa0(%rsp), %rdi
callq 0x5170
jmp 0xcf8f
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x5170
leaq 0x60(%rsp), %rdi
callq 0x5170
leaq 0x80(%rsp), %rdi
callq 0x5170
leaq 0x130(%rsp), %rdi
jmp 0xd01e
movq %rax, %rbx
jmp 0xcf9c
movq %rax, %rbx
jmp 0xcfa6
movq %rax, %rbx
jmp 0xcfb3
leaq 0x150(%rsp), %rdi
movq %rax, %rbx
callq 0x5170
jmp 0xcfe1
movq %rax, %rbx
leaq 0x170(%rsp), %rdi
jmp 0xd01e
movq %rax, %rbx
jmp 0xd00f
movq %rax, %rbx
jmp 0xd002
leaq 0x8(%rsp), %rdi
movq %rax, %rbx
callq 0x5170
leaq 0xa0(%rsp), %rdi
callq 0x5170
leaq 0x60(%rsp), %rdi
callq 0x947e
leaq 0x28(%rsp), %rdi
callq 0x5170
movq %rbx, %rdi
callq 0x5690
nop