// File: ATOMIC-LICHESS[P]ATOMKRAFT/create_book.cpp
// Function: findChildren(MoveTreeNode*, Position&, int*)
void findChildren(MoveTreeNode* node, Position& pos, int* index) {
	searchMoves[0] = MOVE_NONE;

	SearchLimits limits;
	limits.maxTime = MAX_SEARCH_TIME;
    limits.increment = 0;

    Move bestmove, pondermove;

	think(pos, limits, searchMoves, bestmove, pondermove);
	insertion_sort<MoveStack, base::iterator>(book_moves.begin(), book_moves.end());

	for (base::iterator it = book_moves.begin(); it != book_moves.end(); ++it) {

		node->child[node->child_count] = new MoveTreeNode();
		node->child[node->child_count]->parent = node;
		node->child[node->child_count]->child_count = 0;
		node->child[node->child_count]->ms.move = it->move;
		node->child[node->child_count]->ms.score = it->score;
		node->child[node->child_count]->index = *index;

		cout << "  " << move_to_string(node->child[node->child_count]->ms.move) << " "
			 << node->child[node->child_count]->ms.score << endl;

		++(*index);
		++node->child_count;
		if (node->child_count >= MAX_BOOK_BRANCHING) {
			break;
		}
	}
}

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq %rdx, 0xd0(%rsp)
movl $0x0, 0x144027(%rip)    # 0x153bb0
leaq 0xb4(%rsp), %rdi
callq 0x11c00
movl $0xbb8, 0xc0(%rsp) # imm = 0xBB8
movl $0x0, 0xb8(%rsp)
movq 0xd8(%rsp), %rdi
leaq 0xb4(%rsp), %rsi
leaq 0x143fed(%rip), %rdx    # 0x153bb0
leaq 0xb0(%rsp), %rcx
leaq 0xac(%rsp), %r8
callq 0x40bb0
leaq 0x143fb1(%rip), %rdi    # 0x153b90
callq 0x11da0
movq %rax, 0xa0(%rsp)
leaq 0x143f9d(%rip), %rdi    # 0x153b90
callq 0x11dd0
movq %rax, 0x98(%rsp)
movq 0xa0(%rsp), %rdi
movq 0x98(%rsp), %rsi
callq 0x11c20
leaq 0x143f74(%rip), %rdi    # 0x153b90
callq 0x11da0
movq %rax, 0x90(%rsp)
leaq 0x143f60(%rip), %rdi    # 0x153b90
callq 0x11dd0
movq %rax, 0x88(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x88(%rsp), %rsi
callq 0x11e00
testb $0x1, %al
jne 0xfc5b
jmp 0xfe90
movl $0xc0, %edi
callq 0x64d0
movq %rax, %rdx
movq %rdx, 0x18(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movaps %xmm0, 0xb0(%rdx)
movaps %xmm0, 0xa0(%rdx)
movaps %xmm0, 0x90(%rdx)
movaps %xmm0, 0x80(%rdx)
movaps %xmm0, 0x70(%rdx)
movaps %xmm0, 0x60(%rdx)
movaps %xmm0, 0x50(%rdx)
movaps %xmm0, 0x40(%rdx)
movaps %xmm0, 0x30(%rdx)
movaps %xmm0, 0x20(%rdx)
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, (%rdx)
movq 0xe0(%rsp), %rax
movslq 0xa8(%rax), %rcx
movq %rdx, 0x8(%rax,%rcx,8)
movq 0xe0(%rsp), %rcx
movslq 0xa8(%rcx), %rax
movq 0x8(%rcx,%rax,8), %rax
movq %rcx, (%rax)
movq 0xe0(%rsp), %rax
movslq 0xa8(%rax), %rcx
movq 0x8(%rax,%rcx,8), %rax
movl $0x0, 0xa8(%rax)
leaq 0x90(%rsp), %rdi
movq %rdi, 0x38(%rsp)
callq 0x11e40
movq 0x38(%rsp), %rdi
movl (%rax), %ecx
movq 0xe0(%rsp), %rax
movslq 0xa8(%rax), %rdx
movq 0x8(%rax,%rdx,8), %rax
movl %ecx, 0xac(%rax)
callq 0x11e40
movl 0x4(%rax), %ecx
movq 0xe0(%rsp), %rax
movslq 0xa8(%rax), %rdx
movq 0x8(%rax,%rdx,8), %rax
movl %ecx, 0xb0(%rax)
movq 0xd0(%rsp), %rax
movl (%rax), %ecx
movq 0xe0(%rsp), %rax
movslq 0xa8(%rax), %rdx
movq 0x8(%rax,%rdx,8), %rax
movl %ecx, 0xb4(%rax)
movq 0x5c23f(%rip), %rdi     # 0x6bfb8
leaq 0x497df(%rip), %rsi     # 0x5955f
callq 0x64b0
movq %rax, 0x40(%rsp)
movq 0xe0(%rsp), %rax
movslq 0xa8(%rax), %rcx
movq 0x8(%rax,%rcx,8), %rax
movl 0xac(%rax), %esi
leaq 0x68(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0x2c450
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x6420
movq %rax, 0x50(%rsp)
jmp 0xfdc9
movq 0x50(%rsp), %rdi
leaq 0x4978b(%rip), %rsi     # 0x59560
callq 0x64b0
movq %rax, 0x10(%rsp)
jmp 0xfde1
movq 0x10(%rsp), %rdi
movq 0xe0(%rsp), %rax
movslq 0xa8(%rax), %rcx
movq 0x8(%rax,%rcx,8), %rax
movl 0xb0(%rax), %esi
callq 0x6940
movq %rax, 0x8(%rsp)
jmp 0xfe0c
movq 0x8(%rsp), %rdi
movq 0x5c178(%rip), %rsi     # 0x6bf90
callq 0x6520
jmp 0xfe1f
leaq 0x68(%rsp), %rdi
callq 0x6a78
movq 0xd0(%rsp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
movq 0xe0(%rsp), %rax
movl 0xa8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0xa8(%rax)
movq 0xe0(%rsp), %rax
cmpl $0x14, 0xa8(%rax)
jl 0xfe7c
jmp 0xfe90
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x60(%rsp)
movl %eax, 0x5c(%rsp)
leaq 0x68(%rsp), %rdi
callq 0x6a78
jmp 0xfe98
jmp 0xfe7e
leaq 0x90(%rsp), %rdi
callq 0x11e50
jmp 0xfc29
addq $0xe8, %rsp
retq
movq 0x60(%rsp), %rdi
callq 0x6970
nopw %cs:(%rax,%rax)