// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: clean_u_trans_t_idx_adv(kv_u_trans_t*, ma_ug_t*, asg_t*)
void clean_u_trans_t_idx_adv(kv_u_trans_t *ta, ma_ug_t *ug, asg_t *read_g)
{
    u_trans_clean_t sl; uint64_t k, i, l, occ; ha_mzl_t *tz;
    ha_mzl_v srt_a; kv_u_trans_t *bl; u_trans_t *z;
    memset(&sl, 0, sizeof(sl)); kv_init(srt_a);
    
    kt_u_trans_t_idx(ta, ug->g->n_seq);
    sl.n_thread = asm_opt.thread_num; sl.ug = ug; sl.rg = read_g; sl.ta = ta;
    CALLOC(sl.res, sl.n_thread); 
    sl.ov_cutoff = 3; sl.small_ov_rate = 0.8;
    // dbg_prt_utg_trans(ta, ug, "pre");
    kt_for(sl.n_thread, worker_for_trans_clean, &sl, sl.ta->idx.n);

    for (i = srt_a.n = occ = 0; i < sl.n_thread; i++) {
		bl = &(sl.res[i]); 
		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) {
					kv_pushp(ha_mzl_t, srt_a, &tz);
					tz->x = bl->a[l].qn; tz->x <<= 32; tz->x |= i;
					tz->rid = l>>32; tz->pos = (uint32_t)l;
					occ += (k - l);
				}
				l = k;
			}
		}
	}
    // fprintf(stderr, "[M::%s::] occ::%lu \n", __func__, occ);
    assert(srt_a.n <= sl.ug->u.n); 
	radix_sort_ha_mzl_t_srt1(srt_a.a, srt_a.a + srt_a.n);
    occ <<= 1; ta->n = 0; kv_resize(u_trans_t, *ta, occ); 
    for (i = 0; i < srt_a.n; i++) {
		tz = &(srt_a.a[i]);
		bl = &(sl.res[(uint32_t)(tz->x)]);
		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;
			kv_pushp(u_trans_t, *ta, &z); 
            (*z) = bl->a[k]; if(z->f == RC_3) z->f = RC_2;

            kv_pushp(u_trans_t, *ta, &z); 
            (*z) = bl->a[k]; if(z->f == RC_3) z->f = RC_2;
            z->qn = bl->a[k].tn; z->qs = bl->a[k].ts; z->qe = bl->a[k].te;
            z->tn = bl->a[k].qn; z->ts = bl->a[k].qs; z->te = bl->a[k].qe;
		}
	}

    for (k = 0; k < sl.n_thread; k++) free(sl.res[k].a); 
    free(sl.res); kv_destroy(srt_a);
    kt_u_trans_t_idx(ta, ug->g->n_seq);
    // dbg_prt_utg_trans(ta, ug, "after");
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %r15
movups %xmm0, 0x48(%r15)
movups %xmm0, 0x38(%r15)
movq 0x18(%rsi), %rax
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl 0x14(%rax), %esi
callq 0x88a31
leaq 0x1cb16b(%rip), %rax    # 0x253758
movl 0x7c(%rax), %eax
movslq %eax, %r13
movq %r13, 0x20(%r15)
movq %r14, 0x10(%rsp)
movq %r14, (%r15)
movq %r12, 0x8(%r15)
movq %rbx, 0x18(%r15)
pushq $0x30
popq %rsi
movq %r13, %rdi
callq 0x2120
movq %rax, 0x10(%r15)
movq $0x3, 0x28(%r15)
movabsq $0x3fe999999999999a, %rax # imm = 0x3FE999999999999A
movq %rax, 0x30(%r15)
movq 0x18(%rbx), %rcx
leaq 0x4d9(%rip), %rsi       # 0x88b10
movl %r13d, %edi
movq %r15, %rdx
callq 0xc67c0
xorl %r12d, %r12d
xorl %ebp, %ebp
xorl %edi, %edi
xorl %eax, %eax
xorl %r10d, %r10d
movq %rbx, 0x18(%rsp)
cmpq 0x40(%rsp), %r12
jae 0x88750
movq 0x30(%rsp), %r11
imulq $0x30, %r12, %rdx
movq (%r11,%rdx), %rcx
testq %rcx, %rcx
je 0x88748
addq %rdx, %r11
pushq $0x38
popq %r14
pushq $0x1
popq %r13
xorl %r15d, %r15d
movq %r11, 0x8(%rsp)
cmpq %rcx, %r13
ja 0x88748
je 0x886a9
movq 0x10(%r11), %rdx
movl (%rdx,%r14), %esi
imulq $0x30, %r15, %r8
cmpl 0x8(%rdx,%r8), %esi
je 0x8873c
cmpq %r15, %r13
jbe 0x88739
cmpl %eax, %r10d
jne 0x886e8
movq %rbp, (%rsp)
leal (%rax,%rax), %ebp
testl %eax, %eax
pushq $0x2
popq %rax
cmovel %eax, %ebp
imulq $0x18, %rbp, %rsi
movl %r10d, %ebx
callq 0x2370
movq 0x8(%rsp), %r11
movl %ebx, %r10d
movq %rax, %rdi
movl %ebp, %eax
movq (%rsp), %rbp
movq 0x18(%rsp), %rbx
movl %r10d, %ecx
incl %r10d
imulq $0x18, %rcx, %rcx
movq 0x10(%r11), %rdx
imulq $0x30, %r15, %rsi
movl 0x8(%rdx,%rsi), %edx
shlq $0x20, %rdx
orq %r12, %rdx
movq %rdx, (%rdi,%rcx)
movq %r15, %rdx
shrq $0x20, %rdx
movq 0x8(%rdi,%rcx), %rsi
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %esi       # imm = 0x80000000
orq %rdx, %rsi
subq %r15, %rbp
shlq $0x20, %r15
orq %rsi, %r15
movq %r15, 0x8(%rdi,%rcx)
addq %r13, %rbp
movq (%r11), %rcx
movq %r13, %r15
incq %r13
addq $0x30, %r14
jmp 0x88687
incq %r12
jmp 0x88653
movl %r10d, %r14d
movq 0x20(%rsp), %rax
cmpq %r14, (%rax)
jb 0x88a12
imulq $0x18, %r14, %rsi
addq %rdi, %rsi
movq %rdi, (%rsp)
callq 0x67d37
andq $0x0, (%rbx)
addq %rbp, %rbp
cmpq %rbp, 0x8(%rbx)
jae 0x887ca
decq %rbp
movq %rbp, %rax
shrq %rax
orq %rbp, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
incq %rax
movq %rax, 0x8(%rbx)
movq 0x10(%rbx), %rdi
imulq $0x30, %rax, %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
xorl %eax, %eax
movq (%rsp), %r8
movq %r14, 0x8(%rsp)
cmpq %r14, %rax
je 0x88998
movq %rax, %r15
imulq $0x18, %rax, %rbp
movq 0x30(%rsp), %r12
movq (%r8,%rbp), %rsi
movq 0x8(%r8,%rbp), %rax
movl %esi, %ecx
imulq $0x30, %rcx, %rdx
movq %rax, %r14
rolq $0x20, %r14
btrq $0x3f, %r14
movq 0x10(%r12,%rdx), %rcx
imulq $0x30, %r14, %rdi
shrq $0x20, %rsi
cmpl 0x8(%rcx,%rdi), %esi
jne 0x889f3
addq %r8, %rbp
addq %rdx, %r12
movq %rax, %rdx
shrq $0x20, %rdx
movabsq $0x3000000000, %rsi     # imm = 0x3000000000
imulq %rsi, %rax
imulq $0x30, %rdx, %r13
addq %rax, %r13
cmpq (%r12), %r14
jae 0x88988
movl 0x8(%rcx,%r13), %eax
cmpl %eax, 0x4(%rbp)
jne 0x88988
cmpl 0x14(%rcx,%r13), %eax
je 0x8897c
movq (%rbx), %rdx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rdx
jne 0x88898
leaq (%rdx,%rdx), %rcx
testq %rdx, %rdx
pushq $0x2
popq %rdx
cmoveq %rdx, %rcx
movq %rcx, 0x8(%rbx)
imulq $0x30, %rcx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rdx
movq 0x10(%r12), %rcx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rbx)
imulq $0x30, %rdx, %rdx
movups (%rcx,%r13), %xmm0
movups 0x10(%rcx,%r13), %xmm1
movups 0x20(%rcx,%r13), %xmm2
movups %xmm2, 0x20(%rax,%rdx)
movups %xmm1, 0x10(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
movb 0x28(%rax,%rdx), %cl
movl %ecx, %esi
andb $0x3f, %sil
cmpb $0x3, %sil
jne 0x888db
addq %rdx, %rax
andb $-0x3e, %cl
movb %cl, 0x28(%rax)
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x8890d
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rbx)
imulq $0x30, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
movq (%rsp), %r8
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
imulq $0x30, %rcx, %rcx
leaq (%rax,%rcx), %rdx
movq 0x10(%r12), %rsi
movups (%rsi,%r13), %xmm0
movups 0x10(%rsi,%r13), %xmm1
movups 0x20(%rsi,%r13), %xmm2
movups %xmm2, 0x20(%rax,%rcx)
movups %xmm1, 0x10(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movb 0x28(%rax,%rcx), %al
movl %eax, %ecx
andb $0x3f, %cl
cmpb $0x3, %cl
jne 0x88957
andb $-0x3e, %al
movb %al, 0x28(%rdx)
movq 0x10(%r12), %rcx
movl 0x14(%rcx,%r13), %eax
movl %eax, 0x8(%rdx)
movq 0xc(%rcx,%r13), %rax
movq %rax, (%rdx)
movl 0x8(%rcx,%r13), %eax
movl %eax, 0x14(%rdx)
movq (%rcx,%r13), %rax
movq %rax, 0xc(%rdx)
incq %r14
addq $0x30, %r13
jmp 0x8883e
movq %r15, %rax
incq %rax
movq 0x8(%rsp), %r14
jmp 0x887d5
pushq $0x10
popq %r14
xorl %r15d, %r15d
movq 0x30(%rsp), %rdi
cmpq 0x40(%rsp), %r15
jae 0x889bd
movq (%rdi,%r14), %rdi
callq 0x2220
incq %r15
addq $0x30, %r14
jmp 0x8899f
callq 0x2220
movq (%rsp), %rdi
callq 0x2220
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl 0x14(%rax), %esi
movq %rbx, %rdi
callq 0x88a31
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x16026c(%rip), %rdi    # 0x1e8c66
leaq 0x15f390(%rip), %rsi    # 0x1e7d91
leaq 0x16021d(%rip), %rcx    # 0x1e8c25
movl $0x3c3c, %edx           # imm = 0x3C3C
callq 0x2110
leaq 0x1601f6(%rip), %rdi    # 0x1e8c0f
leaq 0x15f371(%rip), %rsi    # 0x1e7d91
leaq 0x1601fe(%rip), %rcx    # 0x1e8c25
movl $0x3c35, %edx           # imm = 0x3C35
callq 0x2110