// File: /workspace/github_c_makefile_star2_O0/kernfel[P]fNEAT/network-static.c
// Function: build_eNetwork
int build_eNetwork( eNetwork *e, pNetwork *p, struct NEAT_Params *params, struct Implementation_Params *iparams ) {
	int err=0;

	if (( err = Realloc( e->nodes, p->num_used_nodes*sizeof *e->nodes ) )
	 || ( err = Realloc( e->inputs, p->num_inputs*sizeof *e->inputs ) )
	 || ( err = Realloc( e->outputs, p->num_outputs*sizeof *e->outputs ) )
	 || ( err = Realloc( e->links, p->num_used_links*sizeof *e->links ) )) {
		free( e->nodes );
		free( e->inputs );
		free( e->outputs );
		return err;
	}
	e->num_nodes = p->num_used_nodes;
	e->num_inputs = p->num_inputs;
	e->num_outputs = p->num_outputs;
	e->num_links = p->num_used_links;

	// Assign eNode indices to the pNodes
	int block=-1, index;
	unsigned int i, j, node_iter=0;
	pNode *n;
	for ( i=0; i<p->num_nodes; i++ ) {
		index = i % BLOCKSIZE_NODES;
		if ( ! index )
			block++;
		n = &p->p_nodes[block][index];

		if ( i < e->num_inputs ) {
			if ( n->used )
				e->inputs[i] = e->nodes + node_iter;
			else
				e->inputs[i] = 0;
		} else if ( i < e->num_inputs+e->num_outputs ) {
			if ( n->used )
				e->outputs[i-e->num_inputs] = e->nodes + node_iter;
			else
				e->outputs[i-e->num_inputs] = 0;
		}

		if ( n->used )
			n->index = node_iter++;
	}
	
	// Group links by target node
	pLink *l;
	eLink *next_link=e->links;
	eNode *next_node=e->nodes;
	double stretch = iparams->weight_range/(1-params->expression_thresholds[0]), offset = params->expression_thresholds[0] * stretch;
	int l_block, l_index;
	block = -1;
	for ( i=0; i<p->num_nodes; i++ ) {
		index = i % BLOCKSIZE_NODES;
		if ( ! index )
			block++;
		n = &p->p_nodes[block][index];
		if ( n->used ) {
			next_node->num_inputs = 0;
			l_block = -1;
			for ( j=0; j<p->num_links; j++ ) {
				l_index = j % BLOCKSIZE_LINKS;
				if ( ! l_index )
					l_block++;
				l = &p->p_links[l_block][l_index];
				if ( l->used && l->to == n) {
					next_link->w = l->r[0]*stretch - offset;
					next_link->from = e->nodes + l->from->index;
					next_node->num_inputs++;
					next_link++;
				}
			}
			next_node++;
		}
	}

	flush(e);

	return err;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x10(%rbp), %rdi
addq $0x8, %rdi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, %esi
shlq $0x4, %rsi
callq 0x63c0
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
jne 0x93d8
movq -0x10(%rbp), %rdi
addq $0x18, %rdi
movq -0x18(%rbp), %rax
movslq 0x18(%rax), %rsi
shlq $0x3, %rsi
callq 0x63c0
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
jne 0x93d8
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
movq -0x18(%rbp), %rax
movslq 0x1c(%rax), %rsi
shlq $0x3, %rsi
callq 0x63c0
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
jne 0x93d8
movq -0x10(%rbp), %rdi
addq $0x30, %rdi
movq -0x18(%rbp), %rax
movl 0x24(%rax), %eax
movl %eax, %esi
shlq $0x4, %rsi
callq 0x63c0
movl %eax, -0x2c(%rbp)
cmpl $0x0, %eax
je 0x940a
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x1030
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x1030
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x1030
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x9764
movq -0x18(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x14(%rax)
movq -0x18(%rbp), %rax
movl 0x24(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x40(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x9583
movl -0x38(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x947f
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x34(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movl -0x38(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jae 0x94ec
movq -0x48(%rbp), %rax
cmpb $0x0, 0x10(%rax)
je 0x94d7
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movl -0x40(%rbp), %eax
shlq $0x4, %rax
addq %rax, %rdx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x38(%rbp), %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0x94ea
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movl -0x38(%rbp), %ecx
movq $0x0, (%rax,%rcx,8)
jmp 0x9557
movl -0x38(%rbp), %eax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
movq -0x10(%rbp), %rdx
addl 0x14(%rdx), %ecx
cmpl %ecx, %eax
jae 0x9555
movq -0x48(%rbp), %rax
cmpb $0x0, 0x10(%rax)
je 0x9537
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdx
movl -0x40(%rbp), %eax
shlq $0x4, %rax
addq %rax, %rdx
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x38(%rbp), %ecx
movq -0x10(%rbp), %rsi
subl 0x10(%rsi), %ecx
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0x9553
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x38(%rbp), %ecx
movq -0x10(%rbp), %rdx
subl 0x10(%rdx), %ecx
movl %ecx, %ecx
movq $0x0, (%rax,%rcx,8)
jmp 0x9555
jmp 0x9557
movq -0x48(%rbp), %rax
cmpb $0x0, 0x10(%rax)
je 0x9573
movl -0x40(%rbp), %ecx
movl %ecx, %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movq -0x48(%rbp), %rax
movl %ecx, 0x14(%rax)
jmp 0x9575
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x9456
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rax
movsd (%rax), %xmm0
movq -0x20(%rbp), %rax
movsd 0xab9(%rip), %xmm1      # 0xa068
subsd 0x30(%rax), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x20(%rbp), %rax
movsd 0x30(%rax), %xmm0
mulsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movl $0xffffffff, -0x30(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl (%rcx), %eax
jae 0x9755
movl -0x38(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jne 0x9607
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x30(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x34(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
cmpb $0x0, 0x10(%rax)
je 0x9745
movq -0x60(%rbp), %rax
movl $0x0, 0x8(%rax)
movl $0xffffffff, -0x74(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x20(%rcx), %eax
jae 0x9739
movl -0x3c(%rbp), %eax
andl $0x3ff, %eax            # imm = 0x3FF
movl %eax, -0x78(%rbp)
cmpl $0x0, -0x78(%rbp)
jne 0x9677
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x74(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x78(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movzbl 0x18(%rax), %eax
cmpl $0x0, %eax
je 0x9729
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x48(%rbp), %rax
jne 0x9729
movq -0x50(%rbp), %rax
movsd 0x10(%rax), %xmm0
movsd -0x68(%rbp), %xmm2
movsd -0x70(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x58(%rbp), %rax
movsd %xmm0, (%rax)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x50(%rbp), %rax
movq (%rax), %rax
movl 0x14(%rax), %eax
shlq $0x4, %rax
addq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x60(%rbp), %rax
movl 0x8(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x8(%rax)
movq -0x58(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x58(%rbp)
jmp 0x972b
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x964d
movq -0x60(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x60(%rbp)
jmp 0x9747
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x95de
movq -0x10(%rbp), %rdi
callq 0x9770
movl -0x2c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq