// File: /workspace/github_cpp_makefile_star2_O3/CK7[P]abawaca/src/ClusterQuality.cpp
// Function: ClusterQuality::is_split_better(Cluster const&, Cluster const&) const
bool ClusterQuality::is_split_better(/*const Cluster& cluster, */const Cluster& sub_cluster1, const Cluster& sub_cluster2) const
{
	map<string, size_t>	cluster_scgs, sub_cluster1_scgs, sub_cluster2_scgs;
	size_t	sub_cluster1_size=0, sub_cluster2_size=0;

//	auto cluster_scafs = cluster.get_assigned_scafs();
	auto sub_cluster1_scafs = sub_cluster1.get_assigned_scafs();
	auto sub_cluster2_scafs = sub_cluster2.get_assigned_scafs();
	set<size_t> cluster_scafs(sub_cluster1_scafs);
	cluster_scafs.insert(sub_cluster2_scafs.begin(), sub_cluster2_scafs.end());

	scg_db.get_scg2count(cluster_scafs, cluster_scgs);
	scg_db.get_scg2count(sub_cluster1_scafs, sub_cluster1_scgs);
	scg_db.get_scg2count(sub_cluster2_scafs, sub_cluster2_scgs);

	for(auto it=sub_cluster1_scafs.begin(); it!=sub_cluster1_scafs.end(); it++)
		sub_cluster1_size += scaf_db.get_scaf(*it)->get_seq_size();

	for(auto it=sub_cluster2_scafs.begin(); it!=sub_cluster2_scafs.end(); it++)
		sub_cluster2_size += scaf_db.get_scaf(*it)->get_seq_size();

	// If one of the clusters has no SCGs then decide based on the total cluster size.
	if((sub_cluster1_scgs.size() == 0) || (sub_cluster2_scgs.size() == 0)) {
		return ((sub_cluster1_size >= 500000) && (sub_cluster2_size >= 500000));
	}

	// If the two clusters have complementary sets of SCGs - don't split further.
	set<string> scgs;
	for(auto it=sub_cluster1_scgs.begin(); it!=sub_cluster1_scgs.end(); it++) {
		if(sub_cluster2_scgs.find(it->first) != sub_cluster2_scgs.end())
			scgs.insert(it->first);
	}

	// If the overlap between the two clusters is small then this is probably an over-splitting.
	if(double(scgs.size())/((sub_cluster1_scgs.size()<sub_cluster2_scgs.size())? sub_cluster1_scgs.size() : sub_cluster2_scgs.size()) < 0.2)
		return false;

	// Consider more criteria

	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rdx, %r14
movq %rdi, %rbx
leaq -0x178(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, (%rax)
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
leaq -0x58(%rbp), %r13
movl %ecx, (%r13)
movq %rcx, 0x8(%r13)
movq %r13, 0x10(%r13)
movq %r13, 0x18(%r13)
movq %rcx, 0x20(%r13)
leaq -0x88(%rbp), %rax
movl %ecx, (%rax)
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
addq $0x70, %rsi
leaq -0xf0(%rbp), %rdi
callq 0x188d8
addq $0x70, %r14
leaq -0xc0(%rbp), %rdi
movq %r14, %rsi
callq 0x188d8
leaq -0x150(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x188d8
leaq -0xb8(%rbp), %r14
movq 0x10(%r14), %rsi
leaq -0x150(%rbp), %rdi
movq %r14, %rdx
callq 0x18bc2
movq 0x10(%rbx), %rdi
leaq -0x150(%rbp), %rsi
leaq -0x180(%rbp), %rdx
callq 0x15260
movq 0x10(%rbx), %rdi
leaq -0xf0(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x15260
movq 0x10(%rbx), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x15260
leaq -0xe8(%rbp), %r15
movq 0x10(%r15), %rax
movabsq $-0x71c71c71c71c71c7, %rdx # imm = 0x8E38E38E38E38E39
cmpq %r15, %rax
je 0x1860e
movq %rbx, -0x30(%rbp)
movq 0x8(%rbx), %rcx
movq 0x78(%rcx), %r12
movq 0x80(%rcx), %rbx
subq %r12, %rbx
sarq $0x3, %rbx
imulq %rdx, %rbx
xorl %r13d, %r13d
xorl %r14d, %r14d
movq 0x20(%rax), %rcx
cmpq %rcx, %rbx
leaq (%rcx,%rcx,8), %rcx
leaq (%r12,%rcx,8), %rcx
cmovbeq %r13, %rcx
movq 0x38(%rcx), %rcx
addq 0x50(%rcx), %r14
movq %rax, %rdi
callq 0x5430
cmpq %r15, %rax
jne 0x185c0
cmpq $0x7a120, %r14          # imm = 0x7A120
setae %r15b
leaq -0x58(%rbp), %r13
movq -0x30(%rbp), %rbx
leaq -0xb8(%rbp), %r14
movabsq $-0x71c71c71c71c71c7, %rdx # imm = 0x8E38E38E38E38E39
jmp 0x18611
xorl %r15d, %r15d
movq -0xa8(%rbp), %rax
cmpq %r14, %rax
je 0x18680
movl %r15d, -0x30(%rbp)
movq 0x8(%rbx), %rcx
movq 0x78(%rcx), %rbx
movq 0x80(%rcx), %r12
subq %rbx, %r12
sarq $0x3, %r12
imulq %rdx, %r12
xorl %r13d, %r13d
movq %r14, %r15
xorl %r14d, %r14d
movq 0x20(%rax), %rcx
cmpq %rcx, %r12
leaq (%rcx,%rcx,8), %rcx
leaq (%rbx,%rcx,8), %rcx
cmovbeq %r13, %rcx
movq 0x38(%rcx), %rcx
addq 0x50(%rcx), %r14
movq %rax, %rdi
callq 0x5430
cmpq %r15, %rax
jne 0x18644
cmpq $0x7a120, %r14          # imm = 0x7A120
setae %dl
leaq -0x58(%rbp), %r13
movl -0x30(%rbp), %r15d
jmp 0x18682
xorl %edx, %edx
movq -0x38(%rbp), %rax
testq %rax, %rax
sete %sil
movq -0x68(%rbp), %rcx
testq %rcx, %rcx
sete %dil
orb %sil, %dil
je 0x186a5
andb %dl, %r15b
jmp 0x1878a
leaq -0x118(%rbp), %rdx
movl $0x0, (%rdx)
xorl %esi, %esi
movq %rsi, 0x8(%rdx)
movq %rdx, 0x10(%rdx)
movq %rdx, 0x18(%rdx)
movq %rsi, 0x20(%rdx)
movq -0x48(%rbp), %rbx
cmpq %r13, %rbx
je 0x1873e
leaq -0x90(%rbp), %r14
leaq -0x120(%rbp), %r15
leaq 0x20(%rbx), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0xf494
leaq -0x88(%rbp), %rcx
cmpq %rcx, %rax
je 0x18701
movq %r15, %rdi
movq %r12, %rsi
callq 0x18d1c
movq %rbx, %rdi
callq 0x5260
movq %rax, %rbx
cmpq %r13, %rax
jne 0x186db
movq -0x38(%rbp), %rax
movsd -0xf8(%rbp), %xmm1
unpcklps 0x1a6c(%rip), %xmm1     # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1a74(%rip), %xmm1     # 0x1a1a0
movq -0x68(%rbp), %rcx
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
jmp 0x18742
xorpd %xmm0, %xmm0
cmpq %rcx, %rax
cmovbq %rax, %rcx
movq %rcx, %xmm1
punpckldq 0x1a3a(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x1a42(%rip), %xmm1     # 0x1a1a0
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
divsd %xmm2, %xmm0
movsd 0x1f72(%rip), %xmm1     # 0x1a6e8
ucomisd %xmm0, %xmm1
setbe %r15b
leaq -0x120(%rbp), %rdi
callq 0x9852
leaq -0x150(%rbp), %rdi
callq 0x9b94
leaq -0xc0(%rbp), %rdi
callq 0x9b94
leaq -0xf0(%rbp), %rdi
callq 0x9b94
leaq -0x90(%rbp), %rdi
callq 0x9dba
leaq -0x60(%rbp), %rdi
callq 0x9dba
leaq -0x180(%rbp), %rdi
callq 0x9dba
movl %r15d, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x18815
movq %rax, %rbx
jmp 0x18821
movq %rax, %rbx
jmp 0x1882d
movq %rax, %rbx
jmp 0x18809
jmp 0x187fa
movq %rax, %rbx
leaq -0x120(%rbp), %rdi
callq 0x9852
leaq -0x150(%rbp), %rdi
callq 0x9b94
leaq -0xc0(%rbp), %rdi
callq 0x9b94
leaq -0xf0(%rbp), %rdi
callq 0x9b94
leaq -0x90(%rbp), %rdi
callq 0x9dba
leaq -0x60(%rbp), %rdi
callq 0x9dba
leaq -0x180(%rbp), %rdi
callq 0x9dba
movq %rbx, %rdi
callq 0x56a0