// File: /workspace/github_cpp_makefile_star2_O1/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
movaps %xmm0, 0x40(%r15)
movaps %xmm0, 0x30(%r15)
movaps %xmm0, 0x20(%r15)
movaps %xmm0, 0x10(%r15)
movaps %xmm0, (%r15)
movq $0x0, 0x50(%r15)
movq 0x18(%rsi), %rax
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl 0x14(%rax), %esi
callq 0xc405a
leaq 0x1c6bdd(%rip), %rax    # 0x28a758
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)
movl $0x30, %esi
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 0x594(%rip), %rsi       # 0xc415b
movl %r13d, %edi
movq %r15, %rdx
callq 0x1047b4
cmpq $0x0, 0x20(%r15)
je 0xc3d24
xorl %r8d, %r8d
xorl %eax, %eax
xorl %edi, %edi
xorl %r12d, %r12d
xorl %ebp, %ebp
movq %rbx, 0x18(%rsp)
movq 0x30(%rsp), %r10
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
shlq $0x4, %rcx
cmpq $0x0, (%r10,%rcx)
je 0xc3d11
addq %rcx, %r10
movq (%r10), %rcx
testq %rcx, %rcx
je 0xc3d11
movl $0x1, %r15d
movl $0x38, %r14d
xorl %r13d, %r13d
movq %r10, 0x8(%rsp)
cmpq %rcx, %r15
je 0xc3c56
movq 0x10(%r10), %rcx
movl (%rcx,%r14), %edx
leaq (,%r13,2), %rsi
addq %r13, %rsi
shlq $0x4, %rsi
cmpl 0x8(%rcx,%rsi), %edx
je 0xc3cfe
cmpq %r13, %r15
jbe 0xc3cfb
cmpl %eax, %r8d
jne 0xc3ca2
movq %r12, (%rsp)
leal (%rax,%rax), %r12d
testl %eax, %eax
movl $0x2, %eax
cmovel %eax, %r12d
leaq (,%r12,8), %rax
leaq (%rax,%rax,2), %rsi
movq %r8, %rbx
callq 0x2370
movq 0x8(%rsp), %r10
movq %rbx, %r8
movq %rax, %rdi
movl %r12d, %eax
movq (%rsp), %r12
movq 0x18(%rsp), %rbx
movl %r8d, %ecx
incl %r8d
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%r10), %rdx
leaq (,%r13,2), %rsi
addq %r13, %rsi
shlq $0x4, %rsi
movl 0x8(%rdx,%rsi), %edx
shlq $0x20, %rdx
orq %rbp, %rdx
movq %rdx, (%rdi,%rcx,8)
movq %r13, %rdx
shrq $0x20, %rdx
movq 0x8(%rdi,%rcx,8), %rsi
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %esi       # imm = 0x80000000
orq %rdx, %rsi
subq %r13, %r12
shlq $0x20, %r13
orq %rsi, %r13
movq %r13, 0x8(%rdi,%rcx,8)
addq %r15, %r12
movq %r15, %r13
incq %r15
movq (%r10), %rcx
addq $0x30, %r14
cmpq %rcx, %r15
jbe 0xc3c30
incq %rbp
cmpq 0x40(%rsp), %rbp
jb 0xc3bee
addq %r12, %r12
jmp 0xc3d2c
xorl %r12d, %r12d
xorl %edi, %edi
xorl %r8d, %r8d
movl %r8d, %r14d
movq 0x20(%rsp), %rax
cmpq %r14, (%rax)
jb 0xc403b
leaq (%r14,%r14,2), %rax
leaq (%rdi,%rax,8), %rsi
movq %rdi, (%rsp)
callq 0x9e737
movq $0x0, (%rbx)
cmpq %r12, 0x8(%rbx)
jae 0xc3dab
decq %r12
movq %r12, %rax
shrq %rax
orq %r12, %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
shlq $0x4, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
testq %r14, %r14
movq (%rsp), %r9
je 0xc3fb4
xorl %r13d, %r13d
movq %r14, 0x8(%rsp)
leaq (,%r13,2), %rcx
addq %r13, %rcx
movq 0x30(%rsp), %rbp
movq (%r9,%rcx,8), %rsi
movq 0x8(%r9,%rcx,8), %rax
movl %esi, %edx
leaq (%rdx,%rdx,2), %rdx
movq %rax, %r12
rolq $0x20, %r12
shlq $0x4, %rdx
btrq $0x3f, %r12
movq 0x10(%rbp,%rdx), %rdi
leaq (%r12,%r12,2), %r8
shlq $0x4, %r8
shrq $0x20, %rsi
cmpl 0x8(%rdi,%r8), %esi
jne 0xc401c
addq %rdx, %rbp
cmpq (%rbp), %r12
jae 0xc3fa3
leaq (%r9,%rcx,8), %r14
leaq (%rax,%rax,2), %rcx
shrq $0x20, %rax
shlq $0x24, %rcx
leaq (%rax,%rax,2), %r15
shlq $0x4, %r15
addq %rcx, %r15
movq 0x10(%rbp), %rax
movl 0x8(%rax,%r15), %ecx
cmpl %ecx, 0x4(%r14)
jne 0xc3fa3
cmpl 0x14(%rax,%r15), %ecx
je 0xc3f92
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0xc3e87
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq (%rsp), %r9
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
movq 0x10(%rbp), %rdx
movups (%rdx,%r15), %xmm0
movups 0x10(%rdx,%r15), %xmm1
movups 0x20(%rdx,%r15), %xmm2
movups %xmm2, 0x20(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movups %xmm1, 0x10(%rax,%rcx)
movb 0x28(%rax,%rcx), %dl
movl %edx, %esi
andb $0x3f, %sil
cmpb $0x3, %sil
jne 0xc3ed9
addq %rcx, %rax
andb $-0x3e, %dl
movb %dl, 0x28(%rax)
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0xc3f0f
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq (%rsp), %r9
movq %rax, 0x10(%rbx)
movq (%rbx), %rax
movq 0x10(%rbx), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rbx)
leaq (%rax,%rax,2), %rdx
shlq $0x4, %rdx
leaq (%rcx,%rdx), %rax
movq 0x10(%rbp), %rsi
movups (%rsi,%r15), %xmm0
movups 0x10(%rsi,%r15), %xmm1
movups 0x20(%rsi,%r15), %xmm2
movups %xmm2, 0x20(%rcx,%rdx)
movups %xmm0, (%rcx,%rdx)
movups %xmm1, 0x10(%rcx,%rdx)
movb 0x28(%rcx,%rdx), %cl
movl %ecx, %edx
andb $0x3f, %dl
cmpb $0x3, %dl
jne 0xc3f60
andb $-0x3e, %cl
movb %cl, 0x28(%rax)
movq 0x10(%rbp), %rcx
movl 0x14(%rcx,%r15), %edx
movl %edx, 0x8(%rax)
movl 0xc(%rcx,%r15), %edx
movl %edx, (%rax)
movl 0x10(%rcx,%r15), %edx
movl %edx, 0x4(%rax)
movl 0x8(%rcx,%r15), %edx
movl %edx, 0x14(%rax)
movl (%rcx,%r15), %edx
movl %edx, 0xc(%rax)
movl 0x4(%rcx,%r15), %ecx
movl %ecx, 0x10(%rax)
incq %r12
addq $0x30, %r15
cmpq (%rbp), %r12
jb 0xc3e33
incq %r13
movq 0x8(%rsp), %r14
cmpq %r14, %r13
jne 0xc3dc0
cmpq $0x0, 0x40(%rsp)
je 0xc3fe1
movl $0x10, %r14d
xorl %r15d, %r15d
movq 0x30(%rsp), %rax
movq (%rax,%r14), %rdi
callq 0x2220
incq %r15
addq $0x30, %r14
cmpq 0x40(%rsp), %r15
jb 0xc3fc5
movq 0x30(%rsp), %rdi
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 0xc405a
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x166b53(%rip), %rdi    # 0x22ab76
leaq 0x165c77(%rip), %rsi    # 0x229ca1
leaq 0x166b04(%rip), %rcx    # 0x22ab35
movl $0x3c3c, %edx           # imm = 0x3C3C
callq 0x2110
leaq 0x166add(%rip), %rdi    # 0x22ab1f
leaq 0x165c58(%rip), %rsi    # 0x229ca1
leaq 0x166ae5(%rip), %rcx    # 0x22ab35
movl $0x3c35, %edx           # imm = 0x3C35
callq 0x2110