// File: /workspace/github_cpp_makefile_star2_O1/tewalds[P]morat/pentago/agentmctsthread.cpp
// Function: Morat::Pentago::AgentMCTS::AgentThread::create_children(Morat::Pentago::Board const&, Morat::Pentago::AgentMCTS::Node*)
bool AgentMCTS::AgentThread::create_children(const Board & board, Node * node){
	if(!node->children.lock())
		return false;

	CompactTree<Node>::Children temp;
	temp.alloc(board.moves_avail(), agent->ctmem);

	Node * child = temp.begin(),
	     * end   = temp.end();
	MoveIterator move(board, agent->prunesymmetry);
	int num_moves = 0;
	for(; !move.done() && child != end; ++move, ++child){
		*child = Node(*move);
		const Board & after = move.board();

		if(agent->minimax){
			child->outcome = after.outcome();

			if(child->outcome == board.to_play()){ //proven win from here, don't need children
				node->outcome = child->outcome;
				node->proofdepth = 1;
				node->bestmove = *move;
				node->children.unlock();
				temp.dealloc(agent->ctmem);
				return true;
			}
		}

		if(agent->knowledge)
			add_knowledge(after, node, child);
		num_moves++;
	}

	if(agent->prunesymmetry)
		temp.shrink(num_moves); //shrink the node to ignore the extra moves
	else{ //both end conditions should happen in parallel
		assert(move.done() && child == end);
	}

	//sort in decreasing order by knowledge
//	sort(temp.begin(), temp.end(), sort_node_know);

	PLUS(agent->nodes, temp.num());
	node->children.swap(temp);
	assert(temp.unlock());

	return true;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl $0x1, %ecx
xorl %eax, %eax
lock
cmpxchgq %rcx, 0x18(%rdx)
sete %al
jne 0x17b9c
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r12
movb %al, 0xf(%rsp)
movq $0x0, 0x10(%rsp)
movq %rsi, %rdi
callq 0xe726
shll $0x3, %eax
movl $0xe8, %edx
addq 0x40(%r12), %rdx
leaq 0x10(%rsp), %rdi
movl %eax, %esi
callq 0x14bda
movq 0x10(%rsp), %rcx
leaq 0x10(%rcx), %rax
xorl %r13d, %r13d
movl $0x0, %r15d
cmpq $0x2, %rcx
cmovaeq %rax, %r15
jb 0x17963
movzwl 0x6(%rcx), %ecx
shll $0x5, %ecx
addq %rcx, %rax
movq %rax, %r13
movq 0x40(%r12), %rax
movzbl 0x6c(%rax), %edx
leaq 0x48(%rsp), %rdi
movq %rbx, 0x40(%rsp)
movq %rbx, %rsi
callq 0xe0ba
movq %r14, 0x18(%rsp)
movb 0x78(%rsp), %dl
cmpb $0x24, %dl
setge %al
cmpq %r13, %r15
sete %cl
xorl %ebp, %ebp
cmpb $0x23, %dl
jg 0x17af2
cmpq %r13, %r15
je 0x17af2
addq $0x20, %r15
xorl %ebp, %ebp
leaq 0x20(%rsp), %rbx
leaq -0x20(%r15), %rdi
leaq 0x1a3e9(%rip), %rax     # 0x31da6
movb (%rax), %al
vxorps %xmm0, %xmm0, %xmm0
vmovaps %xmm0, 0x20(%rsp)
movw $0x0, 0x30(%rsp)
movb %al, 0x32(%rsp)
movb $0x0, 0x33(%rsp)
movzwl 0x78(%rsp), %eax
movw %ax, 0x34(%rsp)
movw $0xefc, 0x36(%rsp)      # imm = 0xEFC
movq $0x0, 0x38(%rsp)
movq %rbx, %rsi
callq 0x1447c
movq %rbx, %r14
movq %rbx, %rdi
callq 0x13f14
movq 0x40(%r12), %rax
cmpl $0x0, 0x64(%rax)
je 0x17a90
movb 0x6a(%rsp), %al
leaq 0x1a389(%rip), %rcx     # 0x31da5
cmpb (%rcx), %al
jne 0x17a2e
leaq 0x50(%rsp), %rdi
callq 0xe358
movb %al, 0x6a(%rsp)
movb 0x6a(%rsp), %al
movb %al, -0xe(%r15)
movq 0x40(%rsp), %rcx
cmpb 0x19(%rcx), %al
jne 0x17a90
movq 0x18(%rsp), %rdx
movb %al, 0x12(%rdx)
movb $0x1, 0x13(%rdx)
movzwl 0x78(%rsp), %eax
movw %ax, 0x16(%rdx)
xorl %ecx, %ecx
movl $0x1, %eax
lock
cmpxchgq %rcx, 0x18(%rdx)
movq 0x10(%rsp), %rsi
testq %rsi, %rsi
je 0x17ab8
movq 0x40(%r12), %rdi
movl $0xe8, %eax
addq %rax, %rdi
xorl %ecx, %ecx
movq %rsi, %rax
lock
cmpxchgq %rcx, 0x10(%rsp)
jne 0x17ab8
callq 0x15064
xorl %ecx, %ecx
jmp 0x17ab8
movq 0x40(%r12), %rax
cmpb $0x1, 0x50(%rax)
jne 0x17ab4
movl 0x74(%rax), %ebx
testl %ebx, %ebx
jle 0x17ab4
leaq 0x50(%rsp), %rdi
callq 0xe52a
imull %ebx, %eax
movw %ax, -0x10(%r15)
incl %ebp
movb $0x1, %cl
testb %cl, %cl
je 0x17b7a
leaq 0x48(%rsp), %rdi
callq 0xe1b8
movb 0x78(%rsp), %dl
cmpb $0x24, %dl
setge %al
cmpq %r13, %r15
sete %cl
cmpb $0x23, %dl
jg 0x17af2
leaq 0x20(%r15), %rdx
cmpq %r13, %r15
movq %rdx, %r15
movq %r14, %rbx
jne 0x179b2
movq 0x40(%r12), %rdx
cmpb $0x1, 0x6c(%rdx)
jne 0x17b10
movq 0x10(%rsp), %rdi
movl %ebp, %esi
callq 0x16d02
movq 0x18(%rsp), %rdx
jmp 0x17b1d
testb %cl, %al
movq 0x18(%rsp), %rdx
je 0x17bcd
addq $0x18, %rdx
movq 0x40(%r12), %rax
movq 0x10(%rsp), %rcx
cmpq $0x2, %rcx
jb 0x17b37
movzwl 0x6(%rcx), %ecx
jmp 0x17b39
xorl %ecx, %ecx
lock
addq %rcx, 0xc8(%rax)
movq (%rdx), %rax
movq 0x10(%rsp), %rcx
movq %rcx, (%rdx)
movq %rax, 0x10(%rsp)
cmpq $0x2, %rcx
jb 0x17b5b
movq %rdx, 0x8(%rcx)
cmpq $0x2, %rax
jb 0x17b6a
leaq 0x10(%rsp), %rcx
movq %rcx, 0x8(%rax)
xorl %ecx, %ecx
movl $0x1, %eax
lock
cmpxchgq %rcx, 0x10(%rsp)
jne 0x17bae
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x17b8c
callq 0x5490
cmpq $0x0, 0x10(%rsp)
jne 0x17c37
movb 0xf(%rsp), %al
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16ec5(%rip), %rdi     # 0x2ea7a
leaq 0x16de5(%rip), %rsi     # 0x2e9a1
leaq 0x16e63(%rip), %rcx     # 0x2ea26
movl $0x9c, %edx
callq 0x5200
leaq 0x16e36(%rip), %rdi     # 0x2ea0a
leaq 0x16dc6(%rip), %rsi     # 0x2e9a1
leaq 0x16e44(%rip), %rcx     # 0x2ea26
movl $0x94, %edx
callq 0x5200
jmp 0x17bee
movq %rax, %rbx
jmp 0x17c27
jmp 0x17bf7
jmp 0x17bf7
movq %rax, %rbx
jmp 0x17c09
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x13f14
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x17c1b
callq 0x5490
movq $0x0, 0x90(%rsp)
cmpq $0x0, 0x10(%rsp)
jne 0x17c37
movq %rbx, %rdi
callq 0x56c0
leaq 0x15d8a(%rip), %rdi     # 0x2d9c8
leaq 0x15d90(%rip), %rsi     # 0x2d9d5
leaq 0x15da6(%rip), %rcx     # 0x2d9f2
movl $0x7a, %edx
callq 0x5200