// File: tewalds[P]morat/hex/agentpns.cpp
// Function: Morat::Hex::AgentPNS::search(double, unsigned long, int)
void AgentPNS::search(double time, uint64_t maxiters, int verbose){
	max_nodes_seen = maxiters;

	if(rootboard.outcome() >= 0)
		return;

	Time starttime;

	pool.reset();
	pool.resume();

	pool.wait_pause(time);


	double time_used = Time() - starttime;


	if(verbose){
		DepthStats treelen;
		for(auto & t : pool)
			treelen += t->treelen;

		logerr("Finished:    " + to_str(nodes_seen) + " nodes created in " + to_str(time_used*1000, 0) + " msec: " + to_str(nodes_seen/time_used, 0) + " Nodes/s\n");
		if(nodes_seen > 0){
			logerr("Tree depth:  " + treelen.to_s() + "\n");
		}

		Side to_play = rootboard.to_play();

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

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

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

// Assembly:
subq $0x458, %rsp            # imm = 0x458
movq %rdi, 0x450(%rsp)
vmovsd %xmm0, 0x448(%rsp)
movq %rsi, 0x440(%rsp)
movl %edx, 0x43c(%rsp)
movq 0x450(%rsp), %rdi
movq %rdi, 0x38(%rsp)
movq 0x440(%rsp), %rax
movq %rax, 0x1520(%rdi)
addq $0x10, %rdi
callq 0x1a900
movb %al, 0x43b(%rsp)
movb $0x0, 0x439(%rsp)
leaq 0x43a(%rsp), %rdi
leaq 0x439(%rsp), %rsi
callq 0x1a870
leaq 0x43b(%rsp), %rdi
leaq 0x43a(%rsp), %rsi
callq 0x1a8c0
testb $0x1, %al
jne 0x2d51b
jmp 0x2d520
jmp 0x2e056
leaq 0x430(%rsp), %rdi
callq 0x6780
movq 0x38(%rsp), %rdi
addq $0x1430, %rdi           # imm = 0x1430
callq 0x30170
movq 0x38(%rsp), %rdi
addq $0x1430, %rdi           # imm = 0x1430
callq 0x30250
movq 0x38(%rsp), %rdi
addq $0x1430, %rdi           # imm = 0x1430
vmovsd 0x448(%rsp), %xmm0
callq 0x302c0
leaq 0x420(%rsp), %rdi
callq 0x6780
leaq 0x420(%rsp), %rdi
leaq 0x430(%rsp), %rsi
callq 0x1ad50
vmovsd %xmm0, 0x428(%rsp)
cmpl $0x0, 0x43c(%rsp)
je 0x2e056
leaq 0x400(%rsp), %rdi
callq 0x1ad70
movq 0x38(%rsp), %rax
addq $0x1430, %rax           # imm = 0x1430
movq %rax, 0x3f8(%rsp)
movq 0x3f8(%rsp), %rdi
callq 0x30440
movq %rax, 0x3f0(%rsp)
movq 0x3f8(%rsp), %rdi
callq 0x30470
movq %rax, 0x3e8(%rsp)
leaq 0x3f0(%rsp), %rdi
leaq 0x3e8(%rsp), %rsi
callq 0x304a0
testb $0x1, %al
jne 0x2d607
jmp 0x2d64a
leaq 0x3f0(%rsp), %rdi
callq 0x304e0
movq %rax, 0x3e0(%rsp)
movq 0x3e0(%rsp), %rax
movq (%rax), %rsi
addq $0x9ca8, %rsi           # imm = 0x9CA8
leaq 0x400(%rsp), %rdi
callq 0x1ae30
leaq 0x3f0(%rsp), %rdi
callq 0x304f0
jmp 0x2d5ec
movq 0x38(%rsp), %rax
movq 0x1518(%rax), %rsi
leaq 0x300(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0x1a9f0
movq 0x30(%rsp), %rdx
leaq 0x1fca5(%rip), %rsi     # 0x4d319
leaq 0x320(%rsp), %rdi
callq 0x19f30
jmp 0x2d683
leaq 0x21208(%rip), %rdx     # 0x4e892
leaq 0x340(%rsp), %rdi
leaq 0x320(%rsp), %rsi
callq 0xb910
jmp 0x2d6a1
vmovsd 0x428(%rsp), %xmm0
vmovsd 0x1fb1e(%rip), %xmm1    # 0x4d1d0
vmulsd %xmm1, %xmm0, %xmm0
leaq 0x2d0(%rsp), %rdi
xorl %esi, %esi
callq 0x48780
jmp 0x2d6c7
leaq 0x360(%rsp), %rdi
leaq 0x340(%rsp), %rsi
leaq 0x2d0(%rsp), %rdx
callq 0x19e40
jmp 0x2d6e6
leaq 0x1fc44(%rip), %rdx     # 0x4d331
leaq 0x380(%rsp), %rdi
leaq 0x360(%rsp), %rsi
callq 0xb910
jmp 0x2d704
movq 0x38(%rsp), %rax
vcvtusi2sdq 0x1518(%rax), %xmm0, %xmm0
vmovsd 0x428(%rsp), %xmm1
vdivsd %xmm1, %xmm0, %xmm0
leaq 0x2b0(%rsp), %rdi
xorl %esi, %esi
callq 0x48780
jmp 0x2d731
leaq 0x3a0(%rsp), %rdi
leaq 0x380(%rsp), %rsi
leaq 0x2b0(%rsp), %rdx
callq 0x19e40
jmp 0x2d750
leaq 0x2114e(%rip), %rdx     # 0x4e8a5
leaq 0x3c0(%rsp), %rdi
leaq 0x3a0(%rsp), %rsi
callq 0xb910
jmp 0x2d76e
leaq 0x3c0(%rsp), %rdi
callq 0x1a9b0
jmp 0x2d77d
leaq 0x3c0(%rsp), %rdi
callq 0x5260
leaq 0x3a0(%rsp), %rdi
callq 0x5260
leaq 0x2b0(%rsp), %rdi
callq 0x5260
leaq 0x380(%rsp), %rdi
callq 0x5260
leaq 0x360(%rsp), %rdi
callq 0x5260
leaq 0x2d0(%rsp), %rdi
callq 0x5260
leaq 0x340(%rsp), %rdi
callq 0x5260
leaq 0x320(%rsp), %rdi
callq 0x5260
leaq 0x300(%rsp), %rdi
callq 0x5260
movq 0x38(%rsp), %rax
cmpq $0x0, 0x1518(%rax)
jbe 0x2da4c
leaq 0x250(%rsp), %rdi
movq %rdi, 0x28(%rsp)
leaq 0x400(%rsp), %rsi
callq 0x1aee0
movq 0x28(%rsp), %rdx
leaq 0x1fb26(%rip), %rsi     # 0x4d351
leaq 0x270(%rsp), %rdi
callq 0x19f30
jmp 0x2d83a
leaq 0x1f0a7(%rip), %rdx     # 0x4c8e8
leaq 0x290(%rsp), %rdi
leaq 0x270(%rsp), %rsi
callq 0xb910
jmp 0x2d858
leaq 0x290(%rsp), %rdi
callq 0x1a9b0
jmp 0x2d867
leaq 0x290(%rsp), %rdi
callq 0x5260
leaq 0x270(%rsp), %rdi
callq 0x5260
leaq 0x250(%rsp), %rdi
callq 0x5260
jmp 0x2da4c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2d9ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2d9c1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2d9b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2d9a7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2d99a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2d98d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2d980
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2d973
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
leaq 0x3c0(%rsp), %rdi
callq 0x5260
leaq 0x3a0(%rsp), %rdi
callq 0x5260
leaq 0x2b0(%rsp), %rdi
callq 0x5260
leaq 0x380(%rsp), %rdi
callq 0x5260
leaq 0x360(%rsp), %rdi
callq 0x5260
leaq 0x2d0(%rsp), %rdi
callq 0x5260
leaq 0x340(%rsp), %rdi
callq 0x5260
leaq 0x320(%rsp), %rdi
callq 0x5260
leaq 0x300(%rsp), %rdi
callq 0x5260
jmp 0x2e05e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2da3a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2da2d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
leaq 0x290(%rsp), %rdi
callq 0x5260
leaq 0x270(%rsp), %rdi
callq 0x5260
leaq 0x250(%rsp), %rdi
callq 0x5260
jmp 0x2e05e
movq 0x38(%rsp), %rdi
addq $0x10, %rdi
callq 0x1a8a0
movq 0x38(%rsp), %rsi
movb %al, 0x24f(%rsp)
addq $0x1540, %rsi           # imm = 0x1540
leaq 0x1e8(%rsp), %rdi
movq %rdi, 0x20(%rsp)
callq 0x2c960
movq 0x20(%rsp), %rdx
leaq 0x20e24(%rip), %rsi     # 0x4e8af
leaq 0x208(%rsp), %rdi
callq 0x19f30
jmp 0x2da9a
leaq 0x1ee47(%rip), %rdx     # 0x4c8e8
leaq 0x228(%rsp), %rdi
leaq 0x208(%rsp), %rsi
callq 0xb910
jmp 0x2dab8
leaq 0x228(%rsp), %rdi
callq 0x1a9b0
jmp 0x2dac7
leaq 0x228(%rsp), %rdi
callq 0x5260
leaq 0x208(%rsp), %rdi
callq 0x5260
leaq 0x1e8(%rsp), %rdi
callq 0x5260
movq 0x38(%rsp), %rax
addq $0x1540, %rax           # imm = 0x1540
movq %rax, 0x18(%rsp)
movb 0x24f(%rsp), %al
movb %al, 0x1e5(%rsp)
movzbl 0x1e5(%rsp), %edi
callq 0x1c680
movq 0x18(%rsp), %rdi
movb %al, 0x1e6(%rsp)
movzbl 0x1e6(%rsp), %esi
callq 0x30510
movb %al, 0x1e7(%rsp)
leaq 0x1e7(%rsp), %rdi
leaq 0x3f978(%rip), %rsi     # 0x6d4c0
callq 0x1b350
testb $0x1, %al
jne 0x2db56
jmp 0x2dcd2
movb 0x24f(%rsp), %al
movb %al, 0x17f(%rsp)
movzbl 0x17f(%rsp), %edx
leaq 0x180(%rsp), %rdi
movq %rdi, 0x10(%rsp)
leaq 0x1e7(%rsp), %rsi
callq 0x48380
movq 0x10(%rsp), %rdx
leaq 0x1f7f7(%rip), %rsi     # 0x4d389
leaq 0x1a0(%rsp), %rdi
callq 0x19f30
jmp 0x2dba1
leaq 0x1ed40(%rip), %rdx     # 0x4c8e8
leaq 0x1c0(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
callq 0xb910
jmp 0x2dbbf
leaq 0x1c0(%rsp), %rdi
callq 0x1a9b0
jmp 0x2dbce
leaq 0x1c0(%rsp), %rdi
callq 0x5260
leaq 0x1a0(%rsp), %rdi
callq 0x5260
leaq 0x180(%rsp), %rdi
callq 0x5260
jmp 0x2dcd2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2dc54
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2dc47
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
leaq 0x228(%rsp), %rdi
callq 0x5260
leaq 0x208(%rsp), %rdi
callq 0x5260
leaq 0x1e8(%rsp), %rdi
callq 0x5260
jmp 0x2e05e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2dcc0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2dcb3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
leaq 0x1c0(%rsp), %rdi
callq 0x5260
leaq 0x1a0(%rsp), %rdi
callq 0x5260
leaq 0x180(%rsp), %rdi
callq 0x5260
jmp 0x2e05e
leaq 0x158(%rsp), %rdi
callq 0x55a0
movq 0x38(%rsp), %rsi
leaq 0x138(%rsp), %rdi
callq 0x1b390
jmp 0x2dcf3
leaq 0x138(%rsp), %rax
movq %rax, 0x150(%rsp)
movq 0x150(%rsp), %rdi
callq 0x1b430
movq %rax, 0x130(%rsp)
movq 0x150(%rsp), %rdi
callq 0x1b460
movq %rax, 0x128(%rsp)
leaq 0x130(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x1b490
testb $0x1, %al
jne 0x2dd71
leaq 0x138(%rsp), %rdi
callq 0x11920
jmp 0x2de6d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2e047
leaq 0x130(%rsp), %rdi
callq 0x1b4d0
movw (%rax), %ax
movw %ax, 0x126(%rsp)
leaq 0xe0(%rsp), %rdi
leaq 0x126(%rsp), %rsi
callq 0x19f80
jmp 0x2dda0
leaq 0x22b30(%rip), %rsi     # 0x508d7
leaq 0x100(%rsp), %rdi
leaq 0xe0(%rsp), %rdx
callq 0x19f30
jmp 0x2ddbe
leaq 0x158(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x5520
jmp 0x2ddd5
leaq 0x100(%rsp), %rdi
callq 0x5260
leaq 0xe0(%rsp), %rdi
callq 0x5260
leaq 0x130(%rsp), %rdi
callq 0x1b4e0
jmp 0x2dd2d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2de5b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2de4e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x5260
leaq 0xe0(%rsp), %rdi
callq 0x5260
leaq 0x138(%rsp), %rdi
callq 0x11920
jmp 0x2e047
leaq 0x1f522(%rip), %rsi     # 0x4d396
leaq 0xa0(%rsp), %rdi
leaq 0x158(%rsp), %rdx
callq 0xb960
jmp 0x2de8b
leaq 0x1ea56(%rip), %rdx     # 0x4c8e8
leaq 0xc0(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0xb910
jmp 0x2dea9
leaq 0xc0(%rsp), %rdi
callq 0x1a9b0
jmp 0x2deb8
leaq 0xc0(%rsp), %rdi
callq 0x5260
leaq 0xa0(%rsp), %rdi
callq 0x5260
cmpl $0x3, 0x43c(%rsp)
jl 0x2e038
movq 0x38(%rsp), %rdi
addq $0x1558, %rdi           # imm = 0x1558
callq 0x305c0
movb %al, 0xf(%rsp)
jmp 0x2def7
movb 0xf(%rsp), %al
testb $0x1, %al
jne 0x2e038
jmp 0x2df05
vpxor %xmm0, %xmm0, %xmm0
vmovdqa %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
leaq 0x40(%rsp), %rdi
movq %rdi, (%rsp)
callq 0x118a0
movq 0x38(%rsp), %rsi
movq (%rsp), %rdx
movq (%rsi), %rax
movq 0x48(%rax), %rax
leaq 0x60(%rsp), %rdi
callq *%rax
jmp 0x2df3f
leaq 0x1f45d(%rip), %rsi     # 0x4d3a3
leaq 0x80(%rsp), %rdi
leaq 0x60(%rsp), %rdx
callq 0x19f30
jmp 0x2df5a
leaq 0x80(%rsp), %rdi
callq 0x1a9b0
jmp 0x2df69
leaq 0x80(%rsp), %rdi
callq 0x5260
leaq 0x60(%rsp), %rdi
callq 0x5260
leaq 0x40(%rsp), %rdi
callq 0x11920
jmp 0x2e038
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2dfc6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
leaq 0xc0(%rsp), %rdi
callq 0x5260
leaq 0xa0(%rsp), %rdi
callq 0x5260
jmp 0x2e047
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2e02c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
jmp 0x2e022
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x2f8(%rsp)
movl %eax, 0x2f4(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x5260
leaq 0x60(%rsp), %rdi
callq 0x5260
leaq 0x40(%rsp), %rdi
callq 0x11920
jmp 0x2e047
leaq 0x158(%rsp), %rdi
callq 0x5260
jmp 0x2e056
leaq 0x158(%rsp), %rdi
callq 0x5260
jmp 0x2e05e
addq $0x458, %rsp            # imm = 0x458
retq
movq 0x2f8(%rsp), %rdi
callq 0x5760
nopl (%rax,%rax)