// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq (%rdi), %rax
testq %rax, %rax
je 0x4a35
cmpq $0x0, (%rax)
je 0x4a3b
xorl %r15d, %r15d
movq (%r14), %rdi
addq %r15, %rdi
movq %rbx, %rsi
callq 0x49e8
testl %eax, %eax
jne 0x4b92
addq $0x28, %r15
cmpq $0xa0, %r15
jne 0x4a0d
jmp 0x4b90
movq 0x28(%rbx), %r15
jmp 0x4a5e
movq 0x28(%rbx), %r15
movl 0x8(%r15), %eax
decl %eax
cmpl %eax, 0x20(%r14)
jne 0x4a5e
movq %r14, %rdi
movq %r15, %rsi
callq 0x4be0
ucomisd 0x10(%r15), %xmm0
ja 0x4a0a
movsd 0x8(%r14), %xmm0
andpd 0x2824(%rip), %xmm0     # 0x7290
movsd 0x30(%r15), %xmm1
ucomisd %xmm0, %xmm1
ja 0x4b90
movb 0x20(%r14), %cl
movl $0x1, %eax
shll %cl, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd 0x269a(%rip), %xmm1     # 0x7130
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
leaq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
xorpd %xmm0, %xmm0
leaq 0x30(%rsp), %rbp
movb $0x1, %r12b
xorl %r13d, %r13d
movq %rbp, %r15
movsd %xmm0, 0x18(%rsp)
movq 0x10(%rsp), %rax
movups (%rax), %xmm0
movaps %xmm0, 0x30(%rsp)
movsd 0x10(%r14,%r13,8), %xmm0
subsd 0x8(%rsp), %xmm0
movsd %xmm0, (%r15)
movq %rbp, %rdi
leaq 0x28(%rsp), %rsi
movq %rbx, %rdx
callq 0x4c4f
movsd 0x10(%r14,%r13,8), %xmm0
addsd 0x8(%rsp), %xmm0
movsd %xmm0, (%r15)
movq %rbp, %rdi
leaq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x4c4f
movq 0x28(%rbx), %rax
movsd 0x8(%r14), %xmm1
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
movsd 0x28(%rsp), %xmm0
movhpd 0x20(%rsp), %xmm0       # xmm0 = xmm0[0],mem[0]
subpd %xmm0, %xmm1
andpd 0x2758(%rip), %xmm1     # 0x7290
movsd 0x28(%rax), %xmm0
unpcklpd %xmm0, %xmm0            # xmm0 = xmm0[0,0]
mulpd %xmm1, %xmm0
addpd 0x2873(%rip), %xmm0     # 0x73c0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
minsd %xmm1, %xmm0
maxsd 0x18(%rsp), %xmm0
movl $0x1, %r13d
leaq 0x38(%rsp), %r15
testb $0x1, %r12b
movl $0x0, %r12d
jne 0x4abb
ucomisd 0x20(%rax), %xmm0
jbe 0x4b90
movq %r14, %rdi
movq %rbx, %rsi
callq 0x5124
testl %eax, %eax
jne 0x4b92
xorl %eax, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq