// File: /workspace/github_cpp_makefile_star2_O1/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 0x1303c7
movsd %xmm0, (%rsp)
movl $0x1, %edi
movl $0x10, %esi
callq 0x2120
movq %rax, %r14
movq %rax, 0xf8(%rbx)
movq 0xc0(%rbx), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %edi
andl $0x7fffffff, %edi       # imm = 0x7FFFFFFF
movl %edi, 0x8(%r14)
movl $0x18, %esi
callq 0x2120
movq %rax, (%r14)
movq $0x1, 0xac(%rbx)
movl 0xa8(%rbx), %edi
movq 0x8(%rbx), %rax
movq (%rax), %rcx
leaq 0x435(%rip), %rsi       # 0x1e1abb
movq %rbx, %rdx
callq 0x1047b4
movq 0x8(%rbx), %r14
cmpq $0x0, (%r14)
jne 0x1e169e
xorl %eax, %eax
xorl %ecx, %ecx
jmp 0x1e16bf
movq 0x80(%rbx), %rdx
xorl %ecx, %ecx
xorl %esi, %esi
movq (%rdx,%rcx,8), %rax
addq %rsi, %rax
movq %rsi, (%rdx,%rcx,8)
incq %rcx
movq %rax, %rsi
cmpq (%r14), %rcx
jb 0x1e16a9
movq 0x80(%rbx), %rdx
movq %rax, (%rdx,%rcx,8)
movl %eax, 0x64(%rbx)
movl %eax, 0x60(%rbx)
movl %eax, %eax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rdi
callq 0x2280
movq %rax, 0x68(%rbx)
movq $0x0, 0xac(%rbx)
movl 0xa8(%rbx), %edi
movq (%r14), %rcx
leaq 0x3bd(%rip), %rsi       # 0x1e1abb
movq %rbx, %rdx
callq 0x1047b4
movl 0x60(%rbx), %r14d
movl %r14d, 0x8c(%rbx)
movl %r14d, 0x88(%rbx)
leaq (,%r14,8), %rax
leaq (%rax,%rax,2), %rdi
callq 0x2280
movq %rax, 0x90(%rbx)
movabsq $0x100000000, %r9       # imm = 0x100000000
testq %r14, %r14
je 0x1e179d
xorl %eax, %eax
xorl %ecx, %ecx
xorl %edx, %edx
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), %r14d
addq $0x18, %rcx
addq %r9, %rax
cmpq %r14, %rdx
jb 0x1e1745
movq 0x90(%rbx), %rdi
leaq (%r14,%r14,2), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x19910c
movl 0x88(%rbx), %edx
xorl %r14d, %r14d
movl $0x0, %r12d
testq %rdx, %rdx
je 0x1e18b6
movl $0x1, %ebp
xorl %r12d, %r12d
xorl %eax, %eax
xorl %r14d, %r14d
xorl %ecx, %ecx
cmpq %rdx, %rbp
je 0x1e1801
movq 0x90(%rbx), %rdx
leaq (%rcx,%rcx,2), %rsi
movq (%rdx,%rsi,8), %rsi
leaq (,%rbp,2), %rdi
addq %rbp, %rdi
cmpq (%rdx,%rdi,8), %rsi
je 0x1e18a0
movq %rbp, %r13
subq %rcx, %r13
jbe 0x1e186b
leaq (,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
movq 0x68(%rbx), %rdi
movq 0x90(%rbx), %rsi
movq (%rsi,%rdx), %r9
movq 0x8(%rsi,%rdx), %r8
rolq $0x20, %r8
btrq $0x3f, %r8
leaq (%r8,%r8,2), %r8
cmpq (%rdi,%r8,8), %r9
jne 0x1e1a9c
addq %rdx, %rsi
leaq (%rdi,%r8,8), %rdi
movq 0x10(%rdi), %r9
movq %r9, 0x10(%rsi)
movupd (%rdi), %xmm0
movupd %xmm0, (%rsi)
movq 0x68(%rbx), %rsi
movq %rcx, (%rsi,%r8,8)
incq %rcx
addq $0x18, %rdx
cmpq %rcx, %rbp
jne 0x1e1815
cmpq %rax, %r12
jne 0x1e1896
leaq (%rax,%rax), %r15
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %r15
leaq (,%r15,8), %rsi
movq %r14, %rdi
callq 0x2370
movq %rax, %r14
movq %r15, %rax
movq %r13, (%r14,%r12,8)
incq %r12
movq %rbp, %rcx
leaq 0x1(%rbp), %rsi
movl 0x88(%rbx), %edx
cmpq %rdx, %rbp
movq %rsi, %rbp
jb 0x1e17d8
testq %r12, %r12
je 0x1e1944
leaq (%r14,%r12,8), %rsi
movq %r14, %rdi
callq 0x194fef
movq %r12, %xmm0
punpckldq 0x43968(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x43970(%rip), %xmm0    # 0x225250
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x51fcc(%rip), %xmm1    # 0x2338c0
cvttsd2si %xmm1, %rax
movq %rax, %rcx
subsd 0x43964(%rip), %xmm1    # 0x225268
sarq $0x3f, %rcx
cvttsd2si %xmm1, %rdx
andq %rcx, %rdx
orq %rax, %rdx
leaq -0x1(%rdx), %rax
negq %rdx
cmpq %r12, %rax
movq $-0x1, %rax
cmovbq %rdx, %rax
addq %r12, %rax
movq (%r14,%rax,8), %rax
incq %rax
movslq 0xb4(%rbx), %rcx
cmpq %rcx, %rax
jae 0x1e1944
movl %eax, 0xb4(%rbx)
movq %r14, %rdi
callq 0x2220
movabsq $0x100000000, %rax      # imm = 0x100000000
movq %rax, 0xac(%rbx)
movl 0xa8(%rbx), %edi
movq 0x8(%rbx), %rax
movq (%rax), %rcx
leaq 0x14a(%rip), %rsi       # 0x1e1abb
movq %rbx, %rdx
callq 0x1047b4
cmpl $0x0, 0xa8(%rbx)
jle 0x1e19df
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x18(%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x395cd
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
movslq 0xa8(%rbx), %rax
addq $0x68, %r14
cmpq %rax, %r15
jl 0x1e1988
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
cmpl $0x0, 0xa8(%rbx)
jle 0x1e1a56
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0xf0(%rbx), %rax
movq 0x10(%rax,%r14), %rdi
callq 0x2220
movq 0xf0(%rbx), %rax
movq 0x18(%rax,%r14), %rdi
callq 0x2220
incq %r15
movslq 0xa8(%rbx), %rax
addq $0x30, %r14
cmpq %rax, %r15
jl 0x1e1a21
movq 0xf0(%rbx), %rdi
callq 0x2220
movq 0xa8577(%rip), %rax     # 0x289fe0
movq (%rax), %rbx
callq 0x1303c7
subsd (%rsp), %xmm0
leaq 0x4e7e6(%rip), %rsi     # 0x230263
leaq 0x570a6(%rip), %rdx     # 0x238b2a
movq %rbx, %rdi
movb $0x1, %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22b0
leaq 0x56d6f(%rip), %rdi     # 0x238812
leaq 0x51ee1(%rip), %rsi     # 0x23398b
leaq 0x57051(%rip), %rcx     # 0x238b02
movl $0x5927, %edx           # imm = 0x5927
callq 0x2110