// File: /workspace/github_c_makefile_star2_O3/kernfel[P]fNEAT/network.c
// Function: build_pNetwork
int build_pNetwork( pNetwork *net, CPPN *cppn, struct NEAT_Params *params, int num_inputs, const pNode *inputs, int num_outputs, const pNode *outputs ) {
	int block, index, err=0;
	unsigned int i;

	// Set up static input and output nodes
	pNode *tmp;
	for ( i=0; i<num_inputs; i++ ) {
		if (( err = add_pNode( net, inputs[i].x, &tmp ) ))
			return err;
	}
	for ( i=0; i<num_outputs; i++ ) {
		if (( err = add_pNode( net, outputs[i].x, &tmp ) ))
			return err;
	}
	net->num_inputs = num_inputs;
	net->num_outputs = num_outputs;

	struct Extraction_Params eparams = {0};
	eparams.params = params;
	eparams.cppn = cppn;
	eparams.net = net;

	if ( params->max_network_depth ) {
		// Extract links from input to first hidden layer
		eparams.outgoing = 1;
		eparams.create_nodes = 1;
		block = -1;
		for ( i=0; i<num_inputs; i++ ) {
			index = i % BLOCKSIZE_NODES;
			if ( ! index )
				block++;
			memcpy( eparams.ref, net->p_nodes[block][index].x, DIMENSIONS*sizeof *eparams.ref );
			if (( err = extract_links( &eparams ) ))
				return err;
		}

		// Extract deeper layers
		int depth;
		unsigned int i_start=num_inputs+num_outputs, i_end;
		block = (num_inputs+num_outputs-1) / BLOCKSIZE_NODES;
		for ( depth=1; depth < params->max_network_depth; depth++ ) {
			i_end = net->num_nodes;
			for ( i=i_start; i<i_end; i++ ) {
				index = i % BLOCKSIZE_NODES;
				if ( ! index )
					block++;
				memcpy( eparams.ref, net->p_nodes[block][index].x, DIMENSIONS*sizeof *eparams.ref );
				if (( err = extract_links( &eparams ) ))
					return err;
			}
			i_start = i_end;
		}
	}

	// Extract links to the output layer
	eparams.outgoing = 0;
	eparams.create_nodes = 0;
	block = (num_inputs-1) / BLOCKSIZE_NODES;
	for ( i=num_inputs; i<num_inputs+num_outputs; i++ ) {
		index = i % BLOCKSIZE_NODES;
		if ( ! index )
			block++;
		memcpy( eparams.ref, net->p_nodes[block][index].x, DIMENSIONS*sizeof *eparams.ref );
		if (( err = extract_links( &eparams ) ))
			return err;

		// Mark everything that connects to this output node
		if ( ! (params->flags & EFL_NO_BACKTRACKING) ) {
			backtrack( net, &net->p_nodes[block][index] );
		}
	}

	return err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, (%rsp)
movl %ecx, %r14d
movq %rdx, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
movq %rdi, %r12
testl %ecx, %ecx
je 0x5386
movq %r8, %r15
movl %r14d, %ebx
leaq 0x18(%rsp), %r13
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x5001
testl %eax, %eax
jne 0x5584
addq $0x18, %r15
decq %rbx
jne 0x5367
cmpl $0x0, (%rsp)
je 0x53bb
movq 0x90(%rsp), %r15
movl (%rsp), %ebx
leaq 0x18(%rsp), %r13
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x5001
testl %eax, %eax
jne 0x5584
addq $0x18, %r15
decq %rbx
jne 0x539c
movl %r14d, 0x18(%r12)
movq (%rsp), %rax
movl %eax, 0x1c(%r12)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x10(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movq %r12, 0x50(%rsp)
movl 0xc(%rax), %eax
testl %eax, %eax
je 0x54ec
movw $0x101, 0x38(%rsp)      # imm = 0x101
testl %r14d, %r14d
je 0x5458
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
xorl %r15d, %r15d
leaq 0x28(%rsp), %rbx
movzbl %r15b, %eax
cmpl $0x1, %eax
adcl $0x0, %r13d
movq 0x10(%r12), %rcx
movslq %r13d, %rdx
movq (%rcx,%rdx,8), %rcx
leaq (%rax,%rax,2), %rax
movups (%rcx,%rax,8), %xmm0
movups %xmm0, (%rbx)
leaq 0x20(%rsp), %rdi
callq 0x482c
testl %eax, %eax
jne 0x5584
incl %r15d
cmpl %r15d, %r14d
jne 0x5414
movq 0x8(%rsp), %rax
movl 0xc(%rax), %eax
cmpl $0x2, %eax
jl 0x54ec
movq (%rsp), %rdx
leal (%rdx,%r14), %ebx
leal (%rdx,%r14), %ecx
decl %ecx
leal (%rdx,%r14), %r13d
addl $0xfe, %r13d
testl %ecx, %ecx
cmovnsl %ecx, %r13d
sarl $0x8, %r13d
movl $0x1, %ecx
movl %ecx, 0x10(%rsp)
movl %ebx, %r15d
movl (%r12), %ebx
cmpl %ebx, %r15d
jae 0x54e2
movzbl %r15b, %eax
cmpl $0x1, %eax
adcl $0x0, %r13d
movq 0x10(%r12), %rcx
movslq %r13d, %rdx
movq (%rcx,%rdx,8), %rcx
leaq (%rax,%rax,2), %rax
movups (%rcx,%rax,8), %xmm0
leaq 0x28(%rsp), %rax
movups %xmm0, (%rax)
leaq 0x20(%rsp), %rdi
callq 0x482c
testl %eax, %eax
jne 0x5584
incl %r15d
cmpl %r15d, %ebx
jne 0x5499
movq 0x8(%rsp), %rax
movl 0xc(%rax), %eax
movl 0x10(%rsp), %ecx
incl %ecx
cmpl %eax, %ecx
jl 0x5489
movw $0x0, 0x38(%rsp)
movq (%rsp), %rax
addl %r14d, %eax
xorl %ebp, %ebp
cmpl %r14d, %eax
jbe 0x5586
leal -0x1(%r14), %eax
leal 0xfe(%r14), %r13d
testl %eax, %eax
cmovnsl %eax, %r13d
sarl $0x8, %r13d
movzbl %r14b, %eax
cmpl $0x1, %eax
adcl $0x0, %r13d
movq 0x10(%r12), %rcx
movslq %r13d, %rbx
movq (%rcx,%rbx,8), %rcx
leaq (%rax,%rax,2), %r15
movups (%rcx,%r15,8), %xmm0
leaq 0x28(%rsp), %rax
movups %xmm0, (%rax)
leaq 0x20(%rsp), %rdi
callq 0x482c
testl %eax, %eax
jne 0x5584
movq 0x8(%rsp), %rax
testb $0x4, 0x1(%rax)
jne 0x5573
movq 0x10(%r12), %rax
shll $0x3, %r15d
addq (%rax,%rbx,8), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x5597
incl %r14d
movq (%rsp), %rax
decl %eax
movq %rax, (%rsp)
jne 0x551a
jmp 0x5586
movl %eax, %ebp
movl %ebp, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq