// File: /workspace/github_cpp_makefile_star2_O2/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
leaq -0x170(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0x80(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0x50(%rbp), %rax
andl $0x0, (%rax)
movq %rdx, %rbx
andq $0x0, 0x8(%rax)
movq %rdi, %r14
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
addq $0x70, %rsi
leaq -0xe8(%rbp), %rdi
callq 0x14156
addq $0x70, %rbx
leaq -0xb8(%rbp), %rdi
movq %rbx, %rsi
callq 0x14156
leaq -0x118(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x14156
leaq -0xb0(%rbp), %rbx
movq 0x10(%rbx), %rsi
leaq -0x118(%rbp), %rdi
movq %rbx, %rdx
callq 0x144ac
movq 0x10(%r14), %rdi
leaq -0x118(%rbp), %rsi
leaq -0x178(%rbp), %rdx
callq 0x11646
movq 0x10(%r14), %rdi
leaq -0xe8(%rbp), %rsi
leaq -0x88(%rbp), %rdx
callq 0x11646
movq 0x10(%r14), %rdi
leaq -0xb8(%rbp), %rsi
leaq -0x58(%rbp), %rdx
callq 0x11646
leaq -0xe0(%rbp), %r13
movq 0x10(%r13), %rdi
movq 0x8(%r14), %r15
xorl %r14d, %r14d
pushq $0x48
popq %r12
cmpq %r13, %rdi
je 0x13eea
movq 0x20(%rdi), %rsi
movq 0x78(%r15), %rcx
movq 0x80(%r15), %rax
subq %rcx, %rax
cqto
idivq %r12
cmpq %rsi, %rax
ja 0x13ed1
xorl %ecx, %ecx
jmp 0x13ed8
imulq $0x48, %rsi, %rax
addq %rax, %rcx
movq 0x38(%rcx), %rax
addq 0x50(%rax), %r14
callq 0x43d0
movq %rax, %rdi
jmp 0x13eac
movq -0xa0(%rbp), %rdi
xorl %r13d, %r13d
cmpq %rbx, %rdi
je 0x13f32
movq 0x20(%rdi), %rsi
movq 0x78(%r15), %rcx
movq 0x80(%r15), %rax
subq %rcx, %rax
cqto
idivq %r12
cmpq %rsi, %rax
ja 0x13f19
xorl %ecx, %ecx
jmp 0x13f20
imulq $0x48, %rsi, %rax
addq %rax, %rcx
movq 0x38(%rcx), %rax
addq 0x50(%rax), %r13
callq 0x43d0
movq %rax, %rdi
jmp 0x13ef4
cmpq $0x0, -0x60(%rbp)
je 0x13fa4
cmpq $0x0, -0x30(%rbp)
je 0x13fa4
leaq -0x140(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq -0x70(%rbp), %r15
leaq -0x58(%rbp), %rbx
leaq -0x148(%rbp), %r14
leaq -0x80(%rbp), %r13
cmpq %r13, %r15
je 0x13fb9
leaq 0x20(%r15), %r12
movq %rbx, %rdi
movq %r12, %rsi
callq 0xc044
leaq -0x50(%rbp), %rcx
cmpq %rcx, %rax
je 0x13f97
movq %r14, %rdi
movq %r12, %rsi
callq 0x14602
movq %r15, %rdi
callq 0x4250
movq %rax, %r15
jmp 0x13f6f
movl $0x7a120, %eax          # imm = 0x7A120
cmpq %rax, %r14
setae %cl
cmpq %rax, %r13
setae %bl
andb %cl, %bl
jmp 0x14028
leaq -0x148(%rbp), %rdi
movsd 0x28(%rdi), %xmm0
movsd 0x2193(%rip), %xmm1     # 0x16160
unpcklps %xmm1, %xmm0            # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x2198(%rip), %xmm2     # 0x16170
subpd %xmm2, %xmm0
movapd %xmm0, %xmm3
unpckhpd %xmm0, %xmm3            # xmm3 = xmm3[1],xmm0[1]
addsd %xmm0, %xmm3
movq -0x60(%rbp), %rax
movq -0x30(%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 0x260c(%rip), %xmm0     # 0x16628
ucomisd %xmm3, %xmm0
setbe %bl
callq 0x725c
leaq -0x118(%rbp), %rdi
callq 0x7602
leaq -0xb8(%rbp), %rdi
callq 0x7602
leaq -0xe8(%rbp), %rdi
callq 0x7602
leaq -0x58(%rbp), %rdi
callq 0x7876
leaq -0x88(%rbp), %rdi
callq 0x7876
leaq -0x178(%rbp), %rdi
callq 0x7876
movl %ebx, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x140b2
movq %rax, %rbx
jmp 0x140be
movq %rax, %rbx
jmp 0x140ca
movq %rax, %rbx
jmp 0x140a6
jmp 0x14097
movq %rax, %rbx
leaq -0x148(%rbp), %rdi
callq 0x725c
leaq -0x118(%rbp), %rdi
callq 0x7602
leaq -0xb8(%rbp), %rdi
callq 0x7602
leaq -0xe8(%rbp), %rdi
callq 0x7602
leaq -0x58(%rbp), %rdi
callq 0x7876
leaq -0x88(%rbp), %rdi
callq 0x7876
leaq -0x178(%rbp), %rdi
callq 0x7876
movq %rbx, %rdi
callq 0x4660
nop