// File: chhylp123[P]hifiasm/inter.cpp
// Function: gen_trans_base_count_mmhap_comp_rmap(ug_trans_t*, kv_u_trans_t*)
void gen_trans_base_count_mmhap_comp_rmap(ug_trans_t *p, kv_u_trans_t *res)
{
	double index_time = yak_realtime();
	uint64_t i, k, l, occ, m, cc; 
	p->ccov = gen_ug_rid_cov_t(p->ug, p->rg, p->uopt->sources);
	clean_u_trans_t_idx_adv(res, p->ug, p->rg); p->filter = res;

	p->is_cnt = 1; p->is_ovlp = 0; 
	memset(p->free_cnt, 0, sizeof((*(p->free_cnt)))*p->n_thread);
	kt_for(p->n_thread, worker_for_trans_ovlp_mmhap_adv, 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;
	}

	p->idx_n.a[i] = l;
	p->idx_a.n = p->idx_a.m = l; MALLOC(p->idx_a.a, p->idx_a.n);
	p->is_cnt = 0; p->is_ovlp = 0; 
	memset(p->free_cnt, 0, sizeof((*(p->free_cnt)))*p->n_thread);
	kt_for(p->n_thread, worker_for_trans_ovlp_mmhap_adv, 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);
	
	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);
	
	p->is_cnt = 0; p->is_ovlp = 1; 
	memset(p->free_cnt, 0, sizeof((*(p->free_cnt)))*p->n_thread);
	kt_for(p->n_thread, worker_for_trans_ovlp_mmhap_adv, p, p->ug->u.n);

	clean_trans_base_count_mmhap_comp_rmap(p, res);

	for (i = 0; (int64_t)i < p->n_thread; i++) p->ll[i].tk.n = 0;

	p->is_cnt = 0; p->is_ovlp = 1; 
	memset(p->free_cnt, 0, sizeof((*(p->free_cnt)))*p->n_thread);
	kt_for(p->n_thread, worker_for_trans_chain_mmhap_adv, p, p->ug->u.n);





	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->idx_a.a); free(p->idx_n.a); free(p->hab); free(p->free_cnt);
	destory_ug_rid_cov_t(p->ccov); free(p->ccov);






	



	for (i = 0; (int64_t)i < p->n_thread; i++) free(p->ll[i].tk.a);
	free(p->srt_a.a); free(p->ll);
	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)
movq %rsi, -0x10(%rbp)
callq 0x1b7ca0
movsd %xmm0, -0x18(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq 0x8(%rax), %rdx
callq 0x107f90
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x108(%rax)
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rdx
callq 0x103c60
movq -0x10(%rbp), %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0xf8(%rax)
movq -0x8(%rbp), %rax
movl $0x1, 0xb4(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0xb8(%rax)
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rdi
movq -0x8(%rbp), %rax
movslq 0xb0(%rax), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x2100
movq -0x8(%rbp), %rax
movl 0xb0(%rax), %edi
movq -0x8(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rcx
leaq 0x7f3(%rip), %rsi       # 0x305aa0
callq 0x16d710
movq $0x0, -0x30(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
cmpq (%rcx), %rax
jae 0x30531b
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x30(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x20(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x38(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x3052c2
movq -0x30(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rax
movq -0x20(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x6c(%rax)
movq -0x8(%rbp), %rax
movl %ecx, 0x68(%rax)
movq -0x8(%rbp), %rax
movl 0x68(%rax), %eax
imulq $0x18, %rax, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0xb4(%rax)
movq -0x8(%rbp), %rax
movl $0x0, 0xb8(%rax)
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rdi
movq -0x8(%rbp), %rax
movslq 0xb0(%rax), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x2100
movq -0x8(%rbp), %rax
movl 0xb0(%rax), %edi
movq -0x8(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rcx
leaq 0x6e2(%rip), %rsi       # 0x305aa0
callq 0x16d710
movq -0x8(%rbp), %rax
movl 0x68(%rax), %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0x94(%rax)
movq -0x8(%rbp), %rax
movl %ecx, 0x90(%rax)
movq -0x8(%rbp), %rax
movl 0x90(%rax), %eax
imulq $0x18, %rax, %rdi
callq 0x2270
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, 0x98(%rax)
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x90(%rcx), %ecx
cmpq %rcx, %rax
jae 0x3054e0
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rcx
imulq $0x18, -0x20(%rbp), %rax
addq %rax, %rcx
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
imulq $0x18, -0x20(%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 -0x20(%rbp), %rax
movl %eax, %eax
movl %eax, %edx
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
imulq $0x18, -0x20(%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 -0x20(%rbp), %rdx
shrq $0x20, %rdx
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
imulq $0x18, -0x20(%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 -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x305407
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rdi
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rsi
movq -0x8(%rbp), %rax
movl 0x90(%rax), %eax
imulq $0x18, %rax, %rax
addq %rax, %rsi
callq 0x282bb0
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x1, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x90(%rcx), %ecx
cmpq %rcx, %rax
ja 0x305725
movq -0x28(%rbp), %rax
movq -0x8(%rbp), %rcx
movl 0x90(%rcx), %ecx
cmpq %rcx, %rax
je 0x305590
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
imulq $0x18, -0x30(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x98(%rcx), %rcx
imulq $0x18, -0x28(%rbp), %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
je 0x305712
movq -0x30(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq -0x28(%rbp), %rax
jae 0x3056a3
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
imulq $0x18, -0x20(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
andq $0x7fffffff, %rax       # imm = 0x7FFFFFFF
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
shlq $0x20, %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
imulq $0x18, -0x20(%rbp), %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x20, %rax
orq -0x40(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
imulq $0x18, -0x20(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x70(%rcx), %rcx
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jne 0x305623
jmp 0x305642
leaq 0x9008c(%rip), %rdi     # 0x3956b6
leaq 0x8b1fe(%rip), %rsi     # 0x39082f
movl $0x5777, %edx           # imm = 0x5777
leaq 0x901f0(%rip), %rcx     # 0x39582d
callq 0x2130
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rcx
imulq $0x18, -0x40(%rbp), %rax
addq %rax, %rcx
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rax
imulq $0x18, -0x20(%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 -0x20(%rbp), %rcx
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rax
imulq $0x18, -0x40(%rbp), %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x305598
jmp 0x3056a5
movq -0x60(%rbp), %rax
cmpq -0x58(%rbp), %rax
jne 0x3056eb
cmpq $0x0, -0x58(%rbp)
je 0x3056c3
movq -0x58(%rbp), %rax
shlq %rax
movq %rax, -0x68(%rbp)
jmp 0x3056ce
movl $0x2, %eax
movq %rax, -0x68(%rbp)
jmp 0x3056ce
movq -0x68(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rdi
movq -0x58(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rdx
subq -0x30(%rbp), %rdx
movq -0x50(%rbp), %rax
movq -0x60(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x60(%rbp)
movq %rdx, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
jmp 0x305714
movq -0x28(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x28(%rbp)
jmp 0x305534
cmpq $0x0, -0x60(%rbp)
jbe 0x305805
movq -0x60(%rbp), %rax
movq -0x50(%rbp), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x27a9b0
movaps 0x7c8c8(%rip), %xmm1    # 0x382010
movq -0x60(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x7c8c7(%rip), %xmm1    # 0x382020
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x8aff8(%rip), %xmm1    # 0x390768
mulsd %xmm1, %xmm0
movaps %xmm0, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, %rdx
sarq $0x3f, %rdx
movsd 0x7c86d(%rip), %xmm1    # 0x381ff8
subsd %xmm1, %xmm0
cvttsd2si %xmm0, %rcx
andq %rdx, %rcx
orq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x50(%rbp), %rax
movq -0x60(%rbp), %rcx
subq $0x1, %rcx
movq (%rax,%rcx,8), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x40(%rbp)
jbe 0x3057df
movq -0x40(%rbp), %rax
cmpq -0x60(%rbp), %rax
ja 0x3057df
movq -0x50(%rbp), %rax
movq -0x60(%rbp), %rcx
subq -0x40(%rbp), %rcx
movq (%rax,%rcx,8), %rax
addq $0x1, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0xbc(%rcx), %rcx
cmpq %rcx, %rax
jae 0x305803
movq -0x48(%rbp), %rax
movl %eax, %ecx
movq -0x8(%rbp), %rax
movl %ecx, 0xbc(%rax)
jmp 0x305805
movq -0x50(%rbp), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movl $0x0, 0xb4(%rax)
movq -0x8(%rbp), %rax
movl $0x1, 0xb8(%rax)
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rdi
movq -0x8(%rbp), %rax
movslq 0xb0(%rax), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x2100
movq -0x8(%rbp), %rax
movl 0xb0(%rax), %edi
movq -0x8(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rcx
leaq 0x235(%rip), %rsi       # 0x305aa0
callq 0x16d710
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x304990
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0xb0(%rcx), %rcx
cmpq %rcx, %rax
jge 0x3058bf
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x68, -0x20(%rbp), %rcx
addq %rcx, %rax
movq $0x0, 0x20(%rax)
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x305885
movq -0x8(%rbp), %rax
movl $0x0, 0xb4(%rax)
movq -0x8(%rbp), %rax
movl $0x1, 0xb8(%rax)
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rdi
movq -0x8(%rbp), %rax
movslq 0xb0(%rax), %rdx
shlq $0x2, %rdx
xorl %esi, %esi
callq 0x2100
movq -0x8(%rbp), %rax
movl 0xb0(%rax), %edi
movq -0x8(%rbp), %rdx
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rcx
leaq 0x7c4(%rip), %rsi       # 0x3060e0
callq 0x16d710
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0xb0(%rcx), %rcx
cmpq %rcx, %rax
jge 0x3059ad
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x20(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x14f00
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x68, -0x20(%rbp), %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x68, -0x20(%rbp), %rcx
addq %rcx, %rax
movq 0x58(%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x68, -0x20(%rbp), %rcx
addq %rcx, %rax
movq 0x30(%rax), %rdi
callq 0x2210
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x305929
movq -0x8(%rbp), %rax
movq 0x70(%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq 0x88(%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq 0x100(%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq 0x108(%rax), %rdi
callq 0x108300
movq -0x8(%rbp), %rax
movq 0x108(%rax), %rdi
callq 0x2210
movq $0x0, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq -0x8(%rbp), %rcx
movslq 0xb0(%rcx), %rcx
cmpq %rcx, %rax
jge 0x305a4a
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
imulq $0x68, -0x20(%rbp), %rcx
addq %rcx, %rax
movq 0x18(%rax), %rdi
callq 0x2210
movq -0x20(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x20(%rbp)
jmp 0x305a0f
movq -0x8(%rbp), %rax
movq 0x98(%rax), %rdi
callq 0x2210
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x2210
movq 0xbe572(%rip), %rax     # 0x3c3fe0
movq (%rax), %rax
movq %rax, -0x70(%rbp)
callq 0x1b7ca0
movq -0x70(%rbp), %rdi
subsd -0x18(%rbp), %xmm0
leaq 0x87646(%rip), %rsi     # 0x38d0d0
leaq 0x8fde4(%rip), %rdx     # 0x395875
movb $0x1, %al
callq 0x22a0
addq $0x70, %rsp
popq %rbp
retq
nop