// File: /workspace/github_cpp_makefile_star2_O3/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, %r14
movl 0x94(%rdi), %edx
movl 0x90(%rdi), %ecx
movq 0x8(%rdi), %rax
movq (%rax), %r15
leaq (%r15,%rcx), %rax
cmpq %rdx, %rax
movq %rsi, 0x8(%rsp)
jbe 0x1e996f
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(%r14)
movq 0x98(%r14), %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq 0x8(%rsp), %rsi
movq %rax, 0x98(%r14)
movl 0x90(%r14), %ecx
movq 0x8(%r14), %rdx
movq (%rdx), %r15
jmp 0x1e9976
movq 0x98(%r14), %rax
leaq (%rcx,%rcx,2), %rcx
testq %r15, %r15
je 0x1e99a6
leaq (%rax,%rcx,8), %rdx
addq $0x10, %rdx
movq %r15, %rdi
movq $-0x1, -0x10(%rdx)
movb $0x0, (%rdx)
movq $0x0, -0x8(%rdx)
addq $0x18, %rdx
decq %rdi
jne 0x1e998a
leaq (%rax,%rcx,8), %r12
movq (%rsi), %rax
movl 0xb0(%r14), %edx
testl %edx, %edx
jle 0x1e9a69
xorl %ecx, %ecx
movq 0x20(%r14), %rsi
imulq $0x68, %rcx, %rdi
movq 0x20(%rsi,%rdi), %r9
testq %r9, %r9
je 0x1e9a5a
leaq (%rsi,%rdi), %rdx
addq $0x18, %rdx
movl $0x1, %esi
movl $0x1c, %edi
xorl %r8d, %r8d
cmpq %r9, %rsi
je 0x1e9a06
movq (%rdx), %r10
movl (%r10,%rdi), %r11d
leaq (%r8,%r8,8), %rbx
leaq (%rbx,%rbx,2), %rbx
addq %r8, %rbx
cmpl (%r10,%rbx), %r11d
je 0x1e9a47
cmpq %r8, %rsi
jbe 0x1e9a44
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 0x8(%rdx), %r9
movq %rsi, %r8
incq %rsi
addq $0x1c, %rdi
cmpq %r9, %rsi
jbe 0x1e99e9
movl 0xb0(%r14), %edx
incq %rcx
movslq %edx, %rsi
cmpq %rsi, %rcx
jl 0x1e99be
movq %r14, 0x10(%rsp)
movq 0x8(%rsp), %r9
cmpq %rax, 0x8(%r9)
jae 0x1e9ace
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)
testq %r15, %r15
je 0x1e9cdc
xorl %r13d, %r13d
movl $0x3fffffff, %r10d      # imm = 0x3FFFFFFF
movsd 0x4c290(%rip), %xmm3    # 0x235d78
xorpd %xmm4, %xmm4
movq %r15, 0x18(%rsp)
leaq (,%r13,2), %rax
addq %r13, %rax
movq 0x8(%r12,%rax,8), %rdx
testl %edx, %edx
jns 0x1e9ccb
leaq (%r12,%rax,8), %r15
movq 0x10(%rsp), %rax
movq 0x20(%rax), %rax
movq (%r15), %rdi
movl %edi, %ecx
imulq $0x68, %rcx, %rsi
movq %rdx, %rbp
rolq $0x20, %rbp
btrq $0x3f, %rbp
movq 0x18(%rax,%rsi), %rcx
leaq (,%rbp,8), %r8
addq %rbp, %r8
leaq (%r8,%r8,2), %r8
addq %rbp, %r8
shrq $0x20, %rdi
cmpl (%rcx,%r8), %edi
jne 0x1e9d4e
leaq (%rax,%rsi), %r14
addq $0x18, %r14
movq 0x8(%r14), %rax
cmpq %rax, %rbp
jae 0x1e9ccb
movq %rdx, %rsi
shrq $0x20, %rsi
movabsq $0x1c00000000, %rdi     # imm = 0x1C00000000
imulq %rdi, %rdx
leaq (%rsi,%rsi,8), %rdi
leaq (%rdi,%rdi,2), %rbx
addq %rsi, %rbx
addq %rdx, %rbx
movl (%rcx,%rbx), %edx
cmpl %edx, 0x4(%r15)
jne 0x1e9ccb
cmpl 0xc(%rcx,%rbx), %edx
je 0x1e9cbb
movl 0x8(%rcx,%rbx), %edx
subl 0x4(%rcx,%rbx), %edx
movl 0x14(%rcx,%rbx), %esi
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
movl 0x18(%rcx,%rbx), %edx
andl %r10d, %edx
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
subsd %xmm1, %xmm0
subl 0x10(%rcx,%rbx), %esi
xorps %xmm2, %xmm2
cvtsi2sd %rsi, %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 0x1e9cbb
movq (%r9), %rcx
movq 0x10(%r9), %rax
cmpq 0x8(%r9), %rcx
jne 0x1e9c5b
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r9)
shlq $0x4, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, %rdi
movapd %xmm1, 0x20(%rsp)
callq 0x2370
movapd 0x20(%rsp), %xmm1
xorpd %xmm4, %xmm4
movsd 0x4c12f(%rip), %xmm3    # 0x235d78
movl $0x3fffffff, %r10d      # imm = 0x3FFFFFFF
movq 0x8(%rsp), %r9
movq %rax, 0x10(%r9)
movq (%r9), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r9)
leaq (%rcx,%rcx,2), %rdx
shlq $0x4, %rdx
movb 0x28(%rax,%rdx), %cl
andb $-0x40, %cl
orb $0x3, %cl
movb %cl, 0x28(%rax,%rdx)
movq (%r14), %rcx
movl 0x18(%rcx,%rbx), %ecx
shrl $0x19, %ecx
andb $0x40, %cl
orb $0x3, %cl
movb %cl, 0x28(%rax,%rdx)
movq (%r14), %rcx
movl (%rcx,%rbx), %esi
movl %esi, 0x8(%rax,%rdx)
movq 0x4(%rcx,%rbx), %rsi
movq %rsi, (%rax,%rdx)
movl 0xc(%rcx,%rbx), %esi
movl %esi, 0x14(%rax,%rdx)
movq 0x10(%rcx,%rbx), %rsi
movq %rsi, 0xc(%rax,%rdx)
movsd %xmm1, 0x20(%rax,%rdx)
movq 0x8(%r14), %rax
incq %rbp
addq $0x1c, %rbx
cmpq %rax, %rbp
jb 0x1e9b88
incq %r13
movq 0x18(%rsp), %r15
cmpq %r15, %r13
jne 0x1e9af1
movq 0x10(%rsp), %r14
movq 0x108(%r14), %rdi
movq %r9, %rbx
callq 0xc7129
movq 0x108(%r14), %rdi
callq 0x2220
movq (%r14), %rax
movq 0x8(%r14), %rdi
movq 0x10(%r14), %rsi
movq 0x8(%rax), %rdx
callq 0xc6eb8
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 0xc80ab
movq 0x108(%r14), %rsi
movq %rbx, %rdi
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc8007
leaq 0x4d011(%rip), %rdi     # 0x236d66
leaq 0x55eff(%rip), %rsi     # 0x23fc5b
leaq 0x5aeac(%rip), %rcx     # 0x244c0f
movl $0x5743, %edx           # imm = 0x5743
callq 0x2110