// File: /workspace/github_cpp_makefile_star2_O3/CK7[P]abawaca/src/ClusterSeparatorBySensitivitySpecificity.cpp
// Function: ClusterSeparatorBySensitivitySpecificity::separate_dimension(unsigned long)
void ClusterSeparatorBySensitivitySpecificity::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);
	ClusterSeparatorBySensitivitySpecificity::ClusterStats	curr_cluster_stats1(curr_cluster1, scaf_db);
	ClusterSeparatorBySensitivitySpecificity::ClusterStats	curr_cluster_stats2(curr_cluster2, scaf_db);
	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.add_dp(vit->dp);
		dps.push_back(*vit);
		if(scaf_db.ndps(scaf_db.dp2scaf(vit->dp)) > 1) {
			useful_scafs.insert(scaf_db.dp2scaf(vit->dp));
			curr_cluster_stats2.assign_scaf(scaf_db.dp2scaf(vit->dp));
		}
	}

	sort(dps.begin(), dps.end(), comp_by_value);
	ClusterSeparatorBySensitivitySpecificity::ClusteringResult	best_dimension_separation;

	for(auto vit=dps.begin(); vit!=dps.end();) {
		double value = vit->value;
		while(vit!=dps.end() && vit->value==value) {
			size_t scaf = scaf_db.dp2scaf(vit->dp);
			size_t scaf_total_ndps = scaf_db.ndps(scaf);

			curr_cluster_stats1.add_dp(vit->dp);
			curr_cluster_stats2.remove_dp(vit->dp);
			if(curr_cluster_stats2.get_cluster().assigned(scaf) && (scaf_total_ndps >= 2) && (2*curr_cluster_stats1.get_cluster().ndps(scaf) > scaf_total_ndps)) {
				curr_cluster_stats1.assign_scaf(scaf);
				curr_cluster_stats2.unassign_scaf(scaf);
			}
			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, 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 $0x248, %rsp            # imm = 0x248
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, %r12
movq 0x8(%rbx), %rax
leaq -0x258(%rbp), %rcx
movq %rax, -0x10(%rcx)
xorl %r15d, %r15d
movl %r15d, (%rcx)
movq %r15, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %r15, 0x20(%rcx)
leaq -0x200(%rbp), %rcx
movq %rcx, -0x30(%rcx)
movl $0x1, %edx
movq %rdx, -0x28(%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x20(%rcx)
movl $0x3f800000, %esi       # imm = 0x3F800000
movl %esi, -0x10(%rcx)
movupd %xmm0, -0x8(%rcx)
leaq -0x1f0(%rbp), %rcx
movl %r15d, (%rcx)
movq %r15, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %r15, 0x20(%rcx)
leaq -0x1b8(%rbp), %rcx
movq %rax, -0x10(%rcx)
movl %r15d, (%rcx)
movq %r15, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %r15, 0x20(%rcx)
leaq -0x160(%rbp), %rcx
movq %rcx, -0x30(%rcx)
movq %rdx, -0x28(%rcx)
movupd %xmm0, -0x20(%rcx)
movl %esi, -0x10(%rcx)
movupd %xmm0, -0x8(%rcx)
leaq -0x150(%rbp), %rcx
movl %r15d, (%rcx)
movq %r15, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %r15, 0x20(%rcx)
movq %rax, -0x80(%rbp)
leaq -0x268(%rbp), %rcx
movq %rcx, -0x78(%rbp)
leaq 0xe548(%rip), %rcx      # 0x21c20
movq %rcx, -0x88(%rbp)
movq %r15, -0x70(%rbp)
movl %r15d, -0x68(%rbp)
movq %rax, -0xa8(%rbp)
leaq -0x1c8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq %rcx, -0xb0(%rbp)
movq %r15, -0x98(%rbp)
movl %r15d, -0x90(%rbp)
movq %r15, -0x30(%rbp)
movapd %xmm0, -0x40(%rbp)
leaq -0x120(%rbp), %rax
movl %r15d, (%rax)
movq %r15, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %r15, 0x20(%rax)
movq 0x60(%r12), %r14
cmpq 0x68(%r12), %r14
je 0x13834
leaq -0xb0(%rbp), %r15
movq (%r14), %rsi
movq %r15, %rdi
callq 0x13154
movq -0x38(%rbp), %rsi
cmpq -0x30(%rbp), %rsi
je 0x13770
movupd (%r14), %xmm0
movupd %xmm0, (%rsi)
addq $0x10, -0x38(%rbp)
jmp 0x1377c
leaq -0x40(%rbp), %rdi
movq %r14, %rdx
callq 0x13e86
movq 0x8(%rbx), %r13
movq (%r14), %rsi
movq %r13, %rdi
callq 0xcc30
movq %r13, %rdi
movq %rax, %rsi
callq 0xcce6
cmpq $0x2, %rax
jb 0x137d9
movq 0x8(%rbx), %rdi
movq (%r14), %rsi
callq 0xcc30
movq %rax, -0xf8(%rbp)
leaq -0x128(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x13f68
movq 0x8(%rbx), %rdi
movq (%r14), %rsi
callq 0xcc30
movq %r15, %rdi
movq %rax, %rsi
callq 0x13274
addq $0x10, %r14
cmpq 0x68(%r12), %r14
jne 0x1374b
movq -0x40(%rbp), %r15
movq -0x38(%rbp), %r14
cmpq %r14, %r15
je 0x13834
movq %r14, %rax
subq %r15, %rax
sarq $0x4, %rax
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0xf33(%rip), %rcx      # 0x128e0
movq %r15, %rdi
movq %r14, %rsi
callq 0x14022
leaq -0xf45(%rip), %rdx      # 0x128e0
movq %r15, %rdi
movq %r14, %rsi
callq 0x1415a
movq -0x40(%rbp), %r15
leaq -0xf8(%rbp), %rcx
movq $-0x1, 0x8(%rcx)
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, 0x10(%rcx)
leaq 0xdfd0(%rip), %rax      # 0x21828
movq %rax, (%rcx)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x18(%rcx)
movabsq $0x3fe999999999999a, %rax # imm = 0x3FE999999999999A
movq %rax, 0x28(%rcx)
movq %rax, 0x30(%rcx)
movq %rax, 0x38(%rcx)
movabsq $0x3ff999999999999a, %rax # imm = 0x3FF999999999999A
movq %rax, 0x40(%rcx)
leaq -0xb0(%rbp), %r14
cmpq -0x38(%rbp), %r15
je 0x13999
movsd 0x8(%r15), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd 0x8(%r15), %xmm0
ucomisd -0x48(%rbp), %xmm0
jne 0x13972
jp 0x13972
movq 0x8(%rbx), %rdi
movq (%r15), %rsi
callq 0xcc30
movq %rax, %r12
movq 0x8(%rbx), %rdi
movq %rax, %rsi
callq 0xcce6
movq %rax, %r13
movq (%r15), %rsi
leaq -0x88(%rbp), %rdi
callq 0x13154
movq (%r15), %rsi
movq %r14, %rdi
callq 0x131e4
movq -0xa0(%rbp), %rax
movq 0x80(%rax), %rdx
testq %rdx, %rdx
je 0x13964
addq $0x78, %rax
movq %rax, %rcx
xorl %esi, %esi
cmpq %r12, 0x20(%rdx)
setb %sil
cmovaeq %rdx, %rcx
movq 0x10(%rdx,%rsi,8), %rdx
testq %rdx, %rdx
jne 0x1390d
cmpq %rax, %rcx
je 0x13964
cmpq $0x2, %r13
jb 0x13964
cmpq %r12, 0x20(%rcx)
ja 0x13964
movq -0x78(%rbp), %rdi
movq %r12, %rsi
callq 0x12278
addq %rax, %rax
cmpq %r13, %rax
jbe 0x13964
leaq -0x88(%rbp), %rdi
movq %r12, %rsi
callq 0x13274
movq %r14, %rdi
movq %r12, %rsi
callq 0x1334c
addq $0x10, %r15
cmpq -0x38(%rbp), %r15
jne 0x138a4
movq %rbx, %rdi
leaq -0x88(%rbp), %rsi
movq %r14, %rdx
movq -0x50(%rbp), %rcx
movsd -0x48(%rbp), %xmm0
leaq -0xf8(%rbp), %r8
callq 0x13ac0
jmp 0x1388f
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 -0xf8(%rbp), %rdi
callq 0x9a3e
testb %al, %al
je 0x139df
movq 0xa8(%rbx), %rdi
movq (%rdi), %rax
leaq -0xf8(%rbp), %rsi
callq *0x8(%rax)
movq 0xe0(%rbx), %rdi
callq 0x13c68
leaq -0x60(%rbp), %rdi
callq 0x13cb0
leaq -0x128(%rbp), %rdi
callq 0x9b94
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x13a0e
callq 0x5340
leaq -0x158(%rbp), %rdi
callq 0x9b94
leaq -0x190(%rbp), %rdi
callq 0x9bec
leaq -0x1c0(%rbp), %rdi
callq 0x9c62
leaq -0x1f8(%rbp), %rdi
callq 0x9b94
leaq -0x230(%rbp), %rdi
callq 0x9bec
leaq -0x260(%rbp), %rdi
callq 0x9c62
addq $0x248, %rsp            # imm = 0x248
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x13a82
jmp 0x13a82
movq %rax, %rbx
leaq -0x60(%rbp), %rdi
callq 0x13cb0
jmp 0x13a85
jmp 0x13a82
jmp 0x13a82
jmp 0x13a82
jmp 0x13a82
movq %rax, %rbx
leaq -0x128(%rbp), %rdi
callq 0x9b94
movq -0x40(%rbp), %rdi
testq %rdi, %rdi
je 0x13a9f
callq 0x5340
leaq -0x1c8(%rbp), %rdi
callq 0x13cca
leaq -0x268(%rbp), %rdi
callq 0x13cca
movq %rbx, %rdi
callq 0x56a0
nop