// File: /workspace/github_cpp_makefile_star2_O3/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
movups %xmm0, 0x48(%r12)
movups %xmm0, 0x38(%r12)
movq 0x18(%rsi), %rax
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl 0x14(%rax), %esi
callq 0xc4edd
leaq 0x1d016d(%rip), %rax    # 0x295758
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 0x620(%rip), %rsi       # 0xc5c6b
movl %ebp, %edi
movq %r12, %rdx
callq 0x108f2c
movq 0x20(%r12), %rcx
testq %rcx, %rcx
movq %rbx, 0x8(%rsp)
je 0xc579d
xorl %r9d, %r9d
xorl %r8d, %r8d
xorl %edi, %edi
xorl %ebp, %ebp
xorl %r14d, %r14d
movq 0x40(%rsp), %r11
leaq (%r14,%r14,2), %rdx
shlq $0x4, %rdx
movq (%r11,%rdx), %rax
testq %rax, %rax
je 0xc5787
addq %rdx, %r11
movl $0x1, %r12d
movl $0x38, %r15d
xorl %r13d, %r13d
movq %r11, 0x10(%rsp)
cmpq %rax, %r12
je 0xc56cc
movq 0x10(%r11), %rcx
movl (%rcx,%r15), %edx
leaq (,%r13,2), %rsi
addq %r13, %rsi
shlq $0x4, %rsi
cmpl 0x8(%rcx,%rsi), %edx
je 0xc5772
cmpq %r13, %r12
jbe 0xc576f
cmpl %r8d, %r9d
jne 0xc5713
movq %rbp, (%rsp)
leal (%r9,%r9), %ebp
testl %r9d, %r9d
movl $0x2, %eax
cmovel %eax, %ebp
leaq (,%rbp,8), %rax
leaq (%rax,%rax,2), %rsi
movq %r9, %rbx
callq 0x2370
movq 0x10(%rsp), %r11
movq %rbx, %r9
movq %rbp, %r8
movq (%rsp), %rbp
movq %rax, %rdi
movl %r9d, %eax
incl %r9d
leaq (%rax,%rax,2), %rax
movq 0x10(%r11), %rcx
leaq (,%r13,2), %rdx
addq %r13, %rdx
shlq $0x4, %rdx
movl 0x8(%rcx,%rdx), %ecx
shlq $0x20, %rcx
orq %r14, %rcx
movq %rcx, (%rdi,%rax,8)
movq %r13, %rcx
shrq $0x20, %rcx
movq 0x8(%rdi,%rax,8), %rdx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl $0x80000000, %edx       # imm = 0x80000000
orq %rcx, %rdx
subq %r13, %rbp
shlq $0x20, %r13
orq %rdx, %r13
movq %r13, 0x8(%rdi,%rax,8)
addq %r12, %rbp
movq (%r11), %rax
movq %r12, %r13
incq %r12
addq $0x30, %r15
cmpq %rax, %r12
jbe 0xc56a6
movq 0x50(%rsp), %rcx
incq %r14
cmpq %rcx, %r14
jb 0xc5675
addq %rbp, %rbp
movq 0x8(%rsp), %rbx
jmp 0xc57a4
xorl %ebp, %ebp
xorl %edi, %edi
xorl %r9d, %r9d
movl %r9d, %r14d
movq 0x30(%rsp), %rax
cmpq %r14, (%rax)
jb 0xc5c4c
leaq (%r14,%r14,2), %rax
leaq (%rdi,%rax,8), %rsi
movq %rdi, (%rsp)
callq 0x9ee5d
movq $0x0, (%rbx)
cmpq %rbp, 0x8(%rbx)
jae 0xc5823
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 %r14, %r14
movq (%rsp), %r9
je 0xc5a22
xorl %eax, %eax
movq %r14, 0x10(%rsp)
movq %rax, %r12
leaq (%rax,%rax,2), %rsi
movq 0x40(%rsp), %r15
movq (%r9,%rsi,8), %rdi
movq 0x8(%r9,%rsi,8), %rdx
movl %edi, %eax
leaq (%rax,%rax,2), %rax
movq %rdx, %r13
rolq $0x20, %r13
shlq $0x4, %rax
btrq $0x3f, %r13
movq 0x10(%r15,%rax), %rcx
leaq (,%r13,2), %r8
addq %r13, %r8
shlq $0x4, %r8
shrq $0x20, %rdi
cmpl 0x8(%rcx,%r8), %edi
jne 0xc5c2d
addq %rax, %r15
movq (%r15), %rax
cmpq %rax, %r13
jae 0xc5a0e
leaq (%r9,%rsi,8), %r14
leaq (%rdx,%rdx,2), %rsi
shrq $0x20, %rdx
shlq $0x24, %rsi
leaq (%rdx,%rdx,2), %rbp
shlq $0x4, %rbp
addq %rsi, %rbp
movl 0x8(%rcx,%rbp), %edx
cmpl %edx, 0x4(%r14)
jne 0xc5a0e
cmpl 0x14(%rcx,%rbp), %edx
je 0xc59fe
movq (%rbx), %rdx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rdx
jne 0xc5903
leaq (%rdx,%rdx), %rcx
testq %rdx, %rdx
movl $0x2, %edx
cmoveq %rdx, %rcx
movq %rcx, 0x8(%rbx)
shlq $0x4, %rcx
leaq (%rcx,%rcx,2), %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rdx
movq 0x10(%r15), %rcx
leaq 0x1(%rdx), %rsi
movq %rsi, (%rbx)
leaq (%rdx,%rdx,2), %rdx
shlq $0x4, %rdx
movups (%rcx,%rbp), %xmm0
movups 0x10(%rcx,%rbp), %xmm1
movups 0x20(%rcx,%rbp), %xmm2
movups %xmm1, 0x10(%rax,%rdx)
movups %xmm2, 0x20(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
movl $0x0, 0x18(%rax,%rdx)
movb 0x28(%rax,%rdx), %cl
movl %ecx, %esi
andb $0x3f, %sil
cmpb $0x3, %sil
jne 0xc594f
addq %rdx, %rax
andb $-0x3e, %cl
movb %cl, 0x28(%rax)
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0xc5987
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rbx)
shlq $0x4, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
movq (%rsp), %r9
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
leaq (%rax,%rcx), %rdx
movq 0x10(%r15), %rsi
movups (%rsi,%rbp), %xmm0
movups 0x10(%rsi,%rbp), %xmm1
movups 0x20(%rsi,%rbp), %xmm2
movups %xmm1, 0x10(%rax,%rcx)
movups %xmm2, 0x20(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movl $0x0, 0x18(%rax,%rcx)
movb 0x28(%rax,%rcx), %al
movl %eax, %ecx
andb $0x3f, %cl
cmpb $0x3, %cl
jne 0xc59d9
andb $-0x3e, %al
movb %al, 0x28(%rdx)
movq 0x10(%r15), %rcx
movl 0x14(%rcx,%rbp), %eax
movl %eax, 0x8(%rdx)
movq 0xc(%rcx,%rbp), %rax
movq %rax, (%rdx)
movl 0x8(%rcx,%rbp), %eax
movl %eax, 0x14(%rdx)
movq (%rcx,%rbp), %rax
movq %rax, 0xc(%rdx)
movq (%r15), %rax
incq %r13
addq $0x30, %rbp
cmpq %rax, %r13
jb 0xc58af
movq %r12, %rax
incq %rax
movq 0x10(%rsp), %r14
cmpq %r14, %rax
jne 0xc5837
cmpq $0x0, 0x50(%rsp)
je 0xc5a4e
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 0xc5a32
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 0xc4edd
cmpq $0x0, 0x28(%rsp)
je 0xc5a99
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
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 0x67d(%rip), %r12       # 0xc6159
movl %r15d, %edi
movq %r12, %rsi
movq %r14, %rdx
callq 0x108f2c
movq %rbx, %rdi
callq 0xc530f
movq %rax, 0x50(%r14)
movl 0x20(%r14), %edi
movq 0x18(%rax), %rcx
movq %r12, %rsi
movq %r14, %rdx
callq 0x108f2c
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 0xc5b57
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 0xc5b3b
movq 0x78(%rsp), %rdi
callq 0x2220
movq 0x8(%rsp), %r9
movq (%r9), %rsi
testq %rsi, %rsi
je 0xc5a87
xorl %ecx, %ecx
xorl %eax, %eax
xorl %edx, %edx
movq 0x10(%r9), %rdi
cmpl $-0x1, 0x18(%rdi,%rcx)
je 0xc5bb1
leaq (%rdi,%rcx), %rsi
leaq (%rax,%rax,2), %r8
incq %rax
shlq $0x4, %r8
movups (%rsi), %xmm0
movups 0x10(%rsi), %xmm1
movups 0x20(%rsi), %xmm2
movups %xmm2, 0x20(%rdi,%r8)
movups %xmm1, 0x10(%rdi,%r8)
movups %xmm0, (%rdi,%r8)
movq (%r9), %rsi
incq %rdx
addq $0x30, %rcx
cmpq %rsi, %rdx
jb 0xc5b78
movq %rax, (%r9)
testq %rax, %rax
je 0xc5a87
movq 0x10(%r9), %rcx
leaq 0x38(%rcx), %rdx
movl $0x1, %esi
xorl %edi, %edi
cmpq %rax, %rsi
jne 0xc5bec
leaq (%rdi,%rdi,2), %rax
shlq $0x4, %rax
movl 0x8(%rcx,%rax), %r8d
jmp 0xc5bfe
leaq (%rdi,%rdi,2), %r8
shlq $0x4, %r8
movl 0x8(%rcx,%r8), %r8d
cmpl %r8d, (%rdx)
je 0xc5c1c
movq %rsi, %rax
subq %rdi, %rax
shlq $0x20, %rdi
orq %rax, %rdi
movq 0x28(%r9), %rax
movl %r8d, %r8d
movq %rdi, (%rax,%r8,8)
movq (%r9), %rax
movq %rsi, %rdi
incq %rsi
addq $0x30, %rdx
cmpq %rax, %rsi
jbe 0xc5bd8
jmp 0xc5a87
leaq 0x171132(%rip), %rdi    # 0x236d66
leaq 0x170256(%rip), %rsi    # 0x235e91
leaq 0x17119b(%rip), %rcx    # 0x236ddd
movl $0x3cb3, %edx           # imm = 0x3CB3
callq 0x2110
leaq 0x1710bc(%rip), %rdi    # 0x236d0f
leaq 0x170237(%rip), %rsi    # 0x235e91
leaq 0x17117c(%rip), %rcx    # 0x236ddd
movl $0x3cac, %edx           # imm = 0x3CAC
callq 0x2110