// File: /workspace/github_cpp_makefile_star2_O3/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 0xc4edd
leaq 0x1d0d21(%rip), %rax    # 0x295758
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 %rbx, 0x18(%rsp)
movq 0x18(%rbx), %rcx
leaq 0x55c(%rip), %rsi       # 0xc4fe4
movl %r13d, %edi
movq %r15, %rdx
callq 0x108f2c
movq 0x20(%r15), %rcx
testq %rcx, %rcx
je 0xc4bbb
xorl %r15d, %r15d
xorl %r8d, %r8d
xorl %edi, %edi
xorl %r13d, %r13d
xorl %r12d, %r12d
movq 0x30(%rsp), %r11
leaq (%r12,%r12,2), %rdx
shlq $0x4, %rdx
movq (%r11,%rdx), %rax
testq %rax, %rax
je 0xc4baa
addq %rdx, %r11
movl $0x1, %ebp
movl $0x38, %ebx
xorl %r14d, %r14d
movq %r11, 0x8(%rsp)
cmpq %rax, %rbp
je 0xc4afb
movq 0x10(%r11), %rcx
movl (%rcx,%rbx), %edx
leaq (%r14,%r14,2), %rsi
shlq $0x4, %rsi
cmpl 0x8(%rcx,%rsi), %edx
je 0xc4b95
cmpq %r14, %rbp
jbe 0xc4b92
cmpl %r8d, %r15d
jne 0xc4b3d
movq %r13, (%rsp)
leal (%r15,%r15), %r13d
testl %r15d, %r15d
movl $0x2, %eax
cmovel %eax, %r13d
leaq (,%r13,8), %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq 0x8(%rsp), %r11
movq %r13, %r8
movq (%rsp), %r13
movq %rax, %rdi
movl %r15d, %eax
incl %r15d
leaq (%rax,%rax,2), %rax
movq 0x10(%r11), %rcx
leaq (%r14,%r14,2), %rdx
shlq $0x4, %rdx
movl 0x8(%rcx,%rdx), %ecx
shlq $0x20, %rcx
orq %r12, %rcx
movq %rcx, (%rdi,%rax,8)
movq %r14, %rcx
shrq $0x20, %rcx
movq 0x8(%rdi,%rax,8), %rdx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orq %rcx, %rdx
subq %r14, %r13
shlq $0x20, %r14
orq %rdx, %r14
movq %r14, 0x8(%rdi,%rax,8)
addq %rbp, %r13
movq (%r11), %rax
movq %rbp, %r14
incq %rbp
addq $0x30, %rbx
cmpq %rax, %rbp
jbe 0xc4add
movq 0x40(%rsp), %rcx
incq %r12
cmpq %rcx, %r12
jb 0xc4aae
addq %r13, %r13
jmp 0xc4bc3
xorl %r13d, %r13d
xorl %edi, %edi
xorl %r15d, %r15d
movl %r15d, %ebx
movq 0x20(%rsp), %rax
cmpq %rbx, (%rax)
movq 0x18(%rsp), %r15
jb 0xc4ebe
leaq (%rbx,%rbx,2), %rax
leaq (%rdi,%rax,8), %rsi
movq %rdi, (%rsp)
callq 0x9ee5d
movq $0x0, (%r15)
cmpq %r13, 0x8(%r15)
jae 0xc4c47
decq %r13
movq %r13, %rax
shrq %rax
orq %r13, %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(%r15)
movq 0x10(%r15), %rdi
shlq $0x4, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq %rax, 0x10(%r15)
testq %rbx, %rbx
movq (%rsp), %r9
je 0xc4e38
xorl %eax, %eax
movq %rbx, 0x8(%rsp)
movq %rax, %rbx
leaq (%rax,%rax,2), %rsi
movq 0x30(%rsp), %r14
movq (%r9,%rsi,8), %rdi
movq 0x8(%r9,%rsi,8), %rdx
movl %edi, %eax
leaq (%rax,%rax,2), %rax
movq %rdx, %r12
rolq $0x20, %r12
shlq $0x4, %rax
btrq $0x3f, %r12
movq 0x10(%r14,%rax), %rcx
leaq (%r12,%r12,2), %r8
shlq $0x4, %r8
shrq $0x20, %rdi
cmpl 0x8(%rcx,%r8), %edi
jne 0xc4e9f
addq %rax, %r14
movq (%r14), %rax
cmpq %rax, %r12
jae 0xc4e24
leaq (%r9,%rsi,8), %rbp
leaq (%rdx,%rdx,2), %rsi
shrq $0x20, %rdx
shlq $0x24, %rsi
leaq (%rdx,%rdx,2), %r13
shlq $0x4, %r13
addq %rsi, %r13
movl 0x8(%rcx,%r13), %edx
cmpl %edx, 0x4(%rbp)
jne 0xc4e24
cmpl 0x14(%rcx,%r13), %edx
je 0xc4e14
movq (%r15), %rdx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rdx
jne 0xc4d21
leaq (%rdx,%rdx), %rcx
testq %rdx, %rdx
movl $0x2, %edx
cmoveq %rdx, %rcx
movq %rcx, 0x8(%r15)
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r15)
movq (%r15), %rdx
movq 0x10(%r14), %rcx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r15)
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %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 0xc4d68
addq %rdx, %rax
andb $-0x3e, %cl
movb %cl, 0x28(%rax)
movq (%r15), %rcx
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rcx
jne 0xc4da0
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r15)
shlq $0x4, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r15)
movq (%r15), %rcx
movq (%rsp), %r9
leaq 0x1(%rcx), %rdx
movq %rdx, (%r15)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
leaq (%rax,%rcx), %rdx
movq 0x10(%r14), %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 0xc4ded
andb $-0x3e, %al
movb %al, 0x28(%rdx)
movq 0x10(%r14), %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)
movq (%r14), %rax
incq %r12
addq $0x30, %r13
cmpq %rax, %r12
jb 0xc4ccc
movq %rbx, %rax
incq %rax
movq 0x8(%rsp), %rbx
cmpq %rbx, %rax
jne 0xc4c5b
cmpq $0x0, 0x40(%rsp)
je 0xc4e64
movl $0x10, %ebx
xorl %r14d, %r14d
movq 0x30(%rsp), %rax
movq (%rax,%rbx), %rdi
callq 0x2220
incq %r14
addq $0x30, %rbx
cmpq 0x40(%rsp), %r14
jb 0xc4e48
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 %r15, %rdi
callq 0xc4edd
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x171ec0(%rip), %rdi    # 0x236d66
leaq 0x170fe4(%rip), %rsi    # 0x235e91
leaq 0x171e71(%rip), %rcx    # 0x236d25
movl $0x3c3c, %edx           # imm = 0x3C3C
callq 0x2110
leaq 0x171e4a(%rip), %rdi    # 0x236d0f
leaq 0x170fc5(%rip), %rsi    # 0x235e91
leaq 0x171e52(%rip), %rcx    # 0x236d25
movl $0x3c35, %edx           # imm = 0x3C35
callq 0x2110