// File: /workspace/github_cpp_makefile_star2_O3/tewalds[P]morat/hex/agentmcts.cpp
// Function: Morat::Hex::AgentMCTS::move(Morat::Move const&)
void AgentMCTS::move(const Move & m){
	pool.pause();

	uword nodesbefore = nodes;

	if(keeptree && root.children.num() > 0){
		Node child;

		for(Node * i = root.children.begin(); i != root.children.end(); i++){
			if(i->move == m){
				child = *i;          //copy the child experience to temp
				child.swap_tree(*i); //move the child tree to temp
				break;
			}
		}

		nodes -= root.dealloc(ctmem);
		root = child;
		root.swap_tree(child);

		if(nodesbefore > 0)
			logerr("Nodes before: " + to_str(nodesbefore) + ", after: " + to_str(nodes) + ", saved " +  to_str(100.0*nodes/nodesbefore, 1) + "% of the tree\n");
	}else{
		nodes -= root.dealloc(ctmem);
		root = Node();
		root.move = m;
	}
	assert(nodes == root.size());

	rootboard.move(m);

	root.exp.addwins(visitexpand+1); //+1 to compensate for the virtual loss
	if(rootboard.outcome() < Outcome::DRAW)
		root.outcome = Outcome::UNKNOWN;

	if(ponder)
		pool.resume();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
leaq 0x54f0(%rdi), %rbx
movq %rdi, %r14
movq %rsi, %r15
movq %rbx, %rdi
callq 0x115ac
cmpb $0x1, 0xa1(%r14)
jne 0xf522
movq 0x4108(%r14), %r13
cmpq $0x2, %r13
jb 0xf522
cmpw $0x0, 0x6(%r13)
je 0xf522
leaq 0x26efe(%rip), %rax     # 0x363ae
vxorpd %xmm0, %xmm0, %xmm0
leaq 0x68(%rsp), %rbp
movq 0x4110(%r14), %r12
vmovupd %ymm0, -0x28(%rbp)
movw $0x0, -0x8(%rbp)
movb (%rax), %al
movb %al, -0x6(%rbp)
movl $0xfc78fd00, -0x5(%rbp) # imm = 0xFC78FD00
movb $0x78, -0x1(%rbp)
movq $0x0, (%rbp)
movzwl 0x6(%r13), %eax
testq %rax, %rax
je 0xf694
movb (%r15), %cl
movb 0x1(%r15), %dl
shll $0x4, %eax
addq $0x38, %r13
leaq (%rax,%rax,2), %rax
cmpb %cl, -0x4(%r13)
jne 0xf513
cmpb %dl, -0x3(%r13)
je 0xf654
addq $0x30, %r13
addq $-0x30, %rax
jne 0xf503
jmp 0xf694
leaq 0x40e0(%r14), %r12
leaq 0x4130(%r14), %rsi
movq %r12, %rdi
callq 0x124a0
movl %eax, %eax
subq %rax, 0x4110(%r14)
leaq 0x26e66(%rip), %rax     # 0x363ae
leaq 0x40(%rsp), %rsi
vxorpd %xmm0, %xmm0, %xmm0
vmovupd %ymm0, (%rsi)
movw $0x0, 0x20(%rsi)
movb (%rax), %al
movb %al, 0x22(%rsi)
movl $0xfc78fd00, 0x23(%rsi) # imm = 0xFC78FD00
movb $0x78, 0x27(%rsi)
movq $0x0, 0x28(%rsi)
movq %r12, %rdi
vzeroupper
callq 0x1297c
leaq 0x40(%rsp), %rdi
callq 0x12448
movzwl (%r15), %eax
movw %ax, 0x4104(%r14)
movq 0x4110(%r14), %r12
leaq 0x40e0(%r14), %rdi
callq 0x129ec
movl %eax, %eax
cmpq %rax, %r12
jne 0xfb45
movsbl (%r15), %eax
movsbl 0x10(%r14), %ecx
leaq 0x40(%rsp), %rsi
leaq 0x10(%r14), %rdi
movl $0x1, %edx
imull %eax, %ecx
movsbl 0x1(%r15), %eax
addl %ecx, %eax
movzwl (%r15), %ecx
movw %cx, (%rsi)
movl $0x1, %ecx
movw %ax, 0x2(%rsi)
callq 0x1388c
movl 0xa8(%r14), %eax
leaq 0x26dbb(%rip), %rcx     # 0x363b1
incl %eax
vmovq %rax, %xmm0
addq %rax, %rax
vmovq %rax, %xmm1
vpunpcklqdq %xmm0, %xmm1, %xmm0 # xmm0 = xmm1[0],xmm0[0]
vpaddq 0x40f0(%r14), %xmm0, %xmm0
vmovdqu %xmm0, 0x40f0(%r14)
movb 0x19(%r14), %al
cmpb (%rcx), %al
jge 0xf633
leaq 0x26d84(%rip), %rax     # 0x363ae
movb (%rax), %al
movb %al, 0x4102(%r14)
cmpb $0x1, 0x58(%r14)
jne 0xf642
movq %rbx, %rdi
callq 0x11718
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x28(%r13), %rsi
leaq 0x40(%rsp), %rdi
vzeroupper
callq 0x1297c
movq 0x68(%rsp), %rax
movq (%r13), %rcx
movq %rcx, 0x68(%rsp)
movq %rax, (%r13)
movq 0x68(%rsp), %rcx
cmpq $0x2, %rcx
jb 0xf68a
movq %rbp, 0x8(%rcx)
movq (%r13), %rax
cmpq $0x2, %rax
jb 0xf694
movq %r13, 0x8(%rax)
leaq 0x40e0(%r14), %r13
leaq 0x4130(%r14), %rsi
movq %r13, %rdi
vzeroupper
callq 0x124a0
movl %eax, %eax
subq %rax, 0x4110(%r14)
leaq 0x40(%rsp), %rsi
movq %r13, %rdi
callq 0x1297c
leaq 0x4108(%r14), %rcx
movq 0x68(%rsp), %rdx
movq (%rcx), %rax
movq %rdx, (%rcx)
movq %rax, 0x68(%rsp)
cmpq $0x2, %rdx
jb 0xf6e9
movq %rcx, 0x8(%rdx)
movq 0x68(%rsp), %rax
cmpq $0x2, %rax
jb 0xf6f3
movq %rbp, 0x8(%rax)
testq %r12, %r12
jne 0xf707
leaq 0x40(%rsp), %rdi
callq 0x12448
jmp 0xf594
leaq 0x138(%rsp), %rdi
movq %r12, %rsi
callq 0x1161f
leaq 0x249d4(%rip), %rcx     # 0x340f2
leaq 0x138(%rsp), %rdi
movl $0xe, %r8d
xorl %esi, %esi
xorl %edx, %edx
callq 0x5380
leaq 0x108(%rsp), %rsi
movq %rax, %rcx
addq $0x10, %rcx
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
cmpq %rcx, %rdx
jne 0xf75a
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%rsi)
jmp 0xf76d
movq %rdx, 0xf8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x108(%rsp)
movq 0x8(%rax), %rdx
leaq 0xf8(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0x22dfd(%rip), %rsi     # 0x32590
callq 0x56e0
leaq 0x88(%rsp), %rbp
movq %rax, %rcx
addq $0x10, %rcx
movq %rbp, -0x10(%rbp)
movq (%rax), %rdx
cmpq %rcx, %rdx
jne 0xf7be
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%rbp)
jmp 0xf7ce
movq %rdx, 0x78(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x88(%rsp)
movq 0x8(%rax), %rdx
movq %rdx, 0x80(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x4110(%r14), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x1161f
movq 0x80(%rsp), %r8
movq 0xe0(%rsp), %rdx
movq 0x78(%rsp), %rcx
movl $0xf, %edi
leaq (%rdx,%r8), %rax
cmpq %rbp, %rcx
je 0xf828
movq 0x88(%rsp), %rdi
movq 0xd8(%rsp), %rsi
cmpq %rdi, %rax
jbe 0xf854
leaq 0xe8(%rsp), %r9
movl $0xf, %edi
cmpq %r9, %rsi
je 0xf84f
movq 0xe8(%rsp), %rdi
cmpq %rdi, %rax
jbe 0xf860
leaq 0x78(%rsp), %rdi
callq 0x50c0
jmp 0xf871
leaq 0xd8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5380
leaq 0x10(%rsp), %rdx
leaq 0x10(%rax), %rcx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
cmpq %rcx, %rsi
jne 0xf890
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%rdx)
jmp 0xf89c
movq %rsi, (%rsp)
movq (%rcx), %rdx
movq %rdx, 0x10(%rsp)
movq 0x8(%rax), %rsi
movq %rax, %rdx
addq $0x8, %rdx
movq %rsi, 0x8(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x22cda(%rip), %rsi     # 0x3259a
movq %rsp, %rdi
callq 0x56e0
leaq 0xa8(%rsp), %r13
movq %rax, %rcx
addq $0x10, %rcx
movq %r13, -0x10(%r13)
movq (%rax), %rdx
cmpq %rcx, %rdx
jne 0xf8ef
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%r13)
jmp 0xf902
movq %rdx, 0x98(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xa8(%rsp)
movq 0x8(%rax), %rdx
movq %rdx, 0xa0(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
vcvtusi2sdq 0x4110(%r14), %xmm1, %xmm0
vmulsd 0x228f1(%rip), %xmm0, %xmm0 # 0x32220
vcvtusi2sd %r12, %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
leaq 0xb8(%rsp), %rdi
movl $0x1, %esi
callq 0x2f6e8
movq 0xa0(%rsp), %r8
movq 0xc0(%rsp), %rdx
movq 0x98(%rsp), %rcx
movl $0xf, %edi
leaq (%rdx,%r8), %rax
cmpq %r13, %rcx
je 0xf979
movq 0xa8(%rsp), %rdi
movq 0xb8(%rsp), %rsi
cmpq %rdi, %rax
jbe 0xf9a5
leaq 0xc8(%rsp), %r9
movl $0xf, %edi
cmpq %r9, %rsi
je 0xf9a0
movq 0xc8(%rsp), %rdi
cmpq %rdi, %rax
jbe 0xf9b4
leaq 0x98(%rsp), %rdi
callq 0x50c0
jmp 0xf9c5
leaq 0xb8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x5380
leaq 0x30(%rsp), %rdx
leaq 0x10(%rax), %rcx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
cmpq %rcx, %rsi
jne 0xf9e4
vmovupd (%rcx), %xmm0
vmovupd %xmm0, (%rdx)
jmp 0xf9f1
movq %rsi, 0x20(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x30(%rsp)
movq 0x8(%rax), %rsi
movq %rax, %rdx
addq $0x8, %rdx
movq %rsi, 0x28(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0x22b8e(%rip), %rsi     # 0x325a3
leaq 0x20(%rsp), %rdi
callq 0x56e0
leaq 0x128(%rsp), %r12
movq %rax, %rcx
addq $0x10, %rcx
movq %r12, -0x10(%r12)
movq (%rax), %rdi
cmpq %rcx, %rdi
jne 0xfa4a
vmovupd (%rcx), %xmm0
movq %r12, %rdi
vmovupd %xmm0, (%r12)
jmp 0xfa5d
movq %rdi, 0x118(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x128(%rsp)
movq 0x8(%rax), %rdx
movq %rdx, 0x120(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq 0x39551(%rip), %rax     # 0x48fd0
movq (%rax), %rsi
callq 0x5370
movq 0x118(%rsp), %rdi
cmpq %r12, %rdi
je 0xfa99
callq 0x52e0
leaq 0x30(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfaac
callq 0x52e0
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfac2
callq 0x52e0
movq 0x98(%rsp), %rdi
cmpq %r13, %rdi
je 0xfad4
callq 0x52e0
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfae7
callq 0x52e0
leaq 0xe8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfafd
callq 0x52e0
movq 0x78(%rsp), %rdi
cmpq %rbp, %rdi
je 0xfb0c
callq 0x52e0
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0xfb26
callq 0x52e0
leaq 0x148(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xf6f8
callq 0x52e0
jmp 0xf6f8
leaq 0x22a66(%rip), %rdi     # 0x325b2
leaq 0x22a74(%rip), %rsi     # 0x325c7
leaq 0x22a7f(%rip), %rcx     # 0x325d9
movl $0xfd, %edx
callq 0x51d0
jmp 0xfc38
leaq 0x30(%rsp), %rcx
movq %rax, %rbx
movq -0x10(%rcx), %rdi
cmpq %rcx, %rdi
je 0xfb84
callq 0x52e0
jmp 0xfb84
movq %rax, %rbx
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfb9f
callq 0x52e0
jmp 0xfb9f
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r13, %rdi
je 0xfbb6
callq 0x52e0
jmp 0xfbb6
movq %rax, %rbx
leaq 0x10(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfbce
callq 0x52e0
jmp 0xfbce
movq %rax, %rbx
leaq 0xe8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfbe9
callq 0x52e0
jmp 0xfbe9
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %rbp, %rdi
je 0xfbfd
callq 0x52e0
jmp 0xfbfd
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
leaq 0x108(%rsp), %rax
cmpq %rax, %rdi
je 0xfc1c
callq 0x52e0
jmp 0xfc1c
movq %rax, %rbx
leaq 0x148(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xfc3b
callq 0x52e0
jmp 0xfc3b
jmp 0xfc38
jmp 0xfc38
movq %rax, %rbx
leaq 0x40(%rsp), %rdi
callq 0x12448
movq %rbx, %rdi
callq 0x5670
nop