// File: /workspace/github_cpp_makefile_star2_O3/CK7[P]abawaca/src/ClusterSeparatorSplitScafs.cpp
// Function: ClusterSeparatorSplitScafs::separate_dimension(unsigned long)
void ClusterSeparatorSplitScafs::separate_dimension(size_t dimension_index)
{
	semaphore.wait();
	const Dimension& dimension = clustering_db.get_dimension(dimension_index);
	const set<double>& values = dimension.get_values();
	int values_checked = 0;

	// Initialize - curr_cluster1 will have no points while curr_cluster2 will have all dps
	Cluster 					curr_cluster1(scaf_db);
	Cluster 					curr_cluster2(scaf_db);
	ClusterSeparatorSplitScafs::IsScafIn		in_operator(fraction_dps_to_be_considered_in);
	ClusterSeparatorSplitScafs::ClusterStats	curr_cluster_stats1(curr_cluster1, scaf_db, in_operator);
	ClusterSeparatorSplitScafs::ClusterStats	curr_cluster_stats2(curr_cluster2, scaf_db, in_operator);
	vector<Dimension::DataPoint>			dps;

	set<size_t> useful_scafs;
	for(vector<Dimension::DataPoint>::const_iterator vit = dimension.begin(); vit!=dimension.end(); vit++) {
		curr_cluster_stats2 += vit->dp;
		dps.push_back(*vit);
		if(scaf_db.ndps(scaf_db.dp2scaf(vit->dp)) > 1)
			useful_scafs.insert(scaf_db.dp2scaf(vit->dp));
	}

	if(curr_cluster_stats2.num_scafs_in_this_cluster() != useful_scafs.size()) {
			cerr << "Error: # useful scafs=" << useful_scafs.size() << " but in cluster 2: " << curr_cluster_stats2.num_scafs_in_this_cluster() << endl;
		semaphore.notify();
		return;
	}
	sort(dps.begin(), dps.end(), comp_by_value);
	ClusterSeparatorSplitScafs::ClusteringResult	best_dimension_separation;

	for(auto vit=dps.begin(); vit!=dps.end();) {
		double value = vit->value;
		while(vit!=dps.end() && vit->value==value) {
			curr_cluster_stats1 += vit->dp;
			curr_cluster_stats2 -= vit->dp;
			vit++;
		}

		// Now do what we actually need to do in this specific class
		this->separate_specific(curr_cluster_stats1, curr_cluster_stats2, dimension_index, value, useful_scafs.size(), best_dimension_separation);
	}

	// Only a single access to the variables common to all threads
	unique_lock<mutex> lck(update_mtx);
	if(best_dimension_separation.is_better(*best_separation))
		best_separation->copy(best_dimension_separation);

	semaphore.notify();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x238, %rsp            # imm = 0x238
movq %rsi, %r14
movq %rdi, %rbx
movq 0xe0(%rdi), %rdi
callq 0x13c12
movq 0x18(%rbx), %rdi
movq %r14, -0x50(%rbp)
movq %r14, %rsi
callq 0xfe54
movq %rax, %r15
movq 0x8(%rbx), %rcx
leaq -0x248(%rbp), %rdx
movq %rcx, -0x10(%rdx)
xorl %eax, %eax
movl %eax, (%rdx)
movq %rax, 0x8(%rdx)
movq %rdx, 0x10(%rdx)
movq %rdx, 0x18(%rdx)
movq %rax, 0x20(%rdx)
leaq -0x1f0(%rbp), %rdx
movq %rdx, -0x30(%rdx)
movl $0x1, %esi
movq %rsi, -0x28(%rdx)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x20(%rdx)
movl $0x3f800000, %edi       # imm = 0x3F800000
movl %edi, -0x10(%rdx)
movupd %xmm0, -0x8(%rdx)
leaq -0x1e0(%rbp), %rdx
movl %eax, (%rdx)
movq %rax, 0x8(%rdx)
movq %rdx, 0x10(%rdx)
movq %rdx, 0x18(%rdx)
movq %rax, 0x20(%rdx)
leaq -0x1a8(%rbp), %rdx
movq %rcx, -0x10(%rdx)
movl %eax, (%rdx)
movq %rax, 0x8(%rdx)
movq %rdx, 0x10(%rdx)
movq %rdx, 0x18(%rdx)
movq %rax, 0x20(%rdx)
leaq -0x150(%rbp), %rdx
movq %rdx, -0x30(%rdx)
movq %rsi, -0x28(%rdx)
movupd %xmm0, -0x20(%rdx)
movl %edi, -0x10(%rdx)
movupd %xmm0, -0x8(%rdx)
leaq -0x140(%rbp), %rdx
movl %eax, (%rdx)
movq %rax, 0x8(%rdx)
movq %rdx, 0x10(%rdx)
movq %rdx, 0x18(%rdx)
movq %rax, 0x20(%rdx)
movsd 0xe8(%rbx), %xmm1
leaq -0xe8(%rbp), %rdx
movsd %xmm1, (%rdx)
movq %rcx, -0xb0(%rbp)
leaq -0x258(%rbp), %rsi
movq %rsi, -0xa8(%rbp)
movq %rax, -0xa0(%rbp)
movl %eax, -0x98(%rbp)
movq %rdx, -0x90(%rbp)
movq %rcx, -0x88(%rbp)
leaq -0x1b8(%rbp), %rcx
movq %rcx, -0x80(%rbp)
movq %rax, -0x78(%rbp)
movl %eax, -0x70(%rbp)
movq %rdx, -0x68(%rbp)
movq %rax, -0x30(%rbp)
movapd %xmm0, -0x40(%rbp)
leaq -0xd8(%rbp), %rcx
movl %eax, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movq 0x60(%r15), %r12
cmpq 0x68(%r15), %r12
je 0x14c81
leaq -0x88(%rbp), %r13
movq (%r12), %rsi
movq %r13, %rdi
callq 0x145a4
movq -0x38(%rbp), %rsi
cmpq -0x30(%rbp), %rsi
je 0x14c0e
movupd (%r12), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, -0x38(%rbp)
jmp 0x14c1a
leaq -0x40(%rbp), %rdi
movq %r12, %rdx
callq 0x13e86
movq 0x8(%rbx), %r14
movq (%r12), %rsi
movq %r14, %rdi
callq 0xcc30
movq %r14, %rdi
movq %rax, %rsi
callq 0xcce6
cmpq $0x2, %rax
jb 0x14c62
movq 0x8(%rbx), %rdi
movq (%r12), %rsi
callq 0xcc30
movq %rax, -0x118(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0x118(%rbp), %rsi
callq 0x13f68
addq $0x10, %r12
cmpq 0x68(%r15), %r12
jne 0x14be7
movslq -0x70(%rbp), %rax
cmpq %rax, -0xb8(%rbp)
jne 0x14deb
movq -0x40(%rbp), %r15
movq -0x38(%rbp), %r14
cmpq %r14, %r15
je 0x14ccd
movq %r14, %rax
subq %r15, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0x23cc(%rip), %rcx     # 0x128e0
movq %r15, %rdi
movq %r14, %rsi
callq 0x14022
leaq -0x23de(%rip), %rdx     # 0x128e0
movq %r15, %rdi
movq %r14, %rsi
callq 0x1415a
movq -0x40(%rbp), %r15
leaq -0x118(%rbp), %r12
movq $-0x1, 0x8(%r12)
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, 0x10(%r12)
leaq 0xcfe5(%rip), %rax      # 0x21cd8
movq %rax, (%r12)
movabsq $0x412e848000000000, %rax # imm = 0x412E848000000000
movq %rax, 0x18(%r12)
movq %rax, 0x20(%r12)
movabsq $0x3fb999999999999a, %rax # imm = 0x3FB999999999999A
movq %rax, 0x28(%r12)
leaq -0xb0(%rbp), %r13
leaq -0x88(%rbp), %r14
cmpq -0x38(%rbp), %r15
je 0x14d8b
movsd 0x8(%r15), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd 0x8(%r15), %xmm0
ucomisd -0x48(%rbp), %xmm0
jne 0x14d68
jp 0x14d68
movq (%r15), %rsi
movq %r13, %rdi
callq 0x145a4
movq (%r15), %rsi
movq %r14, %rdi
callq 0x1473c
addq $0x10, %r15
cmpq -0x38(%rbp), %r15
jne 0x14d39
movq -0xb8(%rbp), %r8
movq %rbx, %rdi
movq %r13, %rsi
movq %r14, %rdx
movq -0x50(%rbp), %rcx
movsd -0x48(%rbp), %xmm0
movq %r12, %r9
callq 0x14f3e
jmp 0x14d28
leaq 0xb8(%rbx), %rax
leaq -0x60(%rbp), %rdi
movq %rax, (%rdi)
movb $0x0, 0x8(%rdi)
callq 0x13e0e
movb $0x1, -0x58(%rbp)
movq 0xa8(%rbx), %rsi
leaq -0x118(%rbp), %rdi
callq 0x15062
testb %al, %al
je 0x14dd1
movq 0xa8(%rbx), %rdi
movq (%rdi), %rax
leaq -0x118(%rbp), %rsi
callq *0x8(%rax)
movq 0xe0(%rbx), %rdi
callq 0x13c68
leaq -0x60(%rbp), %rdi
callq 0x13cb0
jmp 0x14e6e
movq 0xd1f6(%rip), %rdi      # 0x21fe8
leaq 0x559f(%rip), %rsi      # 0x1a398
movl $0x16, %edx
callq 0x5420
movq -0xb8(%rbp), %rsi
movq 0xd1d7(%rip), %rdi      # 0x21fe8
callq 0x5240
movq %rax, %r14
leaq 0x558f(%rip), %rsi      # 0x1a3af
movl $0x13, %edx
movq %rax, %rdi
callq 0x5420
movl -0x70(%rbp), %esi
movq %r14, %rdi
callq 0x5670
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x5360
movsbl %al, %esi
movq %r14, %rdi
callq 0x5040
movq %rax, %rdi
callq 0x5250
movq 0xe0(%rbx), %rdi
callq 0x13c68
leaq -0x220(%rbp), %rbx
leaq -0x180(%rbp), %r14
leaq -0xe0(%rbp), %rdi
callq 0x9b94
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x14e96
callq 0x5340
leaq -0x148(%rbp), %rdi
callq 0x9b94
movq %r14, %rdi
callq 0x9bec
leaq -0x1b0(%rbp), %rdi
callq 0x9c62
leaq -0x1e8(%rbp), %rdi
callq 0x9b94
movq %rbx, %rdi
callq 0x9bec
leaq -0x250(%rbp), %rdi
callq 0x9c62
addq $0x238, %rsp            # imm = 0x238
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14f00
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x13cb0
jmp 0x14f03
jmp 0x14f00
jmp 0x14f00
jmp 0x14f00
jmp 0x14f00
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x9b94
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x14f1d
callq 0x5340
leaq -0x1b8(%rbp), %rdi
callq 0x13cca
leaq -0x258(%rbp), %rdi
callq 0x13cca
movq %rbx, %rdi
callq 0x56a0
nop