// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: clean_u_trans_t_idx_filter_adv(kv_u_trans_t*, ma_ug_t*, asg_t*, double, unsigned long)
void clean_u_trans_t_idx_filter_adv(kv_u_trans_t *ta, ma_ug_t *ug, asg_t *read_g, double sc_sec_rate, uint64_t uniform_only)
{
    u_trans_clean_t sl; uint64_t k, i, l, st, 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; sl.sc_sec_rate = sc_sec_rate;
    // dbg_prt_utg_trans(ta, ug, "pre");
    kt_for(sl.n_thread, worker_for_trans_clean_re, &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]; z->occ = 0; if(z->f == RC_3) z->f = RC_2;

            kv_pushp(u_trans_t, *ta, &z); 
            (*z) = bl->a[k]; z->occ = 0; 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");
    if(uniform_only) return;



    CALLOC(sl.srt, sl.n_thread); sl.sec_rate = 0.5; sl.sc_sec_rate = sc_sec_rate;
    kt_for(sl.n_thread, worker_for_trans_sec_cut, &sl, sl.ta->idx.n);
    sl.cu = gen_u_trans_cluster(ta);
    kt_for(sl.n_thread, worker_for_trans_sec_cut, &sl, sl.cu->idx.n);
    free(sl.cu->idx.a); free(sl.cu->z.a); free(sl.cu);
    for (k = 0; k < sl.n_thread; k++) free(sl.srt[k].a); free(sl.srt);

    for (k = st = 0; k < ta->n; k++) {
        if(ta->a[k].occ == ((uint32_t)-1)) continue;
        ta->a[st++] = ta->a[k];
    }
    ta->n = st;
    for (st = 0, i = 1; i <= ta->n; ++i) {
        if (i == ta->n || ta->a[i].qn != ta->a[st].qn) {
            ta->idx.a[ta->a[st].qn] = (((uint64_t)st)<<32)|(i-st);
            st = i;
        }
    }
    // dbg_prt_utg_extra_trans(ta, ug, asm_opt.output_file_name);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, 0x28(%rsp)
movsd %xmm0, 0x18(%rsp)
movq %rdx, %r13
movq %rsi, %r14
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %r12
movaps %xmm0, 0x40(%r12)
movaps %xmm0, 0x30(%r12)
movaps %xmm0, 0x20(%r12)
movaps %xmm0, 0x10(%r12)
movaps %xmm0, (%r12)
movq $0x0, 0x50(%r12)
movq 0x18(%rsi), %rax
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl 0x14(%rax), %esi
callq 0xc405a
leaq 0x1c5f80(%rip), %rax    # 0x28a758
movl 0x7c(%rax), %eax
movslq %eax, %rbp
movq %rbp, 0x20(%r12)
movq %r14, 0x20(%rsp)
movq %r14, (%r12)
movq %r13, 0x8(%r12)
movq %rbx, 0x18(%r12)
movl $0x30, %esi
movq %rbp, %rdi
callq 0x2120
movq %rax, 0x10(%r12)
movq $0x3, 0x28(%r12)
movabsq $0x3fe999999999999a, %rax # imm = 0x3FE999999999999A
movq %rax, 0x30(%r12)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x40(%r12)
movq 0x18(%rbx), %rcx
leaq 0x618(%rip), %rsi       # 0xc4e50
movl %ebp, %edi
movq %r12, %rdx
callq 0x1047b4
cmpq $0x0, 0x20(%r12)
movq %rbx, 0x8(%rsp)
je 0xc4976
xorl %r13d, %r13d
xorl %eax, %eax
xorl %edi, %edi
xorl %ebp, %ebp
xorl %r14d, %r14d
movq 0x40(%rsp), %r10
leaq (%r14,%r14,2), %rcx
shlq $0x4, %rcx
cmpq $0x0, (%r10,%rcx)
je 0xc495e
addq %rcx, %r10
movq (%r10), %rcx
testq %rcx, %rcx
je 0xc495e
movl $0x1, %r12d
movl $0x38, %r15d
xorl %ebx, %ebx
movq %r10, 0x10(%rsp)
cmpq %rcx, %r12
je 0xc48b8
movq 0x10(%r10), %rcx
movl (%rcx,%r15), %edx
leaq (%rbx,%rbx,2), %rsi
shlq $0x4, %rsi
cmpl 0x8(%rcx,%rsi), %edx
je 0xc494b
cmpq %rbx, %r12
jbe 0xc4948
cmpl %eax, %r13d
jne 0xc48f6
movq %rbp, (%rsp)
leal (%rax,%rax), %ebp
testl %eax, %eax
movl $0x2, %eax
cmovel %eax, %ebp
leaq (,%rbp,8), %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq 0x10(%rsp), %r10
movq %rax, %rdi
movl %ebp, %eax
movq (%rsp), %rbp
movl %r13d, %ecx
incl %r13d
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%r10), %rdx
leaq (%rbx,%rbx,2), %rsi
shlq $0x4, %rsi
movl 0x8(%rdx,%rsi), %edx
shlq $0x20, %rdx
orq %r14, %rdx
movq %rdx, (%rdi,%rcx,8)
movq %rbx, %rdx
shrq $0x20, %rdx
movq 0x8(%rdi,%rcx,8), %rsi
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %esi       # imm = 0x80000000
orq %rdx, %rsi
subq %rbx, %rbp
shlq $0x20, %rbx
orq %rsi, %rbx
movq %rbx, 0x8(%rdi,%rcx,8)
addq %r12, %rbp
movq %r12, %rbx
incq %r12
movq (%r10), %rcx
addq $0x30, %r15
cmpq %rcx, %r12
jbe 0xc4899
incq %r14
cmpq 0x50(%rsp), %r14
movq 0x8(%rsp), %rbx
jb 0xc485f
addq %rbp, %rbp
jmp 0xc497d
xorl %ebp, %ebp
xorl %edi, %edi
xorl %r13d, %r13d
movl %r13d, %r15d
movq 0x30(%rsp), %rax
cmpq %r15, (%rax)
jb 0xc4e31
leaq (%r15,%r15,2), %rax
leaq (%rdi,%rax,8), %rsi
movq %rdi, (%rsp)
callq 0x9e737
movq $0x0, (%rbx)
cmpq %rbp, 0x8(%rbx)
jae 0xc49fc
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
shlq $0x4, %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
testq %r15, %r15
movq (%rsp), %r9
je 0xc4c12
xorl %r14d, %r14d
movq %r15, 0x10(%rsp)
leaq (%r14,%r14,2), %rcx
movq 0x40(%rsp), %r15
movq (%r9,%rcx,8), %rsi
movq 0x8(%r9,%rcx,8), %rax
movl %esi, %edx
leaq (%rdx,%rdx,2), %rdx
movq %rax, %r13
rolq $0x20, %r13
shlq $0x4, %rdx
btrq $0x3f, %r13
movq 0x10(%r15,%rdx), %rdi
leaq (,%r13,2), %r8
addq %r13, %r8
shlq $0x4, %r8
shrq $0x20, %rsi
cmpl 0x8(%rdi,%r8), %esi
jne 0xc4e12
addq %rdx, %r15
cmpq (%r15), %r13
jae 0xc4c01
leaq (%r9,%rcx,8), %rbp
leaq (%rax,%rax,2), %rcx
shrq $0x20, %rax
shlq $0x24, %rcx
leaq (%rax,%rax,2), %r12
shlq $0x4, %r12
addq %rcx, %r12
movq 0x10(%r15), %rax
movl 0x8(%rax,%r12), %ecx
cmpl %ecx, 0x4(%rbp)
jne 0xc4c01
cmpl 0x14(%rax,%r12), %ecx
je 0xc4bf1
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0xc4ad6
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(%r15), %rdx
movups (%rdx,%r12), %xmm0
movups 0x10(%rdx,%r12), %xmm1
movups 0x20(%rdx,%r12), %xmm2
movups %xmm1, 0x10(%rax,%rcx)
movups %xmm2, 0x20(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movl $0x0, 0x18(%rax,%rcx)
movb 0x28(%rax,%rcx), %dl
movl %edx, %esi
andb $0x3f, %sil
cmpb $0x3, %sil
jne 0xc4b30
addq %rcx, %rax
andb $-0x3e, %dl
movb %dl, 0x28(%rax)
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0xc4b66
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(%r15), %rsi
movups (%rsi,%r12), %xmm0
movups 0x10(%rsi,%r12), %xmm1
movups 0x20(%rsi,%r12), %xmm2
movups %xmm1, 0x10(%rcx,%rdx)
movups %xmm2, 0x20(%rcx,%rdx)
movups %xmm0, (%rcx,%rdx)
movl $0x0, 0x18(%rcx,%rdx)
movb 0x28(%rcx,%rdx), %cl
movl %ecx, %edx
andb $0x3f, %dl
cmpb $0x3, %dl
jne 0xc4bbf
andb $-0x3e, %cl
movb %cl, 0x28(%rax)
movq 0x10(%r15), %rcx
movl 0x14(%rcx,%r12), %edx
movl %edx, 0x8(%rax)
movl 0xc(%rcx,%r12), %edx
movl %edx, (%rax)
movl 0x10(%rcx,%r12), %edx
movl %edx, 0x4(%rax)
movl 0x8(%rcx,%r12), %edx
movl %edx, 0x14(%rax)
movl (%rcx,%r12), %edx
movl %edx, 0xc(%rax)
movl 0x4(%rcx,%r12), %ecx
movl %ecx, 0x10(%rax)
incq %r13
addq $0x30, %r12
cmpq (%r15), %r13
jb 0xc4a83
incq %r14
movq 0x10(%rsp), %r15
cmpq %r15, %r14
jne 0xc4a11
cmpq $0x0, 0x50(%rsp)
je 0xc4c3e
movl $0x10, %ebx
xorl %r14d, %r14d
movq 0x40(%rsp), %rax
movq (%rax,%rbx), %rdi
callq 0x2220
incq %r14
addq $0x30, %rbx
cmpq 0x50(%rsp), %r14
jb 0xc4c22
movq 0x40(%rsp), %rdi
callq 0x2220
movq (%rsp), %rdi
callq 0x2220
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rax
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl 0x14(%rax), %esi
movq 0x8(%rsp), %rbx
movq %rbx, %rdi
callq 0xc405a
cmpq $0x0, 0x28(%rsp)
jne 0xc4e00
leaq 0x30(%rsp), %r14
movq 0x20(%r14), %r15
movl $0x18, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x48(%r14)
movabsq $0x3fe0000000000000, %rax # imm = 0x3FE0000000000000
movq %rax, 0x38(%r14)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x40(%r14)
movq 0x18(%r14), %rax
movq 0x18(%rax), %rcx
leaq 0x6d1(%rip), %r12       # 0xc538f
movl %r15d, %edi
movq %r12, %rsi
movq %r14, %rdx
callq 0x1047b4
movq %rbx, %rdi
callq 0xc44f2
movq %rax, 0x50(%r14)
movl 0x20(%r14), %edi
movq 0x18(%rax), %rcx
movq %r12, %rsi
movq %r14, %rdx
callq 0x1047b4
movq 0x50(%r14), %rax
movq 0x28(%rax), %rdi
callq 0x2220
movq 0x50(%r14), %rax
movq 0x10(%rax), %rdi
callq 0x2220
movq 0x50(%r14), %rdi
callq 0x2220
cmpq $0x0, 0x20(%r14)
je 0xc4d39
movl $0x10, %ebx
xorl %r14d, %r14d
movq 0x78(%rsp), %rax
movq (%rax,%rbx), %rdi
callq 0x2220
incq %r14
addq $0x18, %rbx
cmpq 0x50(%rsp), %r14
jb 0xc4d1d
movq 0x78(%rsp), %rdi
callq 0x2220
movq 0x8(%rsp), %r9
cmpq $0x0, (%r9)
je 0xc4d98
xorl %ecx, %ecx
xorl %eax, %eax
xorl %edx, %edx
movq 0x10(%r9), %rsi
cmpl $-0x1, 0x18(%rsi,%rcx)
je 0xc4d8a
leaq (%rsi,%rcx), %rdi
leaq (%rax,%rax,2), %r8
incq %rax
shlq $0x4, %r8
movups (%rdi), %xmm0
movups 0x10(%rdi), %xmm1
movups 0x20(%rdi), %xmm2
movups %xmm2, 0x20(%rsi,%r8)
movups %xmm1, 0x10(%rsi,%r8)
movups %xmm0, (%rsi,%r8)
incq %rdx
addq $0x30, %rcx
cmpq (%r9), %rdx
jb 0xc4d54
jmp 0xc4d9a
xorl %eax, %eax
movq %rax, (%r9)
testq %rax, %rax
je 0xc4e00
movl $0x1, %ecx
movl $0x38, %edx
xorl %esi, %esi
cmpq %rax, %rcx
je 0xc4dc9
movq 0x10(%r9), %rax
movl (%rax,%rdx), %edi
leaq (%rsi,%rsi,2), %r8
shlq $0x4, %r8
cmpl 0x8(%rax,%r8), %edi
je 0xc4df1
movq %rcx, %rax
subq %rsi, %rax
leaq (%rsi,%rsi,2), %rdi
shlq $0x20, %rsi
orq %rsi, %rax
movq 0x10(%r9), %rsi
movq 0x28(%r9), %r8
shlq $0x4, %rdi
movl 0x8(%rsi,%rdi), %esi
movq %rax, (%r8,%rsi,8)
movq %rcx, %rsi
incq %rcx
movq (%r9), %rax
addq $0x30, %rdx
cmpq %rax, %rcx
jbe 0xc4dae
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x165d5d(%rip), %rdi    # 0x22ab76
leaq 0x164e81(%rip), %rsi    # 0x229ca1
leaq 0x165dc6(%rip), %rcx    # 0x22abed
movl $0x3cb3, %edx           # imm = 0x3CB3
callq 0x2110
leaq 0x165ce7(%rip), %rdi    # 0x22ab1f
leaq 0x164e62(%rip), %rsi    # 0x229ca1
leaq 0x165da7(%rip), %rcx    # 0x22abed
movl $0x3cac, %edx           # imm = 0x3CAC
callq 0x2110