// File: /workspace/github_cpp_makefile_star2_O2/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, 0x10(%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 0x88a31
leaq 0x1ca4dd(%rip), %rax    # 0x253758
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)
pushq $0x30
popq %rsi
movq %rbp, %rdi
callq 0x2120
movq %rax, 0x10(%r12)
movq $0x3, 0x28(%r12)
movabsq $0x3fe999999999999a, %rax # imm = 0x3FE999999999999A
movq %rax, 0x30(%r12)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x40(%r12)
movq %rbx, 0x18(%rsp)
movq 0x18(%rbx), %rcx
leaq 0x566(%rip), %rsi       # 0x89844
movl %ebp, %edi
movq %r12, %rdx
callq 0xc67c0
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %edi, %edi
xorl %eax, %eax
xorl %r13d, %r13d
cmpq 0x50(%rsp), %r15
jae 0x893e1
movq 0x40(%rsp), %r11
imulq $0x30, %r15, %rdx
movq (%r11,%rdx), %rcx
testq %rcx, %rcx
je 0x893d9
addq %rdx, %r11
pushq $0x38
popq %r14
pushq $0x1
popq %rbx
xorl %r12d, %r12d
movq %r11, 0x8(%rsp)
cmpq %rcx, %rbx
ja 0x893d9
je 0x89349
movq 0x10(%r11), %rdx
movl (%rdx,%r14), %esi
imulq $0x30, %r12, %r8
cmpl 0x8(%rdx,%r8), %esi
je 0x893cd
cmpq %r12, %rbx
jbe 0x893ca
cmpl %eax, %r13d
jne 0x89379
movq %rbp, (%rsp)
leal (%rax,%rax), %ebp
testl %eax, %eax
pushq $0x2
popq %rax
cmovel %eax, %ebp
imulq $0x18, %rbp, %rsi
callq 0x2370
movq 0x8(%rsp), %r11
movq %rax, %rdi
movl %ebp, %eax
movq (%rsp), %rbp
movl %r13d, %ecx
incl %r13d
imulq $0x18, %rcx, %rcx
movq 0x10(%r11), %rdx
imulq $0x30, %r12, %rsi
movl 0x8(%rdx,%rsi), %edx
shlq $0x20, %rdx
orq %r15, %rdx
movq %rdx, (%rdi,%rcx)
movq %r12, %rdx
shrq $0x20, %rdx
movq 0x8(%rdi,%rcx), %rsi
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl $0x80000000, %esi       # imm = 0x80000000
orq %rdx, %rsi
subq %r12, %rbp
shlq $0x20, %r12
orq %rsi, %r12
movq %r12, 0x8(%rdi,%rcx)
addq %rbx, %rbp
movq (%r11), %rcx
movq %rbx, %r12
incq %rbx
addq $0x30, %r14
jmp 0x89327
incq %r15
jmp 0x892f4
movl %r13d, %ebx
movq 0x30(%rsp), %rax
cmpq %rbx, (%rax)
movq 0x18(%rsp), %r12
jb 0x89825
imulq $0x18, %rbx, %rsi
addq %rdi, %rsi
movq %rdi, (%rsp)
callq 0x67d37
andq $0x0, (%r12)
addq %rbp, %rbp
cmpq %rbp, 0x8(%r12)
jae 0x89465
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(%r12)
movq 0x10(%r12), %rdi
imulq $0x30, %rax, %rsi
callq 0x2370
movq %rax, 0x10(%r12)
xorl %eax, %eax
movq (%rsp), %r8
movq %rbx, 0x8(%rsp)
cmpq %rbx, %rax
je 0x8963f
movq %rax, %rbx
imulq $0x18, %rax, %r14
movq 0x40(%rsp), %r13
movq (%r8,%r14), %rsi
movq 0x8(%r8,%r14), %rax
movl %esi, %ecx
imulq $0x30, %rcx, %rdx
movq %rax, %r15
rolq $0x20, %r15
btrq $0x3f, %r15
movq 0x10(%r13,%rdx), %rcx
imulq $0x30, %r15, %rdi
shrq $0x20, %rsi
cmpl 0x8(%rcx,%rdi), %esi
jne 0x89806
addq %r8, %r14
addq %rdx, %r13
movq %rax, %rdx
shrq $0x20, %rdx
movabsq $0x3000000000, %rsi     # imm = 0x3000000000
imulq %rsi, %rax
imulq $0x30, %rdx, %rbp
addq %rax, %rbp
cmpq (%r13), %r15
jae 0x8962f
movl 0x8(%rcx,%rbp), %eax
cmpl %eax, 0x4(%r14)
jne 0x8962f
cmpl 0x14(%rcx,%rbp), %eax
je 0x89623
movq (%r12), %rdx
movq 0x10(%r12), %rax
cmpq 0x8(%r12), %rdx
jne 0x89537
leaq (%rdx,%rdx), %rcx
testq %rdx, %rdx
pushq $0x2
popq %rdx
cmoveq %rdx, %rcx
movq %rcx, 0x8(%r12)
imulq $0x30, %rcx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rdx
movq 0x10(%r13), %rcx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r12)
imulq $0x30, %rdx, %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)
andl $0x0, 0x18(%rax,%rdx)
movb 0x28(%rax,%rdx), %cl
movl %ecx, %esi
andb $0x3f, %sil
cmpb $0x3, %sil
jne 0x8957d
addq %rdx, %rax
andb $-0x3e, %cl
movb %cl, 0x28(%rax)
movq (%r12), %rcx
movq 0x10(%r12), %rax
cmpq 0x8(%r12), %rcx
jne 0x895b5
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%r12)
imulq $0x30, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rcx
movq (%rsp), %r8
leaq 0x1(%rcx), %rdx
movq %rdx, (%r12)
imulq $0x30, %rcx, %rcx
leaq (%rax,%rcx), %rdx
movq 0x10(%r13), %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)
andl $0x0, 0x18(%rax,%rcx)
movb 0x28(%rax,%rcx), %al
movl %eax, %ecx
andb $0x3f, %cl
cmpb $0x3, %cl
jne 0x89601
andb $-0x3e, %al
movb %al, 0x28(%rdx)
movq 0x10(%r13), %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)
incq %r15
addq $0x30, %rbp
jmp 0x894d9
movq %rbx, %rax
incq %rax
movq 0x8(%rsp), %rbx
jmp 0x89470
pushq $0x10
popq %rbx
xorl %r14d, %r14d
movq 0x40(%rsp), %rdi
cmpq 0x50(%rsp), %r14
jae 0x89663
movq (%rdi,%rbx), %rdi
callq 0x2220
incq %r14
addq $0x30, %rbx
jmp 0x89645
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 %r12, %rdi
callq 0x88a31
cmpq $0x0, 0x28(%rsp)
je 0x896a4
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x30(%rsp), %r14
movq 0x20(%r14), %r15
pushq $0x18
popq %rsi
movq %r15, %rdi
callq 0x2120
movq %rax, 0x48(%r14)
movabsq $0x3fe0000000000000, %rax # imm = 0x3FE0000000000000
movq %rax, 0x38(%r14)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x40(%r14)
movq 0x18(%r14), %rax
movq 0x18(%rax), %rcx
movq %r12, %rbx
leaq 0x60a(%rip), %r12       # 0x89cf2
movl %r15d, %edi
movq %r12, %rsi
movq %r14, %rdx
callq 0xc67c0
movq %rbx, %rdi
callq 0x89002
movq %rax, 0x50(%r14)
movl 0x20(%r14), %edi
movq 0x18(%rax), %rcx
movq %r12, %rsi
movq %r14, %rdx
callq 0xc67c0
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
pushq $0x10
popq %rbx
xorl %r14d, %r14d
movq 0x78(%rsp), %rdi
cmpq 0x50(%rsp), %r14
jae 0x8975c
movq (%rdi,%rbx), %rdi
callq 0x2220
incq %r14
addq $0x18, %rbx
jmp 0x8973e
callq 0x2220
xorl %ecx, %ecx
xorl %edx, %edx
xorl %eax, %eax
movq 0x18(%rsp), %r9
cmpq (%r9), %rdx
jae 0x897ac
movq 0x10(%r9), %rsi
cmpl $-0x1, 0x18(%rsi,%rcx)
je 0x897a3
leaq (%rsi,%rcx), %rdi
imulq $0x30, %rax, %r8
incq %rax
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
jmp 0x8976c
movq %rax, (%r9)
pushq $0x1
popq %rcx
pushq $0x38
popq %rdx
xorl %esi, %esi
cmpq %rax, %rcx
ja 0x89692
movq 0x10(%r9), %r8
jne 0x897d1
imulq $0x30, %rsi, %rax
movl 0x8(%r8,%rax), %edi
jmp 0x897e0
imulq $0x30, %rsi, %rdi
movl 0x8(%r8,%rdi), %edi
cmpl %edi, (%r8,%rdx)
je 0x897fd
movq %rcx, %rax
subq %rsi, %rax
shlq $0x20, %rsi
orq %rax, %rsi
movq 0x28(%r9), %rax
movl %edi, %edi
movq %rsi, (%rax,%rdi,8)
movq (%r9), %rax
movq %rcx, %rsi
incq %rcx
addq $0x30, %rdx
jmp 0x897b7
leaq 0x15f459(%rip), %rdi    # 0x1e8c66
leaq 0x15e57d(%rip), %rsi    # 0x1e7d91
leaq 0x15f4c2(%rip), %rcx    # 0x1e8cdd
movl $0x3cb3, %edx           # imm = 0x3CB3
callq 0x2110
leaq 0x15f3e3(%rip), %rdi    # 0x1e8c0f
leaq 0x15e55e(%rip), %rsi    # 0x1e7d91
leaq 0x15f4a3(%rip), %rcx    # 0x1e8cdd
movl $0x3cac, %edx           # imm = 0x3CAC
callq 0x2110