// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
callq 0xefea7
movsd %xmm0, (%rsp)
pushq $0x1
popq %r14
pushq $0x10
popq %rsi
movq %r14, %rdi
callq 0x2120
movq %rax, %r15
movq %rax, 0xf8(%rbx)
movq 0xc0(%rbx), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl %edi, 0x8(%r15)
pushq $0x18
popq %rsi
callq 0x2120
movq %rax, (%r15)
movq $0x1, 0xac(%rbx)
movl 0xa8(%rbx), %edi
movq 0x8(%rbx), %rax
movq (%rax), %rcx
leaq 0x3cd(%rip), %rsi       # 0x1a134b
movq %rbx, %rdx
callq 0xc67c0
movq 0x8(%rbx), %r15
movq 0x80(%rbx), %rax
xorl %ecx, %ecx
xorl %edx, %edx
cmpq (%r15), %rdx
jae 0x1a0fad
movq (%rax,%rdx,8), %rsi
addq %rcx, %rsi
movq %rcx, (%rax,%rdx,8)
incq %rdx
movq %rsi, %rcx
jmp 0x1a0f95
movq %rcx, (%rax,%rdx,8)
movl %ecx, 0x64(%rbx)
movl %ecx, 0x60(%rbx)
movl %ecx, %eax
imulq $0x18, %rax, %rdi
callq 0x2280
movq %rax, 0x68(%rbx)
andq $0x0, 0xac(%rbx)
movl 0xa8(%rbx), %edi
movq (%r15), %rcx
leaq 0x36d(%rip), %rsi       # 0x1a134b
movq %rbx, %rdx
callq 0xc67c0
movl 0x60(%rbx), %r15d
movl %r15d, 0x8c(%rbx)
movl %r15d, 0x88(%rbx)
imulq $0x18, %r15, %rdi
callq 0x2280
movq %rax, 0x90(%rbx)
xorl %eax, %eax
movabsq $0x100000000, %r9       # imm = 0x100000000
xorl %ecx, %ecx
xorl %edx, %edx
movl %r15d, %esi
cmpq %rsi, %rdx
jae 0x1a1075
movq 0x68(%rbx), %rsi
movq 0x90(%rbx), %rdi
movq 0x10(%rsi,%rcx), %r8
movq %r8, 0x10(%rdi,%rcx)
movupd (%rsi,%rcx), %xmm0
movupd %xmm0, (%rdi,%rcx)
movq 0x90(%rbx), %rsi
movl 0x8(%rsi,%rcx), %edi
addq %rax, %rdi
movq %rdi, 0x8(%rsi,%rcx)
movq 0x90(%rbx), %rsi
andq $-0x80000000, 0x8(%rsi,%rcx) # imm = 0x80000000
incq %rdx
movl 0x88(%rbx), %r15d
addq $0x18, %rcx
addq %r9, %rax
jmp 0x1a1018
movq 0x90(%rbx), %rdi
imulq $0x18, %rsi, %rsi
addq %rdi, %rsi
callq 0x15a8b9
xorl %ebp, %ebp
xorl %r15d, %r15d
xorl %eax, %eax
xorl %r13d, %r13d
movl 0x88(%rbx), %ecx
cmpq %rcx, %r14
ja 0x1a115f
je 0x1a10c0
movq 0x90(%rbx), %rcx
imulq $0x18, %rbp, %rdx
movq (%rcx,%rdx), %rdx
imulq $0x18, %r14, %rsi
cmpq (%rcx,%rsi), %rdx
je 0x1a1157
imulq $0x18, %rbp, %rcx
movq %rbp, %rdx
cmpq %r14, %rdx
jae 0x1a111e
movq 0x68(%rbx), %rdi
movq 0x90(%rbx), %rsi
movq (%rsi,%rcx), %r9
movq 0x8(%rsi,%rcx), %r8
rolq $0x20, %r8
btrq $0x3f, %r8
imulq $0x18, %r8, %r8
cmpq (%rdi,%r8), %r9
jne 0x1a132c
addq %rcx, %rsi
addq %r8, %rdi
movq 0x10(%rdi), %r9
movq %r9, 0x10(%rsi)
movupd (%rdi), %xmm0
movupd %xmm0, (%rsi)
movq 0x68(%rbx), %rsi
movq %rdx, (%rsi,%r8)
incq %rdx
addq $0x18, %rcx
jmp 0x1a10c7
cmpq %rax, %r13
jne 0x1a1147
leaq (%rax,%rax), %r12
testq %rax, %rax
pushq $0x2
popq %rax
cmoveq %rax, %r12
leaq (,%r12,8), %rsi
movq %r15, %rdi
callq 0x2370
movq %rax, %r15
movq %r12, %rax
movq %r14, %rcx
subq %rbp, %rcx
movq %rcx, (%r15,%r13,8)
incq %r13
movq %r14, %rbp
incq %r14
jmp 0x1a1092
testq %r13, %r13
je 0x1a11e9
leaq (%r15,%r13,8), %rsi
movq %r15, %rdi
callq 0x156b0d
movq %r13, %xmm0
punpckldq 0x420ef(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x420f7(%rip), %xmm0    # 0x1e3280
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x508c3(%rip), %xmm1    # 0x1f1a60
cvttsd2si %xmm1, %rax
movq %rax, %rcx
subsd 0x420eb(%rip), %xmm1    # 0x1e3298
sarq $0x3f, %rcx
cvttsd2si %xmm1, %rdx
andq %rcx, %rdx
orq %rax, %rdx
leaq -0x1(%rdx), %rax
negq %rdx
cmpq %r13, %rax
pushq $-0x1
popq %rax
cmovbq %rdx, %rax
addq %r13, %rax
movq (%r15,%rax,8), %rax
incq %rax
movslq 0xb4(%rbx), %rcx
cmpq %rcx, %rax
jae 0x1a11e9
movl %eax, 0xb4(%rbx)
movq %r15, %rdi
callq 0x2220
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0xac(%rbx)
movl 0xa8(%rbx), %edi
movq 0x8(%rbx), %rax
movq (%rax), %rcx
leaq 0x135(%rip), %rsi       # 0x1a134b
movq %rbx, %rdx
callq 0xc67c0
xorl %r14d, %r14d
xorl %r15d, %r15d
movslq 0xa8(%rbx), %rax
cmpq %rax, %r15
jge 0x1a127d
movq 0x18(%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0xc5d1
movq 0x20(%rbx), %rax
movq (%rax,%r14), %rdi
callq 0x2220
movq 0x20(%rbx), %rax
movq 0x58(%rax,%r14), %rdi
callq 0x2220
movq 0x20(%rbx), %rax
movq 0x30(%rax,%r14), %rdi
callq 0x2220
movq 0x20(%rbx), %rax
movq 0x18(%rax,%r14), %rdi
callq 0x2220
incq %r15
addq $0x68, %r14
jmp 0x1a1224
movq 0x68(%rbx), %rdi
callq 0x2220
movq 0x80(%rbx), %rdi
callq 0x2220
movq 0x18(%rbx), %rdi
callq 0x2220
movq 0x90(%rbx), %rdi
callq 0x2220
movq 0x20(%rbx), %rdi
callq 0x2220
xorl %r14d, %r14d
xorl %r15d, %r15d
movslq 0xa8(%rbx), %rax
movq 0xf0(%rbx), %rdi
cmpq %rax, %r15
jge 0x1a12ed
movq 0x10(%rdi,%r14), %rdi
callq 0x2220
movq 0xf0(%rbx), %rax
movq 0x18(%rax,%r14), %rdi
callq 0x2220
incq %r15
addq $0x30, %r14
jmp 0x1a12b6
callq 0x2220
movq 0xb1ce7(%rip), %rax     # 0x252fe0
movq (%rax), %rbx
callq 0xefea7
subsd (%rsp), %xmm0
leaq 0x4d052(%rip), %rsi     # 0x1ee35f
leaq 0x559ae(%rip), %rdx     # 0x1f6cc2
movq %rbx, %rdi
movb $0x1, %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22b0
leaq 0x55677(%rip), %rdi     # 0x1f69aa
leaq 0x507e9(%rip), %rsi     # 0x1f1b23
leaq 0x55959(%rip), %rcx     # 0x1f6c9a
movl $0x5927, %edx           # imm = 0x5927
callq 0x2110