// File: CK7[P]abawaca/src/ClusterSeparatorSplitScafs.cpp
// Function: ClusterSeparatorSplitScafs::separate_specific(ClusterSeparatorSplitScafs::ClusterStats&, ClusterSeparatorSplitScafs::ClusterStats&, unsigned long, double, unsigned long, ClusterSeparatorSplitScafs::ClusteringResult&)
void ClusterSeparatorSplitScafs::separate_specific(ClusterStats& curr_cluster1, ClusterStats& curr_cluster2, size_t dimension_index, double tested_value, size_t nuseful_scafs,
	ClusterSeparatorSplitScafs::ClusteringResult& best_dimension_separation)
{
	// First we will move the dps from cluster2 to cluster1. This includes updating in1, in2, separated, cluster1_useful_ndps and cluster2_useful_ndps.
	size_t separated = nuseful_scafs - curr_cluster1.num_scafs_in_this_cluster() - curr_cluster2.num_scafs_in_this_cluster();

	// Which one is smaller in terms of the number of datapoints that will be considered 
	// for the clustering?
	if((curr_cluster1.ndps_this_cluster_scafs() < this->cluster_ndps_threshold) || (curr_cluster2.ndps_this_cluster_scafs() < this->cluster_ndps_threshold))
		return;

	// Now pick the smaller cluster, we will compute sensitivity and specificity on that one
	const ClusterStats& small_cluster = (curr_cluster1.num_useful_ndps() < curr_cluster2.num_useful_ndps())? curr_cluster1 : curr_cluster2;
	const ClusterStats& large_cluster = (curr_cluster1.num_useful_ndps() >= curr_cluster2.num_useful_ndps())? curr_cluster1 : curr_cluster2;

	double separated_to_cluster1_ratio = double(separated)/double(small_cluster.num_scafs_in_this_cluster());
	double cluster_size_ratio = double(small_cluster.num_scafs_in_this_cluster())/large_cluster.num_scafs_in_this_cluster();
	if(cluster_size_ratio<1)
		cluster_size_ratio = 1/cluster_size_ratio;

	ClusterSeparatorSplitScafs::ClusteringResult	cr(dimension_index, tested_value, separated_to_cluster1_ratio, cluster_size_ratio);
	if(cr.is_better(best_dimension_separation))
		best_dimension_separation.copy(cr);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2b900
movl %eax, %ecx
movq -0xa8(%rbp), %rax
movslq %ecx, %rcx
subq %rcx, %rax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2b900
movl %eax, %ecx
movq -0xa0(%rbp), %rax
movslq %ecx, %rcx
subq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2ba80
movq -0x98(%rbp), %rcx
cltq
cmpq 0xb0(%rcx), %rax
jb 0x2b5af
movq -0x18(%rbp), %rdi
callq 0x2ba80
movq -0x98(%rbp), %rcx
cltq
cmpq 0xb0(%rcx), %rax
jae 0x2b5b4
jmp 0x2b729
movq -0x10(%rbp), %rdi
callq 0x2baa0
movl %eax, -0xac(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2baa0
movl %eax, %ecx
movl -0xac(%rbp), %eax
cmpl %ecx, %eax
jge 0x2b5e5
movq -0x10(%rbp), %rax
movq %rax, -0xb8(%rbp)
jmp 0x2b5f0
movq -0x18(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0xb8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rdi
callq 0x2baa0
movl %eax, -0xbc(%rbp)
movq -0x18(%rbp), %rdi
callq 0x2baa0
movl %eax, %ecx
movl -0xbc(%rbp), %eax
cmpl %ecx, %eax
jl 0x2b62c
movq -0x10(%rbp), %rax
movq %rax, -0xc8(%rbp)
jmp 0x2b637
movq -0x18(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x50(%rbp)
movaps 0xab37(%rip), %xmm1     # 0x36180
movq -0x40(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0xab36(%rip), %xmm1     # 0x36190
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0xd8(%rbp)
movq -0x48(%rbp), %rdi
callq 0x2b900
movsd -0xd8(%rbp), %xmm0
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x48(%rbp), %rdi
callq 0x2b900
cvtsi2sd %eax, %xmm0
movsd %xmm0, -0xd0(%rbp)
movq -0x50(%rbp), %rdi
callq 0x2b900
movsd -0xd0(%rbp), %xmm0
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movsd 0xaad6(%rip), %xmm0     # 0x361a0
ucomisd -0x60(%rbp), %xmm0
jbe 0x2b6e3
movsd 0xaac7(%rip), %xmm0     # 0x361a0
divsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x20(%rbp), %rsi
movsd -0x28(%rbp), %xmm0
movsd -0x58(%rbp), %xmm1
movsd -0x60(%rbp), %xmm2
leaq -0x90(%rbp), %rdi
callq 0x2bac0
movq -0x38(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x2b9a0
testb $0x1, %al
jne 0x2b718
jmp 0x2b729
movq -0x38(%rbp), %rdi
movq (%rdi), %rax
leaq -0x90(%rbp), %rsi
callq *0x8(%rax)
addq $0xe0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)