// File: /workspace/github_c_makefile_star2_O2/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
movl %r9d, 0x4(%rsp)
movl %ecx, %r14d
movq %rdx, 0x10(%rsp)
movq %rsi, 0x8(%rsp)
movq %rdi, %r12
movq 0x90(%rsp), %rbp
movl %ecx, %ebx
incq %rbx
leaq 0x18(%rsp), %r15
decq %rbx
je 0x4d1f
leaq 0x18(%r8), %r13
movq %r12, %rdi
movq %r8, %rsi
movq %r15, %rdx
callq 0x49b5
movq %r13, %r8
testl %eax, %eax
je 0x4cfc
jmp 0x4ed3
movl 0x4(%rsp), %ebx
incq %rbx
leaq 0x18(%rsp), %r15
decq %rbx
je 0x4d4e
leaq 0x18(%rbp), %r13
movq %r12, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x49b5
movq %r13, %rbp
testl %eax, %eax
je 0x4d2b
jmp 0x4ed3
movl %r14d, 0x18(%r12)
movl 0x4(%rsp), %r13d
movl %r13d, 0x1c(%r12)
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
movaps %xmm0, 0x20(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x8(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movq %r12, 0x50(%rsp)
cmpl $0x0, 0xc(%rax)
je 0x4ddc
leaq 0x28(%rsp), %r15
movw $0x101, 0x10(%r15)      # imm = 0x101
xorl %ebx, %ebx
pushq $-0x1
popq %rbp
leaq 0x20(%rsp), %r13
cmpl %ebx, %r14d
je 0x4e5d
movzbl %bl, %eax
cmpl $0x1, %eax
adcl $0x0, %ebp
movq 0x10(%r12), %rcx
movslq %ebp, %rdx
movq (%rcx,%rdx,8), %rcx
imulq $0x18, %rax, %rax
movups (%rcx,%rax), %xmm0
movups %xmm0, (%r15)
movq %r13, %rdi
callq 0x4250
incl %ebx
testl %eax, %eax
je 0x4d9f
jmp 0x4ed3
addl %r14d, %r13d
leaq 0x28(%rsp), %rax
andw $0x0, 0x10(%rax)
leal -0x1(%r14), %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movl %eax, %ebp
cmpl %r13d, %r14d
jae 0x4ed1
movzbl %r14b, %eax
cmpl $0x1, %eax
adcl $0x0, %ebp
movq 0x10(%r12), %rcx
movslq %ebp, %rbx
movq (%rcx,%rbx,8), %rcx
imulq $0x18, %rax, %r15
movups (%rcx,%r15), %xmm0
leaq 0x28(%rsp), %rax
movups %xmm0, (%rax)
leaq 0x20(%rsp), %rdi
callq 0x4250
testl %eax, %eax
jne 0x4ed3
movq 0x10(%rsp), %rax
testb $0x4, 0x1(%rax)
jne 0x4e58
movq 0x10(%r12), %rax
addq (%rax,%rbx,8), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x4eec
incl %r14d
jmp 0x4df7
movl 0x4(%rsp), %ebx
movl %ebx, %eax
addl %r14d, %ebx
addl %r14d, %eax
decl %eax
movl $0x100, %ecx            # imm = 0x100
cltd
idivl %ecx
movl %eax, %ebp
pushq $0x1
popq %rcx
movl %ebx, 0x4(%rsp)
movq 0x10(%rsp), %rax
cmpl 0xc(%rax), %ecx
jge 0x4ee2
movl %ecx, 0x8(%rsp)
movl (%r12), %r13d
cmpl %r13d, %ebx
jae 0x4ec6
movzbl %bl, %eax
cmpl $0x1, %eax
adcl $0x0, %ebp
movq 0x10(%r12), %rcx
movslq %ebp, %rdx
movq (%rcx,%rdx,8), %rcx
imulq $0x18, %rax, %rax
movups (%rcx,%rax), %xmm0
movups %xmm0, (%r15)
leaq 0x20(%rsp), %rdi
callq 0x4250
incl %ebx
testl %eax, %eax
je 0x4e8e
jmp 0x4ed3
movl 0x8(%rsp), %ecx
incl %ecx
movl %r13d, %ebx
jmp 0x4e7c
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x4(%rsp), %r13d
jmp 0x4ddf