// File: /workspace/github_cpp_makefile_star2_O1/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 0x18bc2
addq $0x70, %r14
leaq -0xc0(%rbp), %rdi
movq %r14, %rsi
callq 0x18bc2
leaq -0x120(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x18bc2
leaq -0xb8(%rbp), %r14
movq 0x10(%r14), %rsi
leaq -0x120(%rbp), %rdi
movq %r14, %rdx
callq 0x18eac
movq 0x10(%rbx), %rdi
leaq -0x120(%rbp), %rsi
leaq -0x180(%rbp), %rdx
callq 0x154ba
movq 0x10(%rbx), %rdi
leaq -0xf0(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x154ba
movq 0x10(%rbx), %rdi
leaq -0xc0(%rbp), %rsi
leaq -0x90(%rbp), %rdx
callq 0x154ba
leaq -0xe8(%rbp), %r15
movq 0x10(%r15), %rax
movabsq $-0x71c71c71c71c71c7, %rdx # imm = 0x8E38E38E38E38E39
cmpq %r15, %rax
je 0x18908
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 0x188ba
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 0x1890b
xorl %r15d, %r15d
movq -0xa8(%rbp), %rax
cmpq %r14, %rax
je 0x1897a
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 0x1893e
cmpq $0x7a120, %r14          # imm = 0x7A120
setae %al
leaq -0x58(%rbp), %r13
movl -0x30(%rbp), %r15d
jmp 0x1897c
xorl %eax, %eax
cmpq $0x0, -0x38(%rbp)
je 0x18a70
cmpq $0x0, -0x68(%rbp)
je 0x18a70
leaq -0x148(%rbp), %rax
movl $0x0, (%rax)
xorl %ecx, %ecx
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
movq -0x48(%rbp), %rbx
cmpq %r13, %rbx
je 0x189fe
leaq -0x90(%rbp), %r14
leaq -0x150(%rbp), %r15
leaq 0x20(%rbx), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0xf5b0
leaq -0x88(%rbp), %rcx
cmpq %rcx, %rax
je 0x189ee
movq %r15, %rdi
movq %r12, %rsi
callq 0x19006
movq %rbx, %rdi
callq 0x5260
movq %rax, %rbx
cmpq %r13, %rax
jne 0x189c8
leaq -0x150(%rbp), %rdi
movsd 0x28(%rdi), %xmm0
movsd 0x278e(%rip), %xmm1     # 0x1b1a0
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x2793(%rip), %xmm2     # 0x1b1b0
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movq -0x38(%rbp), %rax
movq -0x68(%rbp), %rcx
cmpq %rcx, %rax
cmovbq %rax, %rcx
movq %rcx, %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
subpd %xmm2, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
divsd %xmm1, %xmm3
movsd 0x2c97(%rip), %xmm0     # 0x1b6f8
ucomisd %xmm3, %xmm0
setbe %r15b
callq 0x990a
jmp 0x18a73
andb %al, %r15b
leaq -0x120(%rbp), %rdi
callq 0x9c80
leaq -0xc0(%rbp), %rdi
callq 0x9c80
leaq -0xf0(%rbp), %rdi
callq 0x9c80
leaq -0x90(%rbp), %rdi
callq 0x9e9c
leaq -0x60(%rbp), %rdi
callq 0x9e9c
leaq -0x180(%rbp), %rdi
callq 0x9e9c
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 0x18afe
movq %rax, %rbx
jmp 0x18b0a
movq %rax, %rbx
jmp 0x18b16
movq %rax, %rbx
jmp 0x18af2
jmp 0x18ae3
movq %rax, %rbx
leaq -0x150(%rbp), %rdi
callq 0x990a
leaq -0x120(%rbp), %rdi
callq 0x9c80
leaq -0xc0(%rbp), %rdi
callq 0x9c80
leaq -0xf0(%rbp), %rdi
callq 0x9c80
leaq -0x90(%rbp), %rdi
callq 0x9e9c
leaq -0x60(%rbp), %rdi
callq 0x9e9c
leaq -0x180(%rbp), %rdi
callq 0x9e9c
movq %rbx, %rdi
callq 0x56a0
nop