// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: clean_trans_base_count_mmhap_comp_rmap(ug_trans_t*, kv_u_trans_t*)
void clean_trans_base_count_mmhap_comp_rmap(ug_trans_t *p, kv_u_trans_t *res)
{
	uint64_t i, k, l, occ, idx_n; ha_mzl_t *tz; u_trans_t *z; 
	kv_ul_ov_t *bl; double ww; ha_mzl_t *idx; 
	///make results consistent
	kv_resize(ha_mzl_t, p->srt_a, p->srt_a.n+p->ug->u.n); 
	idx = p->srt_a.a + p->srt_a.n; idx_n = p->ug->u.n;
	for (i = 0; i < idx_n; i++) {
		tz = &(idx[i]);
		tz->x = (uint64_t)-1; tz->rev = 0;
		tz->pos = tz->rid = tz->span = 0;
	}

	for (i = 0, occ = res->n; (int64_t)i < p->n_thread; i++) {
		bl = &(p->ll[i].tk); 
		if(!(bl->n)) continue;
		for (k = 1, l = 0; k <= bl->n; k++) {
			if(k == bl->n || bl->a[k].qn != bl->a[l].qn) {
				if(k > l) {
					tz = &(idx[bl->a[l].qn]);
					tz->x = bl->a[l].qn; tz->x <<= 32; tz->x |= i;
					tz->rid = l>>32; tz->pos = (uint32_t)l; tz->rev = 1;
					occ += (k - l);
				}
				l = k;
			}
		}
	}

	kv_resize(u_trans_t, *res, occ); 
	for (i = 0; i < idx_n; i++) {
		tz = &(idx[i]);
		if(!(tz->rev)) continue;
		bl = &(p->ll[(uint32_t)(tz->x)].tk);
		k = tz->rid; k <<= 32; k += tz->pos;
		assert(bl->a[k].qn == (tz->x>>32));
		for (; (k < bl->n) && (bl->a[k].qn == (tz->x>>32)); k++) {
			if(bl->a[k].qn == bl->a[k].tn) continue;
			ww = cal_trans_ov_w(&(bl->a[k])); 
			if(ww <= 0) continue;
			
			kv_pushp(u_trans_t, *res, &z);
			z->f = RC_3; z->rev = bl->a[k].rev; z->del = 0; 
			z->qn = bl->a[k].qn; z->qs = bl->a[k].qs; z->qe = bl->a[k].qe;
			z->tn = bl->a[k].tn; z->ts = bl->a[k].ts; z->te = bl->a[k].te;
			z->nw = ww;
		}
	}
	destory_ug_rid_cov_t(p->ccov); free(p->ccov); 
	p->ccov = gen_ug_rid_cov_t(p->ug, p->rg, p->uopt->sources);

	clean_u_trans_t_idx_filter_mmhap_adv(res, p->ug, p->rg, p->uopt->sources, p->ccov);
	gen_ug_rid_cov_t_by_ovlp(res, p->ccov);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movl 0x94(%rdi), %ecx
movl 0x90(%rdi), %eax
movq 0x8(%rdi), %rdx
addq (%rdx), %rax
cmpq %rcx, %rax
movq %rsi, 0x8(%rsp)
jbe 0x1deec7
decl %eax
movl %eax, %ecx
shrl %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x2, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x4, %ecx
orl %eax, %ecx
movl %ecx, %eax
shrl $0x8, %eax
orl %ecx, %eax
movl %eax, %ecx
shrl $0x10, %ecx
orl %eax, %ecx
incl %ecx
movl %ecx, 0x94(%rbx)
movq 0x98(%rbx), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq 0x8(%rsp), %rsi
movq %rax, 0x98(%rbx)
movq 0x98(%rbx), %rax
movl 0x90(%rbx), %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x8(%rbx), %rdx
movq (%rdx), %rdx
movq %rdx, 0x10(%rsp)
testq %rdx, %rdx
je 0x1def12
leaq (%rax,%rcx,8), %rdx
addq $0x10, %rdx
movq 0x10(%rsp), %rdi
movq $-0x1, -0x10(%rdx)
movb $0x0, (%rdx)
movq $0x0, -0x8(%rdx)
addq $0x18, %rdx
decq %rdi
jne 0x1deef6
leaq (%rax,%rcx,8), %r12
movq (%rsi), %rax
cmpl $0x0, 0xb0(%rbx)
jle 0x1defd6
xorl %ecx, %ecx
movq 0x20(%rbx), %rdx
imulq $0x68, %rcx, %rsi
cmpq $0x0, 0x20(%rdx,%rsi)
je 0x1defc3
addq %rsi, %rdx
addq $0x18, %rdx
movq 0x8(%rdx), %r9
testq %r9, %r9
je 0x1defc3
movl $0x1, %esi
movl $0x1c, %edi
xorl %r8d, %r8d
cmpq %r9, %rsi
je 0x1def76
movq (%rdx), %r9
movl (%r9,%rdi), %r10d
leaq (%r8,%r8,8), %r11
leaq (%r11,%r11,2), %r11
addq %r8, %r11
cmpl (%r9,%r11), %r10d
je 0x1defb3
cmpq %r8, %rsi
jbe 0x1defb0
movq (%rdx), %r9
leaq (%r8,%r8,8), %r10
leaq (%r10,%r10,2), %r10
addq %r8, %r10
movl (%r9,%r10), %r9d
leaq (%r9,%r9,2), %r10
shlq $0x20, %r9
orq %rcx, %r9
movq %r9, (%r12,%r10,8)
subq %r8, %rax
rolq $0x20, %r8
btsq $0x1f, %r8
movq %r8, 0x8(%r12,%r10,8)
addq %rsi, %rax
movq %rsi, %r8
incq %rsi
movq 0x8(%rdx), %r9
addq $0x1c, %rdi
cmpq %r9, %rsi
jbe 0x1def59
incq %rcx
movslq 0xb0(%rbx), %rdx
cmpq %rdx, %rcx
jl 0x1def28
movq %rbx, 0x18(%rsp)
movq 0x8(%rsp), %r9
cmpq %rax, 0x8(%r9)
jae 0x1df03b
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
incq %rcx
movq %rcx, 0x8(%r9)
movq 0x10(%r9), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq 0x8(%rsp), %r9
movq %rax, 0x10(%r9)
cmpq $0x0, 0x10(%rsp)
je 0x1df24e
xorl %r13d, %r13d
movl $0x3fffffff, %r10d      # imm = 0x3FFFFFFF
movsd 0x4ab28(%rip), %xmm3    # 0x229b80
xorpd %xmm4, %xmm4
leaq (,%r13,2), %rcx
addq %r13, %rcx
movq 0x8(%r12,%rcx,8), %rax
testl %eax, %eax
jns 0x1df240
leaq (%r12,%rcx,8), %r15
movq 0x18(%rsp), %rcx
movq 0x20(%rcx), %rcx
movq (%r15), %rsi
movl %esi, %edx
imulq $0x68, %rdx, %rdx
movq %rax, %rbp
rolq $0x20, %rbp
btrq $0x3f, %rbp
movq 0x18(%rcx,%rdx), %rdi
leaq (,%rbp,8), %r8
addq %rbp, %r8
leaq (%r8,%r8,2), %r8
addq %rbp, %r8
shrq $0x20, %rsi
cmpl (%rdi,%r8), %esi
jne 0x1df2c0
leaq (%rcx,%rdx), %r14
addq $0x18, %r14
cmpq 0x8(%r14), %rbp
jae 0x1df240
movq %rax, %rcx
shrq $0x20, %rcx
movabsq $0x1c00000000, %rdx     # imm = 0x1C00000000
imulq %rdx, %rax
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rbx
addq %rcx, %rbx
addq %rax, %rbx
movq (%r14), %rax
movl (%rax,%rbx), %ecx
cmpl %ecx, 0x4(%r15)
jne 0x1df240
cmpl 0xc(%rax,%rbx), %ecx
je 0x1df22f
movl 0x8(%rax,%rbx), %ecx
subl 0x4(%rax,%rbx), %ecx
movl 0x14(%rax,%rbx), %edx
xorps %xmm0, %xmm0
cvtsi2sd %rcx, %xmm0
movl 0x18(%rax,%rbx), %ecx
andl %r10d, %ecx
xorps %xmm1, %xmm1
cvtsi2sd %ecx, %xmm1
subsd %xmm1, %xmm0
subl 0x10(%rax,%rbx), %edx
xorps %xmm2, %xmm2
cvtsi2sd %rdx, %xmm2
subsd %xmm1, %xmm2
mulsd %xmm3, %xmm1
addsd %xmm1, %xmm0
addsd %xmm1, %xmm2
movapd %xmm0, %xmm1
cmplesd %xmm2, %xmm1
andpd %xmm1, %xmm0
andnpd %xmm2, %xmm1
orpd %xmm0, %xmm1
ucomisd %xmm1, %xmm4
jae 0x1df22f
movq 0x8(%r9), %rax
cmpq %rax, (%r9)
jne 0x1df1c0
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%r9)
movq 0x10(%r9), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
movapd %xmm1, 0x20(%rsp)
callq 0x2370
movapd 0x20(%rsp), %xmm1
xorpd %xmm4, %xmm4
movsd 0x4a9cf(%rip), %xmm3    # 0x229b80
movl $0x3fffffff, %r10d      # imm = 0x3FFFFFFF
movq 0x8(%rsp), %r9
movq %rax, 0x10(%r9)
movq (%r9), %rcx
movq 0x10(%r9), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, (%r9)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movb 0x28(%rax,%rcx), %dl
andb $-0x40, %dl
orb $0x3, %dl
movb %dl, 0x28(%rax,%rcx)
movq (%r14), %rdx
movl 0x18(%rdx,%rbx), %edx
shrl $0x19, %edx
andb $0x40, %dl
orb $0x3, %dl
movb %dl, 0x28(%rax,%rcx)
movq (%r14), %rdx
movl (%rdx,%rbx), %esi
movl %esi, 0x8(%rax,%rcx)
movl 0x4(%rdx,%rbx), %esi
movl %esi, (%rax,%rcx)
movl 0x8(%rdx,%rbx), %esi
movl %esi, 0x4(%rax,%rcx)
movl 0xc(%rdx,%rbx), %esi
movl %esi, 0x14(%rax,%rcx)
movl 0x10(%rdx,%rbx), %esi
movl %esi, 0xc(%rax,%rcx)
movl 0x14(%rdx,%rbx), %edx
movl %edx, 0x10(%rax,%rcx)
movsd %xmm1, 0x20(%rax,%rcx)
incq %rbp
addq $0x1c, %rbx
cmpq 0x8(%r14), %rbp
jb 0x1df0f0
incq %r13
cmpq 0x10(%rsp), %r13
jne 0x1df05c
movq 0x18(%rsp), %r14
movq 0x108(%r14), %rdi
movq %r9, %rbx
callq 0xc637e
movq 0x108(%r14), %rdi
callq 0x2220
movq (%r14), %rax
movq 0x8(%r14), %rdi
movq 0x10(%r14), %rsi
movq 0x8(%rax), %rdx
callq 0xc610d
movq %rax, 0x108(%r14)
movq (%r14), %rcx
movq 0x8(%r14), %rsi
movq 0x10(%r14), %rdx
movq 0x8(%rcx), %rcx
movq %rbx, %rdi
movq %rax, %r8
callq 0xc72f9
movq 0x108(%r14), %rsi
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc7256
leaq 0x4b8af(%rip), %rdi     # 0x22ab76
leaq 0x546bd(%rip), %rsi     # 0x23398b
leaq 0x5966a(%rip), %rcx     # 0x23893f
movl $0x5743, %edx           # imm = 0x5743
callq 0x2110