// File: chhylp123[P]hifiasm/inter.cpp
// Function: cal_graph_ovlp_binning(ug_bin_t*)
void cal_graph_ovlp_binning(ug_bin_t *p)
{
	double index_time = yak_realtime();
	// ha_flt_tab = NULL;
	uint64_t i, k, l, occ, m, cc; 
	// p->hre = gen_hpc_re_t(p->ug);
	CALLOC(p->mm, 1); p->mm->n = p->udb.ug->g->n_seq; CALLOC(p->mm->a, p->mm->n);

	// fprintf(stderr, "[M::%s::] ==> 0\n", __func__);
	p->is_cnt = 1; p->is_ovlp = 0; 
	kt_for(p->n_thread, worker_for_graph_bin, p, p->ug->u.n);
	for (i = l = 0; i < p->ug->u.n; i++) {
		occ = p->idx_n.a[i]; p->idx_n.a[i] = l; l += occ;
	}
	// fprintf(stderr, "[M::%s::] i::%lu, l::%lu\n", __func__, i, l);
	p->idx_n.a[i] = l;
	p->idx_a.n = p->idx_a.m = l; MALLOC(p->idx_a.a, p->idx_a.n);
	// fprintf(stderr, "[M::%s::] ==> 1\n", __func__);
	p->is_cnt = 0; p->is_ovlp = 0; 
	kt_for(p->n_thread, worker_for_graph_bin, p, p->ug->u.n);
	p->srt_a.n = p->srt_a.m = p->idx_a.n; MALLOC(p->srt_a.a, p->srt_a.n);
	// fprintf(stderr, "[M::%s::] p->idx_a.n::%lu \n", __func__, (uint64_t)p->idx_a.n);
	// memcpy(p->srt_a.a, p->idx_a.a, p->srt_a.n*sizeof((*(p->srt_a.a))));
	for (i = 0; i < p->srt_a.n; i++) {
		p->srt_a.a[i] = p->idx_a.a[i];
		p->srt_a.a[i].pos = (uint32_t)i;
		p->srt_a.a[i].rid = i>>32;
	}
	radix_sort_ha_mzl_t_srt(p->srt_a.a, p->srt_a.a + p->srt_a.n);
	kvec_t(uint64_t) cut; kv_init(cut);
	for (k = 1, l = 0; k <= p->srt_a.n; k++) {
		if(k == p->srt_a.n || p->srt_a.a[l].x != p->srt_a.a[k].x) {
			for (i = l; i < k; i++) {
				m = p->srt_a.a[i].rid; m <<= 32; m |= p->srt_a.a[i].pos;
				assert(p->srt_a.a[i].x == p->idx_a.a[m].x);
				p->srt_a.a[i] = p->idx_a.a[m]; p->idx_a.a[m].x = i;
			}
			kv_push(uint64_t, cut, (k - l));
			l = k;
		}
	}

	if(cut.n > 0) {
		radix_sort_gfa64(cut.a, cut.a + cut.n);
		m = cut.n * 0.0002; cc = cut.a[cut.n-1] + 1;
		if(m > 0 && m <= cut.n) cc = cut.a[cut.n-m] + 1;
		if(cc < (uint64_t)p->mini_cut) p->mini_cut = cc;
	}
	kv_destroy(cut);
	// fprintf(stderr, "[M::%s::] p->mini_cut::%d \n", __func__, p->mini_cut);
	
	// fprintf(stderr, "[M::%s::] ==> 2\n", __func__);
	p->is_cnt = 0; p->is_ovlp = 1; 
	kt_for(p->n_thread, worker_for_graph_bin, p, p->ug->u.n);
	// fprintf(stderr, "[M::%s::] ==> 3\n", __func__);
	// exit(1);
	for (i = 0; (int64_t)i < p->n_thread; i++) {
		ha_ovec_destroy(p->hab[i]);
		free(p->ll[i].lo.a); free(p->ll[i].srt.a.a); free(p->ll[i].tc.a); free(p->ll[i].tk.a);
	}
	free(p->idx_a.a); free(p->idx_n.a); free(p->hab); free(p->srt_a.a); free(p->ll);
	// fprintf(stderr, "[M::%s::] ==> 4\n", __func__);

	// sysm_graph_bin(p);
	for (i = 0; (int64_t)i < p->n_thread; i++) {
		free(p->mk[i].idx.a); free(p->mk[i].srt.a);
	}
	free(p->mk);
	fprintf(stderr, "[M::%s::%.3f] ==> Qualification\n", __func__, yak_realtime()-index_time);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
callq 0x1b7ca0
movsd %xmm0, -0x10(%rbp)
movl $0x1, %edi
movl $0x10, %esi
callq 0x2140
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xf8(%rax)
movq -0x8(%rbp), %rax
movq 0xc0(%rax), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq -0x8(%rbp), %rax
movq 0xf8(%rax), %rax
movl %ecx, 0x8(%rax)
movq -0x8(%rbp), %rax
movq 0xf8(%rax), %rax
movl 0x8(%rax), %eax
movl %eax, %edi
movl $0x18, %esi
callq 0x2140
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq 0xf8(%rax), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movl $0x1, 0xac(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0xb0(%rax)
movq -0x8(%rbp), %rax
movl 0xa8(%rax), %edi
movq -0x8(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rcx
leaq 0x720(%rip), %rsi       # 0x3096c0
callq 0x16d710
movq $0x0, -0x28(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpq (%rcx), %rax
jae 0x30900e
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movq -0x18(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
addq -0x28(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x308fb5
movq -0x28(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rax
movq -0x18(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x64(%rax)
movq -0x8(%rbp), %rax
movl %ecx, 0x60(%rax)
movq -0x8(%rbp), %rax
movl 0x60(%rax), %eax
imulq $0x18, %rax, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x68(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0xac(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0xb0(%rax)
movq -0x8(%rbp), %rax
movl 0xa8(%rax), %edi
movq -0x8(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rcx
leaq 0x630(%rip), %rsi       # 0x3096c0
callq 0x16d710
movq -0x8(%rbp), %rax
movl 0x60(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x8c(%rax)
movq -0x8(%rbp), %rax
movl %ecx, 0x88(%rax)
movq -0x8(%rbp), %rax
movl 0x88(%rax), %eax
imulq $0x18, %rax, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x90(%rax)
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x88(%rcx), %ecx
cmpq %rcx, %rax
jae 0x3091b2
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rcx
imulq $0x18, -0x18(%rbp), %rax
addq %rax, %rcx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
imulq $0x18, -0x18(%rbp), %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movl %eax, %eax
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
imulq $0x18, -0x18(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movabsq $0xffffffff, %rsi       # imm = 0xFFFFFFFF
andq %rsi, %rdx
shlq $0x20, %rdx
movabsq $0xffffffff, %rsi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rdx
shrq $0x20, %rdx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
imulq $0x18, -0x18(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
andq $0x7fffffff, %rdx       # imm = 0x7FFFFFFF
andq $-0x80000000, %rcx      # imm = 0x80000000
orq %rdx, %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x3090d9
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rsi
movq -0x8(%rbp), %rax
movl 0x88(%rax), %eax
imulq $0x18, %rax, %rax
addq %rax, %rsi
callq 0x282bb0
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x1, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x88(%rcx), %ecx
cmpq %rcx, %rax
ja 0x3093f7
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x88(%rcx), %ecx
cmpq %rcx, %rax
je 0x309262
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
imulq $0x18, -0x28(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x90(%rcx), %rcx
imulq $0x18, -0x20(%rbp), %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
je 0x3093e4
movq -0x28(%rbp), %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpq -0x20(%rbp), %rax
jae 0x309375
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
imulq $0x18, -0x18(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
imulq $0x18, -0x18(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
orq -0x38(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
imulq $0x18, -0x18(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x68(%rcx), %rcx
imulq $0x18, -0x38(%rbp), %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jne 0x3092f5
jmp 0x309314
leaq 0x8c3ba(%rip), %rdi     # 0x3956b6
leaq 0x8752c(%rip), %rsi     # 0x39082f
movl $0x5927, %edx           # imm = 0x5927
leaq 0x8c697(%rip), %rcx     # 0x3959a6
callq 0x2130
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rcx
imulq $0x18, -0x38(%rbp), %rax
addq %rax, %rcx
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rax
imulq $0x18, -0x18(%rbp), %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rax
imulq $0x18, -0x38(%rbp), %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x30926a
jmp 0x309377
movq -0x58(%rbp), %rax
cmpq -0x50(%rbp), %rax
jne 0x3093bd
cmpq $0x0, -0x50(%rbp)
je 0x309395
movq -0x50(%rbp), %rax
shlq %rax
movq %rax, -0x60(%rbp)
jmp 0x3093a0
movl $0x2, %eax
movq %rax, -0x60(%rbp)
jmp 0x3093a0
movq -0x60(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, -0x48(%rbp)
movq -0x20(%rbp), %rdx
subq -0x28(%rbp), %rdx
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x58(%rbp)
movq %rdx, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x3093e6
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x309206
cmpq $0x0, -0x58(%rbp)
jbe 0x3094d7
movq -0x58(%rbp), %rax
movq -0x48(%rbp), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x27a9b0
movaps 0x78bf6(%rip), %xmm1    # 0x382010
movq -0x58(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x78bf5(%rip), %xmm1    # 0x382020
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x87326(%rip), %xmm1    # 0x390768
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x78b9b(%rip), %xmm1    # 0x381ff8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x38(%rbp)
jbe 0x3094b1
movq -0x38(%rbp), %rax
cmpq -0x58(%rbp), %rax
ja 0x3094b1
movq -0x48(%rbp), %rax
movq -0x58(%rbp), %rcx
subq -0x38(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0xb4(%rcx), %rcx
cmpq %rcx, %rax
jae 0x3094d5
movq -0x40(%rbp), %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xb4(%rax)
jmp 0x3094d7
movq -0x48(%rbp), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movl $0x0, 0xac(%rax)
movq -0x8(%rbp), %rax
movl $0x1, 0xb0(%rax)
movq -0x8(%rbp), %rax
movl 0xa8(%rax), %edi
movq -0x8(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rcx
leaq 0x1a4(%rip), %rsi       # 0x3096c0
callq 0x16d710
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0xa8(%rcx), %rcx
cmpq %rcx, %rax
jge 0x3095ca
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x14f00
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x68, -0x18(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x68, -0x18(%rbp), %rcx
addq %rcx, %rax
movq 0x58(%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x68, -0x18(%rbp), %rcx
addq %rcx, %rax
movq 0x30(%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x68, -0x18(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rdi
callq 0x2210
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x309529
movq -0x8(%rbp), %rax
movq 0x68(%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq 0x80(%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq 0x90(%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2210
movq $0x0, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0xa8(%rcx), %rcx
cmpq %rcx, %rax
jge 0x309673
movq -0x8(%rbp), %rax
movq 0xf0(%rax), %rax
imulq $0x30, -0x18(%rbp), %rcx
addq %rcx, %rax
movq 0x10(%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq 0xf0(%rax), %rax
imulq $0x30, -0x18(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rdi
callq 0x2210
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
jmp 0x309619
movq -0x8(%rbp), %rax
movq 0xf0(%rax), %rdi
callq 0x2210
movq 0xba956(%rip), %rax     # 0x3c3fe0
movq (%rax), %rax
movq %rax, -0x68(%rbp)
callq 0x1b7ca0
movq -0x68(%rbp), %rdi
subsd -0x10(%rbp), %xmm0
leaq 0x83a2a(%rip), %rsi     # 0x38d0d0
leaq 0x8c321(%rip), %rdx     # 0x3959ce
movb $0x1, %al
callq 0x22a0
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)