// File: 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
subq $0x2a0, %rsp            # imm = 0x2A0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x220(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x13dc0
leaq -0x80(%rbp), %rdi
callq 0x13dc0
leaq -0xb0(%rbp), %rdi
callq 0x13dc0
movq $0x0, -0xb8(%rbp)
movq $0x0, -0xc0(%rbp)
movq -0x18(%rbp), %rdi
callq 0xa460
movq %rax, -0x218(%rbp)
jmp 0x32c48
movq -0x218(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x335b0
jmp 0x32c5d
movq -0x20(%rbp), %rdi
callq 0xa460
movq %rax, -0x228(%rbp)
jmp 0x32c6f
movq -0x228(%rbp), %rsi
leaq -0x130(%rbp), %rdi
callq 0x335b0
jmp 0x32c84
leaq -0x160(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x335b0
jmp 0x32c99
leaq -0x130(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0xa8e0
movq -0x230(%rbp), %rdi
movq %rax, -0x168(%rbp)
callq 0xa910
movq %rax, -0x170(%rbp)
movq -0x168(%rbp), %rsi
movq -0x170(%rbp), %rdx
leaq -0x160(%rbp), %rdi
callq 0x335e0
jmp 0x32ce2
movq -0x220(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x160(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x2bde0
jmp 0x32cff
movq -0x220(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0xf0(%rbp), %rsi
leaq -0x80(%rbp), %rdx
callq 0x2bde0
jmp 0x32d1c
movq -0x220(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x130(%rbp), %rsi
leaq -0xb0(%rbp), %rdx
callq 0x2bde0
jmp 0x32d3c
leaq -0xf0(%rbp), %rdi
callq 0xa8e0
movq %rax, -0x178(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0xa910
movq %rax, -0x180(%rbp)
leaq -0x178(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0xa3a0
testb $0x1, %al
jne 0x32d7e
jmp 0x32e54
movq -0x220(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x240(%rbp)
leaq -0x178(%rbp), %rdi
callq 0xa400
movq -0x240(%rbp), %rdi
movq (%rax), %rsi
callq 0xa940
movq %rax, -0x238(%rbp)
jmp 0x32db4
movq -0x238(%rbp), %rdi
callq 0x33620
movq %rax, -0x248(%rbp)
jmp 0x32dc9
movq -0x248(%rbp), %rax
addq -0xb8(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0x178(%rbp), %rdi
xorl %esi, %esi
callq 0xa420
movq %rax, -0x188(%rbp)
jmp 0x32d4f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x3320d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x33201
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x331f5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
jmp 0x331e9
leaq -0x130(%rbp), %rdi
callq 0xa8e0
movq %rax, -0x190(%rbp)
leaq -0x130(%rbp), %rdi
callq 0xa910
movq %rax, -0x198(%rbp)
leaq -0x190(%rbp), %rdi
leaq -0x198(%rbp), %rsi
callq 0xa3a0
testb $0x1, %al
jne 0x32e93
jmp 0x32f0d
movq -0x220(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x258(%rbp)
leaq -0x190(%rbp), %rdi
callq 0xa400
movq -0x258(%rbp), %rdi
movq (%rax), %rsi
callq 0xa940
movq %rax, -0x250(%rbp)
jmp 0x32ec9
movq -0x250(%rbp), %rdi
callq 0x33620
movq %rax, -0x260(%rbp)
jmp 0x32ede
movq -0x260(%rbp), %rax
addq -0xc0(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0x190(%rbp), %rdi
xorl %esi, %esi
callq 0xa420
movq %rax, -0x1a0(%rbp)
jmp 0x32e67
leaq -0x80(%rbp), %rdi
callq 0x144b0
cmpq $0x0, %rax
je 0x32f2e
leaq -0xb0(%rbp), %rdi
callq 0x144b0
cmpq $0x0, %rax
jne 0x32f71
xorl %eax, %eax
cmpq $0x7a120, -0xb8(%rbp) # imm = 0x7A120
movb %al, -0x261(%rbp)
jb 0x32f57
cmpq $0x7a120, -0xc0(%rbp) # imm = 0x7A120
setae %al
movb %al, -0x261(%rbp)
movb -0x261(%rbp), %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movl $0x1, -0x1a4(%rbp)
jmp 0x33199
leaq -0x1d8(%rbp), %rdi
callq 0x2ca50
leaq -0x80(%rbp), %rdi
callq 0x33650
movq %rax, -0x1e0(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x151c0
movq %rax, -0x1e8(%rbp)
leaq -0x1e0(%rbp), %rdi
leaq -0x1e8(%rbp), %rsi
callq 0x15190
testb $0x1, %al
jne 0x32fb9
jmp 0x3309c
leaq -0x1e0(%rbp), %rdi
callq 0x151f0
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x150b0
movq %rax, -0x270(%rbp)
jmp 0x32fdd
movq -0x270(%rbp), %rax
movq %rax, -0x1f0(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x151c0
movq %rax, -0x1f8(%rbp)
leaq -0x1f0(%rbp), %rdi
leaq -0x1f8(%rbp), %rsi
callq 0x15190
testb $0x1, %al
jne 0x33017
jmp 0x33080
leaq -0x1e0(%rbp), %rdi
callq 0x151f0
movq %rax, %rsi
leaq -0x1d8(%rbp), %rdi
callq 0x33680
movb %dl, -0x279(%rbp)
movq %rax, -0x278(%rbp)
jmp 0x33041
movb -0x279(%rbp), %al
movq -0x278(%rbp), %rcx
movq %rcx, -0x208(%rbp)
movb %al, -0x200(%rbp)
jmp 0x33080
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xf8(%rbp)
movl %eax, -0xfc(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0xb300
jmp 0x331e9
jmp 0x33082
leaq -0x1e0(%rbp), %rdi
xorl %esi, %esi
callq 0x336d0
movq %rax, -0x210(%rbp)
jmp 0x32f8d
leaq -0x1d8(%rbp), %rdi
callq 0x2cbc0
movq %rax, %xmm0
movaps 0x30cc(%rip), %xmm1     # 0x36180
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x30d0(%rip), %xmm1     # 0x36190
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0x290(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x144b0
movq %rax, -0x288(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x144b0
movq %rax, %rcx
movq -0x288(%rbp), %rax
cmpq %rcx, %rax
jae 0x33114
leaq -0x80(%rbp), %rdi
callq 0x144b0
movq %rax, -0x298(%rbp)
jmp 0x33127
leaq -0xb0(%rbp), %rdi
callq 0x144b0
movq %rax, -0x298(%rbp)
movsd -0x290(%rbp), %xmm1
movq -0x298(%rbp), %rax
movq %rax, %xmm0
movaps 0x303e(%rip), %xmm2     # 0x36180
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x3042(%rip), %xmm2     # 0x36190
subpd %xmm2, %xmm0
movaps %xmm0, %xmm2
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm2, %xmm0
divsd %xmm0, %xmm1
movsd 0x3637(%rip), %xmm0     # 0x367a0
ucomisd %xmm1, %xmm0
jbe 0x3317f
movb $0x0, -0x1(%rbp)
movl $0x1, -0x1a4(%rbp)
jmp 0x3318d
movb $0x1, -0x1(%rbp)
movl $0x1, -0x1a4(%rbp)
leaq -0x1d8(%rbp), %rdi
callq 0xb300
leaq -0x160(%rbp), %rdi
callq 0xc190
leaq -0x130(%rbp), %rdi
callq 0xc190
leaq -0xf0(%rbp), %rdi
callq 0xc190
leaq -0xb0(%rbp), %rdi
callq 0xd250
leaq -0x80(%rbp), %rdi
callq 0xd250
leaq -0x50(%rbp), %rdi
callq 0xd250
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x2a0, %rsp            # imm = 0x2A0
popq %rbp
retq
leaq -0x160(%rbp), %rdi
callq 0xc190
leaq -0x130(%rbp), %rdi
callq 0xc190
leaq -0xf0(%rbp), %rdi
callq 0xc190
leaq -0xb0(%rbp), %rdi
callq 0xd250
leaq -0x80(%rbp), %rdi
callq 0xd250
leaq -0x50(%rbp), %rdi
callq 0xd250
movq -0xf8(%rbp), %rdi
callq 0x5750
nopw (%rax,%rax)