// File: /workspace/github_c_makefile_star2_O2/kernfel[P]fNEAT/extract.c
// Function: extract_tree
int extract_tree( BinLeaf *p, struct Extraction_Params *eparams ) {
	int i, j, err=0;
	// If the children c of p do not have children gc, that means that either:
	// (a) c weren't recursed into because the variance threshold wasn't met
	//	=> c's are not different enough to warrant expressing
	//	=> express p and move on
	// (b) c were at highest resolution
	//	=> check variance over all c to decide whether to express them or not
	// Since variance is not calculated recursively, this process may leave a few fragments from min_resolution.
	if ( p->c \
	 && ( p->c[0].c \
	   || ( p->level == eparams->params->max_resolution-1 && get_binleaf_variance(p, eparams->params) > eparams->params->variance_threshold ) ) ) {
		for ( i=0; i<CLUSTERSIZE; i++ ) {
			if (( err = extract_tree( &p->c[i], eparams ) ))
				return err;
		}
	} else {
		// Check expression level
		for ( i=0; i<N_OUTPUTS; i++ )
			if ( fabs(p->r[i]) < eparams->params->expression_thresholds[i] )
				return err;

		// Band pruning: See whether I'm in a slope of some sort
		double w = 1.0 / (1<<p->level);
		double dband=0;
		for ( i=0; i<DIMENSIONS; i++ ) {
			double neighbour[DIMENSIONS], left[N_OUTPUTS], right[N_OUTPUTS];
			memcpy( neighbour, p->x, DIMENSIONS*sizeof *neighbour );

			// Left neighbour
			neighbour[i] = p->x[i] - w;
			get_activation_at( neighbour, left, eparams );
			// Right neighbour
			neighbour[i] = p->x[i] + w;
			get_activation_at( neighbour, right, eparams );
			
			// Calculate weighted difference
			double dleft=0, dright=0;
			for ( j=0; j<N_OUTPUTS; j++ ) {
				dleft += eparams->params->output_bandpruning_weight[j] * fabs(p->r[j] - left[j]);
				dright += eparams->params->output_bandpruning_weight[j] * fabs(p->r[j] - right[j]);
			}
			double ddim = dleft < dright ? dleft : dright;
			if ( ddim > dband )
				dband = ddim;
		}

		// Add a new connection
		if ( dband > eparams->params->band_threshold ) {
			if (( err = connect_pNet( p, eparams ) ))
				return err;
		}
	}

	return err;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq (%rdi), %rax
testq %rax, %rax
je 0x444b
cmpq $0x0, (%rax)
je 0x4451
xorl %r13d, %r13d
xorl %edi, %edi
leaq 0x28(%rdi), %r15
cmpq $0xc8, %r15
je 0x459c
addq (%r14), %rdi
movq %rbx, %rsi
callq 0x43fc
movq %r15, %rdi
testl %eax, %eax
je 0x4423
jmp 0x4594
movq 0x28(%rbx), %r12
jmp 0x4476
movq 0x28(%rbx), %r12
movl 0x8(%r12), %eax
decl %eax
cmpl %eax, 0x20(%r14)
jne 0x4476
movq %r14, %rdi
movq %r12, %rsi
callq 0x45e9
ucomisd 0x10(%r12), %xmm0
ja 0x441e
movsd 0x8(%r14), %xmm0
andpd 0x1dbc(%rip), %xmm0     # 0x6240
movsd 0x30(%r12), %xmm1
xorl %r13d, %r13d
ucomisd %xmm0, %xmm1
ja 0x459c
movb 0x20(%r14), %cl
pushq $0x1
popq %rax
shll %cl, %eax
cvtsi2sd %eax, %xmm0
movsd 0x1c63(%rip), %xmm1     # 0x6110
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
leaq 0x10(%r14), %rbp
xorpd %xmm1, %xmm1
pushq $0x2
popq %r15
leaq 0x10(%rsp), %r13
cmpq $0x4, %r15
je 0x457c
movups (%rbp), %xmm0
movaps %xmm0, 0x10(%rsp)
movsd (%r14,%r15,8), %xmm0
subsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsp,%r15,8)
movq %r13, %rdi
leaq 0x30(%rsp), %rsi
movq %rbx, %rdx
movsd %xmm1, 0x20(%rsp)
callq 0x4662
movsd (%r14,%r15,8), %xmm0
addsd 0x8(%rsp), %xmm0
movsd %xmm0, (%rsp,%r15,8)
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
movq %rbx, %rdx
callq 0x4662
movq 0x28(%rbx), %r12
movsd 0x8(%r14), %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
movsd 0x30(%rsp), %xmm1
movhpd 0x28(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
subpd %xmm1, %xmm0
andpd 0x1cf5(%rip), %xmm0     # 0x6240
movsd 0x28(%r12), %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
mulpd %xmm0, %xmm1
addpd 0x1dee(%rip), %xmm1     # 0x6350
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
minsd %xmm0, %xmm1
maxsd 0x20(%rsp), %xmm1
incq %r15
jmp 0x44c8
ucomisd 0x20(%r12), %xmm1
jbe 0x4599
movq %r14, %rdi
movq %rbx, %rsi
callq 0x4ad7
testl %eax, %eax
je 0x4599
movl %eax, %r13d
jmp 0x459c
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq