// File: /workspace/github_cpp_makefile_star2_O3/tewalds[P]pentagod/agentmctsthread.cpp
// Function: AgentMCTS::MCTSThread::create_children(Board const&, AgentMCTS::Node*, int)
bool AgentMCTS::MCTSThread::create_children(const Board & board, Node * node, int toplay){
	if(!node->children.lock())
		return false;

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

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

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

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

		if(player->knowledge)
			add_knowledge(after, node, child);
		nummoves++;
	}

	if(player->prunesymmetry)
		temp.shrink(nummoves); //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(player->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
movq %rdx, %r14
movl $0x1, %edx
xorl %eax, %eax
lock
cmpxchgq %rdx, 0x20(%r14)
movl %ecx, 0x14(%rsp)
sete %al
jne 0x2137e
movq $0x0, 0x8(%rsp)
movb %al, 0x7(%rsp)
movq %rsi, %rbx
movq %rdi, %r15
movb 0x1a(%rsi), %al
cmpb $-0x4, %al
jne 0x21181
movq %rbx, %rdi
callq 0xd9e4
movb %al, 0x1a(%rbx)
movzbl 0x18(%rbx), %ecx
movl $0x120, %edx            # imm = 0x120
xorl %esi, %esi
shll $0x3, %ecx
subl %ecx, %edx
testb %al, %al
cmovsl %edx, %esi
movl $0xf0, %edx
addq 0x40(%r15), %rdx
leaq 0x8(%rsp), %rdi
callq 0x216c6
movq 0x8(%rsp), %rcx
xorl %ebp, %ebp
movl $0x0, %r13d
leaq 0x10(%rcx), %rax
cmpq $0x2, %rcx
cmovaeq %rax, %r13
jb 0x211d0
movzwl 0x6(%rcx), %ecx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rbp
movq 0x40(%r15), %rax
movq %r14, 0x18(%rsp)
movzbl 0x6c(%rax), %edx
leaq 0x48(%rsp), %rdi
movq %rbx, %rsi
callq 0xd282
movb 0x78(%rsp), %dl
cmpb $0x24, %dl
setge %al
cmpq %rbp, %r13
sete %cl
xorl %r12d, %r12d
cmpb $0x23, %dl
jg 0x212da
cmpq %rbp, %r13
je 0x212da
leaq 0x20(%rsp), %rbx
xorl %r12d, %r12d
movl 0x78(%rsp), %eax
vxorps %xmm0, %xmm0, %xmm0
movl $0xfd0000, 0x30(%rsp)   # imm = 0xFD0000
vmovaps %xmm0, 0x20(%rsp)
movl %eax, 0x34(%rsp)
movw $0x8efc, 0x38(%rsp)     # imm = 0x8EFC
movq $0x0, 0x40(%rsp)
movq %r13, %rdi
movq %rbx, %rsi
callq 0x1ef48
movq %rbx, %rdi
callq 0x1ec34
movq 0x40(%r15), %rax
cmpl $0x0, 0x64(%rax)
je 0x21289
movb 0x6a(%rsp), %al
cmpb $-0x4, %al
jne 0x21274
leaq 0x50(%rsp), %rdi
callq 0xd9e4
movb %al, 0x6a(%rsp)
movb %al, 0x12(%r13)
movsbl %al, %ecx
cmpl 0x14(%rsp), %ecx
je 0x21390
movq 0x40(%r15), %rax
cmpb $0x1, 0x50(%rax)
jne 0x212ab
movl 0x74(%rax), %r14d
testl %r14d, %r14d
jle 0x212ab
leaq 0x50(%rsp), %rdi
callq 0x21788
imull %r14d, %eax
movw %ax, 0x10(%r13)
leaq 0x48(%rsp), %rdi
callq 0xd39c
movb 0x78(%rsp), %dl
incl %r12d
addq $0x28, %r13
cmpb $0x24, %dl
setge %al
cmpq %rbp, %r13
sete %cl
cmpb $0x23, %dl
jg 0x212da
cmpq %rbp, %r13
jne 0x21217
movq 0x40(%r15), %rdx
cmpb $0x1, 0x6c(%rdx)
jne 0x212f7
movq 0x8(%rsp), %rdi
movl %r12d, %esi
callq 0x21b04
movq 0x40(%r15), %rdx
jmp 0x212ff
testb %cl, %al
je 0x213f9
movq 0x18(%rsp), %rsi
movq 0x8(%rsp), %rax
addq $0x20, %rsi
cmpq $0x2, %rax
jb 0x21319
movzwl 0x6(%rax), %eax
jmp 0x2131b
xorl %eax, %eax
lock
addq %rax, 0xd0(%rdx)
movq (%rsi), %rax
movq 0x8(%rsp), %rcx
movq %rcx, (%rsi)
movq %rax, 0x8(%rsp)
cmpq $0x2, %rcx
jb 0x2133d
movq %rsi, 0x8(%rcx)
cmpq $0x2, %rax
jb 0x2134c
leaq 0x8(%rsp), %rcx
movq %rcx, 0x8(%rax)
movl $0x1, %eax
xorl %ecx, %ecx
lock
cmpxchgq %rcx, 0x8(%rsp)
jne 0x213da
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x2136e
callq 0x43d0
cmpq $0x0, 0x8(%rsp)
jne 0x21455
movb 0x7(%rsp), %al
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rsp), %rdx
xorl %ecx, %ecx
movb %al, 0x12(%rdx)
movb $0x1, 0x13(%rdx)
movzwl 0x78(%rsp), %eax
movw %ax, 0x18(%rdx)
movl $0x1, %eax
lock
cmpxchgq %rcx, 0x20(%rdx)
movq 0x8(%rsp), %rsi
testq %rsi, %rsi
je 0x2135c
movl $0xf0, %edi
addq 0x40(%r15), %rdi
xorl %ecx, %ecx
movq %rsi, %rax
lock
cmpxchgq %rcx, 0x8(%rsp)
jne 0x2135c
callq 0x1ffde
jmp 0x2135c
leaq 0xadbc(%rip), %rdi      # 0x2c19d
leaq 0xad01(%rip), %rsi      # 0x2c0e9
leaq 0xad66(%rip), %rcx      # 0x2c155
movl $0x95, %edx
callq 0x41b0
leaq 0xad39(%rip), %rdi      # 0x2c139
leaq 0xace2(%rip), %rsi      # 0x2c0e9
leaq 0xad47(%rip), %rcx      # 0x2c155
movl $0x8d, %edx
callq 0x41b0
jmp 0x21421
jmp 0x2141c
movq %rax, %rbx
jmp 0x21445
movq %rax, %rbx
jmp 0x21433
leaq 0x20(%rsp), %rdi
movq %rax, %rbx
callq 0x1ec34
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x21445
callq 0x43d0
cmpq $0x0, 0x8(%rsp)
jne 0x21455
movq %rbx, %rdi
callq 0x45b0
leaq 0x7d1f(%rip), %rdi      # 0x2917b
leaq 0x7c82(%rip), %rsi      # 0x290e5
leaq 0xa631(%rip), %rcx      # 0x2ba9b
movl $0x73, %edx
callq 0x41b0