// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %rbp
leaq 0x8(%rdi), %r12
movl 0x4(%rsi), %esi
shlq $0x4, %rsi
movq %r12, %rdi
callq 0x480d
testl %eax, %eax
jne 0x62e7
movq %r13, (%rsp)
leaq 0x18(%rbp), %r13
movslq 0x18(%rbx), %rsi
shlq $0x3, %rsi
movq %r13, %rdi
callq 0x480d
testl %eax, %eax
jne 0x62e7
movq %r15, 0x20(%rsp)
leaq 0x20(%rbp), %r15
movslq 0x1c(%rbx), %rsi
shlq $0x3, %rsi
movq %r15, %rdi
callq 0x480d
testl %eax, %eax
jne 0x62e7
movq %r15, 0x10(%rsp)
leaq 0x30(%rbp), %rdi
movl 0x24(%rbx), %esi
shlq $0x4, %rsi
movq %rdi, %r15
callq 0x480d
testl %eax, %eax
je 0x6317
movl %eax, %r14d
movq 0x8(%rbp), %rdi
callq 0x1030
movq 0x18(%rbp), %rdi
callq 0x1030
movq 0x20(%rbp), %rdi
callq 0x1030
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, 0x18(%rsp)
movl 0x4(%rbx), %edi
movl %edi, (%rbp)
movl 0x18(%rbx), %edx
movl %edx, 0x10(%rbp)
movl 0x1c(%rbx), %esi
movl %esi, 0x14(%rbp)
movl 0x24(%rbx), %eax
movl %eax, 0x28(%rbp)
movl (%rbx), %ecx
testq %rcx, %rcx
je 0x6512
movq %rdi, 0x8(%rsp)
addl %edx, %esi
movl %edx, %edi
negl %edi
xorl %r8d, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
xorl %r10d, %r10d
movq 0x10(%rsp), %rbp
cmpb $0x1, %r8b
adcl $0x0, %r9d
movq 0x10(%rbx), %rax
movslq %r9d, %r14
movzbl %r8b, %r11d
leaq (%r11,%r11,2), %r11
shll $0x3, %r11d
addq (%rax,%r14,8), %r11
cmpq %rdx, %r8
jae 0x639b
cmpb $0x0, 0x10(%r11)
je 0x63d3
movl %r10d, %eax
shlq $0x4, %rax
addq (%r12), %rax
movq (%r13), %r14
movq %rax, (%r14,%r8,8)
jmp 0x63ca
movb 0x10(%r11), %al
cmpq %rsi, %r8
jae 0x63c6
testb %al, %al
je 0x63e1
movl %r10d, %eax
shlq $0x4, %rax
addq (%r12), %rax
movq (%rbp), %r14
leal (%rdi,%r8), %ebp
movq %rax, (%r14,%rbp,8)
movq 0x10(%rsp), %rbp
jmp 0x63ca
testb %al, %al
je 0x63f1
movl %r10d, 0x14(%r11)
incl %r10d
jmp 0x63f1
movq (%r13), %rax
movq $0x0, (%rax,%r8,8)
jmp 0x63f1
movq (%rbp), %rax
leal (%rdi,%r8), %r11d
movq $0x0, (%rax,%r11,8)
incq %r8
cmpq %r8, %rcx
jne 0x635b
movq (%r12), %rdx
testq %rcx, %rcx
movq 0x18(%rsp), %rsi
je 0x650b
movq 0x20(%rsp), %rax
movsd (%rax), %xmm0
movq (%rsp), %rax
movsd 0x30(%rax), %xmm1
movsd 0xd07(%rip), %xmm2      # 0x7130
subsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movq (%rsi), %rsi
movq 0x10(%rbx), %rax
movq %rax, (%rsp)
xorpd 0xfec(%rip), %xmm1      # 0x7430
mulsd %xmm0, %xmm1
xorl %r8d, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
movq %rdx, %r10
movzbl %r8b, %edi
cmpl $0x1, %edi
adcl $0x0, %r9d
movslq %r9d, %rax
movq (%rsp), %r11
movq (%r11,%rax,8), %rax
leaq (%rdi,%rdi,2), %rdi
cmpb $0x0, 0x10(%rax,%rdi,8)
je 0x64ff
movl $0x0, 0x8(%r10)
movl 0x20(%rbx), %r11d
testl %r11d, %r11d
je 0x64fb
leaq (%rax,%rdi,8), %r14
movq 0x30(%rbx), %r15
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
xorl %r12d, %r12d
xorl %r13d, %r13d
movl %r13d, %edi
andl $0x3ff, %edi            # imm = 0x3FF
cmpl $0x1, %edi
adcl $0x0, %ebp
movslq %ebp, %rax
movq (%r15,%rax,8), %rax
shll $0x5, %edi
cmpb $0x0, 0x18(%rax,%rdi)
je 0x64f3
addq %rdi, %rax
cmpq %r14, 0x8(%rax)
jne 0x64f3
movsd 0x10(%rax), %xmm2
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
movsd %xmm2, (%rsi)
movq (%rax), %rax
movl 0x14(%rax), %eax
shlq $0x4, %rax
addq %rdx, %rax
movq %rax, 0x8(%rsi)
incl %r12d
movl %r12d, 0x8(%r10)
addq $0x10, %rsi
incl %r13d
cmpl %r13d, %r11d
jne 0x649d
addq $0x10, %r10
incl %r8d
cmpl %ecx, %r8d
jne 0x6454
movq 0x8(%rsp), %rdi
jmp 0x6516
movq (%r12), %rdx
testq %rdi, %rdi
je 0x65c4
movq %rdi, %rcx
shlq $0x4, %rcx
decq %rdi
movq %rdi, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
addq $0x10, %rcx
andq $-0x20, %rcx
movdqa 0xd1d(%rip), %xmm1      # 0x7260
xorl %eax, %eax
movdqa 0xd23(%rip), %xmm2      # 0x7270
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0xef3(%rip), %xmm4      # 0x7450
xorl %r14d, %r14d
movdqa %xmm1, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm0, %xmm6
pcmpeqd %xmm0, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
movd %xmm5, %esi
notl %esi
testb $0x1, %sil
je 0x659a
movq $0x0, (%rdx,%rax)
pxor %xmm3, %xmm5
pextrw $0x4, %xmm5, %esi
testb $0x1, %sil
je 0x65b2
movq $0x0, 0x10(%rdx,%rax)
paddq %xmm4, %xmm1
addq $0x20, %rax
cmpq %rax, %rcx
jne 0x6560
jmp 0x6305
xorl %r14d, %r14d
jmp 0x6305