// File: /workspace/github_c_makefile_star2_O0/kernfel[P]fNEAT/network.c
// Function: connect_pNet
int connect_pNet( BinLeaf *leaf, struct Extraction_Params *eparams ) {
	int err=0;

	// Determine source and target coordinates
	double source[DIMENSIONS], target[DIMENSIONS];
	if ( eparams->outgoing ) {
		memcpy( source, eparams->ref, DIMENSIONS*sizeof *source );
		memcpy( target, leaf->x, DIMENSIONS*sizeof *target );
	} else {
		memcpy( source, leaf->x, DIMENSIONS*sizeof *source );
		memcpy( target, eparams->ref, DIMENSIONS*sizeof *target );
	}

	// Find the source and target nodes
	unsigned int i;
	int block=-1, index;
	pNode *source_pnode=0, *target_pnode=0, *n;
	for ( i=0; i<eparams->net->num_nodes; i++ ) {
		index = i % BLOCKSIZE_NODES;
		if ( ! index )
			block++;
		n = &eparams->net->p_nodes[block][index];
		if ( ! memcmp( source, n->x, DIMENSIONS*sizeof *source ) ) {
			source_pnode = n;
			if ( target_pnode )
				break;
		}
		if ( ! memcmp( target, n->x, DIMENSIONS*sizeof *source ) ) {
			target_pnode = n;
			if ( source_pnode )
				break;
		}
	}

	// Create what does not exist
	if ( ! source_pnode ) {
		if ( ! eparams->create_nodes )
			return 0;
		if (( err = add_pNode( eparams->net, source, &source_pnode ) ))
			return err;
	}
	if ( ! target_pnode ) {
		if ( ! eparams->create_nodes )
			return 0;
		if (( err = add_pNode( eparams->net, target, &target_pnode ) ))
			return err;
	}

	pLink *plink;
	if ( eparams->outgoing ) {
		// Unless the extraction algorithm is out of whack, no link comparison should be necessary, so skip it
		if (( err = add_pLink( eparams->net, source_pnode, target_pnode, &plink ) ))
			return err;
	} else {
		// Check whether the targeted node lies within the substrate space
		unsigned char out_of_bounds=0;
		for ( i=0; i<DIMENSIONS; i++ ) {
			if ( target[i] <= -0.5 || target[i] >= 0.5 ) {
				out_of_bounds = 1;
				break;
			}
		}
		if ( out_of_bounds ) {
			// There's no way extraction could have produced links here, skip the check
			if (( err = add_pLink( eparams->net, source_pnode, target_pnode, &plink ) ))
				return err;
		} else {
			// Target node lies within substrate space, there may already be links to it
			block=-1;
			pLink *l;
			for ( i=0; i<eparams->net->num_links; i++ ) {
				index = i % BLOCKSIZE_LINKS;
				if ( ! index )
					block++;
				l = &eparams->net->p_links[block][index];
				if ( l->from == source_pnode && l->to == target_pnode ) {
					return 0;
				}
			}

			// No such luck, add a new one
			if (( err = add_pLink( eparams->net, source_pnode, target_pnode, &plink ) ))
				return err;
		}
	}

	memcpy( plink->r, leaf->r, N_OUTPUTS*sizeof *plink->r );

	return err;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x1c(%rbp)
movq -0x18(%rbp), %rax
cmpb $0x0, 0x18(%rax)
je 0x750e
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq %rcx, -0x30(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x40(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x38(%rbp)
jmp 0x7536
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x30(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
movq %rcx, -0x40(%rbp)
movq 0x10(%rax), %rax
movq %rax, -0x38(%rbp)
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x30(%rcx), %rcx
cmpl (%rcx), %eax
jae 0x7626
movl -0x44(%rbp), %eax
andl $0xff, %eax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jne 0x7581
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x10(%rax), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
leaq -0x30(%rbp), %rax
movq -0x68(%rbp), %rcx
movups (%rcx), %xmm1
movups (%rax), %xmm0
pcmpeqb %xmm1, %xmm0
pmovmskb %xmm0, %eax
subl $0xffff, %eax           # imm = 0xFFFF
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x75dd
movq -0x68(%rbp), %rax
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x75db
jmp 0x7626
jmp 0x75dd
leaq -0x40(%rbp), %rax
movq -0x68(%rbp), %rcx
movups (%rcx), %xmm1
movups (%rax), %xmm0
pcmpeqb %xmm1, %xmm0
pmovmskb %xmm0, %eax
subl $0xffff, %eax           # imm = 0xFFFF
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x7616
movq -0x68(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x58(%rbp)
je 0x7614
jmp 0x7626
jmp 0x7616
jmp 0x7618
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x7554
cmpq $0x0, -0x58(%rbp)
jne 0x766d
movq -0x18(%rbp), %rax
cmpb $0x0, 0x19(%rax)
jne 0x7643
movl $0x0, -0x4(%rbp)
jmp 0x7843
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x7270
movl %eax, -0x1c(%rbp)
cmpl $0x0, %eax
je 0x766b
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x7843
jmp 0x766d
cmpq $0x0, -0x60(%rbp)
jne 0x76b4
movq -0x18(%rbp), %rax
cmpb $0x0, 0x19(%rax)
jne 0x768a
movl $0x0, -0x4(%rbp)
jmp 0x7843
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x7270
movl %eax, -0x1c(%rbp)
cmpl $0x0, %eax
je 0x76b2
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x7843
jmp 0x76b4
movq -0x18(%rbp), %rax
cmpb $0x0, 0x18(%rax)
je 0x76ef
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
leaq -0x70(%rbp), %rcx
callq 0x7390
movl %eax, -0x1c(%rbp)
cmpl $0x0, %eax
je 0x76ea
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x7843
jmp 0x782d
movb $0x0, -0x71(%rbp)
movl $0x0, -0x44(%rbp)
cmpl $0x2, -0x44(%rbp)
jae 0x773d
movl -0x44(%rbp), %eax
movsd 0x297d(%rip), %xmm0     # 0xa088
ucomisd -0x40(%rbp,%rax,8), %xmm0
jae 0x772a
movl -0x44(%rbp), %eax
movsd -0x40(%rbp,%rax,8), %xmm0
movsd 0x2914(%rip), %xmm1     # 0xa038
ucomisd %xmm1, %xmm0
jb 0x7730
movb $0x1, -0x71(%rbp)
jmp 0x773d
jmp 0x7732
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x76fa
cmpb $0x0, -0x71(%rbp)
je 0x7774
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
leaq -0x70(%rbp), %rcx
callq 0x7390
movl %eax, -0x1c(%rbp)
cmpl $0x0, %eax
je 0x776f
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x7843
jmp 0x782b
movl $0xffffffff, -0x48(%rbp) # imm = 0xFFFFFFFF
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x30(%rcx), %rcx
cmpl 0x20(%rcx), %eax
jae 0x7800
movl -0x44(%rbp), %eax
andl $0x3ff, %eax            # imm = 0x3FF
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x4c(%rbp)
jne 0x77ac
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x30(%rax), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x4c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rax
movq (%rax), %rax
cmpq -0x58(%rbp), %rax
jne 0x77f3
movq -0x80(%rbp), %rax
movq 0x8(%rax), %rax
cmpq -0x60(%rbp), %rax
jne 0x77f3
movl $0x0, -0x4(%rbp)
jmp 0x7843
jmp 0x77f5
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x7782
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x58(%rbp), %rsi
movq -0x60(%rbp), %rdx
leaq -0x70(%rbp), %rcx
callq 0x7390
movl %eax, -0x1c(%rbp)
cmpl $0x0, %eax
je 0x7829
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x7843
jmp 0x782b
jmp 0x782d
movq -0x70(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x8(%rcx), %rcx
movq %rcx, 0x10(%rax)
movl -0x1c(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nop