// File: /workspace/github_c_makefile_star2_O1/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 $0x68, %rsp
movq %r9, 0x8(%rsp)
movl %ecx, %r14d
movq %rdx, 0x10(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %r12
testl %ecx, %ecx
je 0x51bb
movq %r8, %r15
movl %r14d, %ebx
leaq 0x60(%rsp), %r13
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x4e0d
testl %eax, %eax
jne 0x53df
addq $0x18, %r15
decq %rbx
jne 0x519c
cmpl $0x0, 0x8(%rsp)
je 0x51f2
movq 0xa0(%rsp), %r15
movl 0x8(%rsp), %ebx
leaq 0x60(%rsp), %r13
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
callq 0x4e0d
testl %eax, %eax
jne 0x53df
addq $0x18, %r15
decq %rbx
jne 0x51d3
movl %r14d, 0x18(%r12)
movq 0x8(%rsp), %rax
movl %eax, 0x1c(%r12)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x18(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movq %r12, 0x50(%rsp)
cmpl $0x0, 0xc(%rax)
je 0x5331
movw $0x101, 0x38(%rsp)      # imm = 0x101
testl %r14d, %r14d
je 0x528c
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 0x4644
testl %eax, %eax
jne 0x53df
incl %r15d
cmpl %r15d, %r14d
jne 0x5250
xorl %ebp, %ebp
movq 0x10(%rsp), %rax
cmpl $0x2, 0xc(%rax)
setge %dl
jl 0x533b
movq 0x8(%rsp), %rcx
leal (%rcx,%r14), %ebx
leal (%rcx,%r14), %eax
decl %eax
leal (%rcx,%r14), %r13d
addl $0xfe, %r13d
testl %eax, %eax
cmovnsl %eax, %r13d
sarl $0x8, %r13d
movl $0x1, %ecx
movl %ecx, 0x18(%rsp)
movb %dl, 0x7(%rsp)
movl %ebx, %r15d
movl (%r12), %eax
movl %eax, %ebx
cmpl %eax, %r15d
jae 0x531c
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 0x4644
testl %eax, %eax
jne 0x5335
incl %r15d
cmpl %r15d, %ebx
jne 0x52df
movl 0x18(%rsp), %ecx
incl %ecx
movq 0x10(%rsp), %rax
cmpl 0xc(%rax), %ecx
setl %dl
jl 0x52c9
jmp 0x533b
xorl %ebp, %ebp
jmp 0x5344
movl %eax, %ebp
movb 0x7(%rsp), %dl
testb $0x1, %dl
jne 0x53e1
movw $0x0, 0x38(%rsp)
movq 0x8(%rsp), %rax
addl %r14d, %eax
cmpl %r14d, %eax
jbe 0x53e1
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 0x4644
testl %eax, %eax
jne 0x53df
movq 0x10(%rsp), %rax
testb $0x4, 0x1(%rax)
jne 0x53ca
movq 0x10(%r12), %rax
shll $0x3, %r15d
addq (%rax,%rbx,8), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x53f2
incl %r14d
movq 0x8(%rsp), %rax
decl %eax
movq %rax, 0x8(%rsp)
jne 0x5371
xorl %ebp, %ebp
jmp 0x53e1
movl %eax, %ebp
movl %ebp, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq