// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl $0x0, -0x24(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x67bb
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpq $0x0, (%rax)
jne 0x676e
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x18(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl 0x8(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0x67bb
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rsi
callq 0x6a90
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
ucomisd 0x10(%rax), %xmm0
jbe 0x67bb
movl $0x0, -0x1c(%rbp)
cmpl $0x4, -0x1c(%rbp)
jge 0x67b6
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movslq -0x1c(%rbp), %rax
imulq $0x28, %rax, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rsi
callq 0x6700
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
je 0x67a9
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x6a0b
jmp 0x67ab
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x6775
jmp 0x6a05
movl $0x0, -0x1c(%rbp)
cmpl $0x1, -0x1c(%rbp)
jge 0x6811
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd 0x8(%rax,%rcx,8), %xmm1
movaps 0x39d3(%rip), %xmm0     # 0xa1b0
pand %xmm0, %xmm1
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x1c(%rbp), %rcx
movsd 0x30(%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x6804
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x6a0b
jmp 0x6806
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x67c2
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
cvtsi2sd %eax, %xmm1
movsd 0x383d(%rip), %xmm0     # 0xa068
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movl $0x0, -0x1c(%rbp)
cmpl $0x2, -0x1c(%rbp)
jge 0x69d0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq %rcx, -0x50(%rbp)
movq 0x18(%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd 0x10(%rax,%rcx,8), %xmm0
subsd -0x30(%rbp), %xmm0
movslq -0x1c(%rbp), %rax
movsd %xmm0, -0x50(%rbp,%rax,8)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x6bc0
movq -0x10(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd 0x10(%rax,%rcx,8), %xmm0
addsd -0x30(%rbp), %xmm0
movslq -0x1c(%rbp), %rax
movsd %xmm0, -0x50(%rbp,%rax,8)
leaq -0x50(%rbp), %rdi
leaq -0x60(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x6bc0
xorps %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x70(%rbp)
movl $0x0, -0x20(%rbp)
cmpl $0x1, -0x20(%rbp)
jge 0x697a
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x20(%rbp), %rcx
movsd 0x28(%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsd 0x8(%rax,%rcx,8), %xmm2
movslq -0x20(%rbp), %rax
subsd -0x58(%rbp,%rax,8), %xmm2
movaps 0x38a1(%rip), %xmm1     # 0xa1b0
pand %xmm1, %xmm2
movsd -0x68(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x20(%rbp), %rcx
movsd 0x28(%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movslq -0x20(%rbp), %rcx
movsd 0x8(%rax,%rcx,8), %xmm2
movslq -0x20(%rbp), %rax
subsd -0x60(%rbp,%rax,8), %xmm2
movaps 0x385a(%rip), %xmm1     # 0xa1b0
pand %xmm1, %xmm2
movsd -0x70(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x68d4
movsd -0x68(%rbp), %xmm1
movsd -0x70(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x6996
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
jmp 0x69a0
movsd -0x70(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movsd -0x80(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm0
ucomisd -0x38(%rbp), %xmm0
jbe 0x69c0
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x69c2
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x6843
movsd -0x38(%rbp), %xmm0
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
ucomisd 0x20(%rax), %xmm0
jbe 0x6a03
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x74c0
movl %eax, -0x24(%rbp)
cmpl $0x0, %eax
je 0x6a01
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x6a0b
jmp 0x6a03
jmp 0x6a05
movl -0x24(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw (%rax,%rax)