// File: /workspace/github_cpp_makefile_star2_O3/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
subq $0x18, %rsp
movq %rdi, %rbx
callq 0x1365ef
movsd %xmm0, 0x8(%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 0x3ab(%rip), %rsi       # 0x1ec577
movq %rbx, %rdx
callq 0x108f2c
movq 0x8(%rbx), %r14
movq 0x80(%rbx), %rax
cmpq $0x0, (%r14)
jne 0x1ec1eb
xorl %ecx, %ecx
xorl %edx, %edx
jmp 0x1ec205
xorl %edx, %edx
xorl %esi, %esi
movq (%rax,%rdx,8), %rcx
addq %rsi, %rcx
movq %rsi, (%rax,%rdx,8)
incq %rdx
movq %rcx, %rsi
cmpq (%r14), %rdx
jb 0x1ec1ef
movq %rcx, (%rax,%rdx,8)
movl %ecx, 0x64(%rbx)
movl %ecx, 0x60(%rbx)
movl %ecx, %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 0x33a(%rip), %rsi       # 0x1ec577
movq %rbx, %rdx
callq 0x108f2c
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, %r12      # imm = 0x100000000
testq %r14, %r14
jne 0x1ec282
xorl %esi, %esi
jmp 0x1ec2e6
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), %esi
addq $0x18, %rcx
addq %r12, %rax
cmpq %rsi, %rdx
jb 0x1ec288
movq 0x90(%rbx), %rax
leaq (%rsi,%rsi,2), %rcx
leaq (%rax,%rcx,8), %rsi
movq %rax, %rdi
callq 0x1a1df3
movl 0x88(%rbx), %esi
testq %rsi, %rsi
jne 0x1ec308
xorl %edi, %edi
jmp 0x1ec40c
movl $0x1, %r13d
xorl %r14d, %r14d
movl %esi, %edx
xorl %ebp, %ebp
xorl %eax, %eax
xorl %ecx, %ecx
cmpq %rsi, %r13
je 0x1ec342
movq 0x90(%rbx), %rsi
leaq (%rcx,%rcx,2), %rdi
movq (%rsi,%rdi,8), %rdi
leaq (,%r13,2), %r8
addq %r13, %r8
cmpq (%rsi,%r8,8), %rdi
je 0x1ec3e1
movq %r13, %r15
subq %rcx, %r15
jbe 0x1ec3ac
movq 0x68(%rbx), %rsi
leaq (,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
movq 0x90(%rbx), %rdi
movq (%rdi,%rdx), %r9
movq 0x8(%rdi,%rdx), %r8
rolq $0x20, %r8
btrq $0x3f, %r8
leaq (%r8,%r8,2), %r8
cmpq (%rsi,%r8,8), %r9
jne 0x1ec558
addq %rdx, %rdi
leaq (%rsi,%r8,8), %rsi
movq 0x10(%rsi), %r9
movq %r9, 0x10(%rdi)
movupd (%rsi), %xmm0
movupd %xmm0, (%rdi)
movq 0x68(%rbx), %rsi
movq %rcx, (%rsi,%r8,8)
incq %rcx
addq $0x18, %rdx
cmpq %rcx, %r13
jne 0x1ec35a
cmpq %rbp, %r14
jne 0x1ec3d1
leaq (%r14,%r14), %rbp
testq %r14, %r14
movl $0x2, %ecx
cmoveq %rcx, %rbp
leaq (,%rbp,8), %rsi
movq %rax, %rdi
callq 0x2370
movq %r15, (%rax,%r14,8)
incq %r14
movl 0x88(%rbx), %edx
movq %r13, %rcx
leaq 0x1(%r13), %rdi
movl %edx, %esi
cmpq %rsi, %r13
movq %rdi, %r13
jb 0x1ec319
leaq 0x10(%rsp), %r15
movq %r14, %rdi
movq %rax, %rsi
movq %rbx, %rdx
movq %r15, %rcx
callq 0x2a684
movq (%r15), %rdi
callq 0x2220
movq %r12, 0xac(%rbx)
movl 0xa8(%rbx), %edi
movq 0x8(%rbx), %rax
movq (%rax), %rcx
leaq 0x14b(%rip), %rsi       # 0x1ec577
movq %rbx, %rdx
callq 0x108f2c
cmpl $0x0, 0xa8(%rbx)
jle 0x1ec49a
xorl %r14d, %r14d
xorl %r15d, %r15d
movq 0x18(%rbx), %rax
movq (%rax,%r15,8), %rdi
callq 0x38b4b
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 0x1ec443
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 0x1ec511
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 0x1ec4dc
movq 0xf0(%rbx), %rdi
callq 0x2220
movq 0xa8abc(%rip), %rax     # 0x294fe0
movq (%rax), %rbx
callq 0x1365ef
subsd 0x8(%rsp), %xmm0
leaq 0x4ff36(%rip), %rsi     # 0x23c46f
leaq 0x588ba(%rip), %rdx     # 0x244dfa
movq %rbx, %rdi
movb $0x1, %al
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x22b0
leaq 0x58583(%rip), %rdi     # 0x244ae2
leaq 0x536f5(%rip), %rsi     # 0x23fc5b
leaq 0x58865(%rip), %rcx     # 0x244dd2
movl $0x5927, %edx           # imm = 0x5927
callq 0x2110