// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: worker_for_trans_clean(void*, long, int)
static void worker_for_trans_clean(void *data, long i, int tid) // callback for kt_for()
{
    u_trans_clean_t *s = (u_trans_clean_t*)data;
    kv_u_trans_t *ta = s->ta;
    kv_u_trans_t *res = &(s->res[tid]);
    u_trans_t *a = NULL, *r_a = NULL, *mz, *cz;
    uint32_t n, r_n, id = i, k, l, z;

    a = u_trans_a(*ta, id); n = u_trans_n(*ta, id);
    for (k = 1, l = 0; k <= n; k++) {
        if(k == n || a[l].tn != a[k].tn) {
            if(k > l) {
                get_u_trans_spec(ta, a[l].tn, a[l].qn, &r_a, &r_n);
                if(r_n > 0 && id > a[l].tn) {
                    l = k; continue;
                }
                mz = cz = NULL; 
                for (z = l; z < k; z++) {
                    cz = &(a[z]);
                    // fprintf(stderr, ">[M::%s::] qn::%u, tn::%u, cz->nw::%f, cz->f::%u\n", 
                    //     __func__, a[l].qn, a[l].tn, cz->nw, cz->f);
                    if(mz) {
                        if((mz->f == RC_0) && (cz->f != RC_0)) continue;
                        if((mz->f == RC_1) && ((cz->f == RC_2) || (cz->f == RC_3))) continue;
                    }
                    if((!mz) || ((cz->f < mz->f) && ((cz->f == RC_0) || (cz->f == RC_1))) || 
                        (mz->nw < cz->nw) || ((mz->nw == cz->nw) && ((mz->qe - mz->qs) < (cz->qe - cz->qs)))) {
                        // fprintf(stderr, "+[M::%s::] qn::%u, tn::%u, mz->nw::%f, mz->f::%u, cz->nw::%f, cz->f::%u\n", 
                        // __func__, a[l].qn, a[l].tn, mz?mz->nw:-1, mz?mz->f:255, cz->nw, cz->f);
                        mz = cz; 
                    }
                }
                for (z = 0; z < r_n; z++) {
                    cz = &(r_a[z]);
                    if(mz) {
                        if((mz->f == RC_0) && (cz->f != RC_0)) continue;
                        if((mz->f == RC_1) && ((cz->f == RC_2) || (cz->f == RC_3))) continue;
                    }
                    if((!mz) || ((cz->f < mz->f) && ((cz->f == RC_0) || (cz->f == RC_1))) || 
                        (mz->nw < cz->nw) || ((mz->nw == cz->nw) && ((mz->qe - mz->qs) < (cz->te - cz->ts)))) {
                        ///note here is (cz->te - cz->ts)
                        // fprintf(stderr, "-[M::%s::] qn::%u, tn::%u, mz->nw::%f, mz->f::%u, cz->nw::%f, cz->f::%u\n", 
                        // __func__, a[l].qn, a[l].tn, mz?mz->nw:-1, mz?mz->f:255, cz->nw, cz->f);
                        mz = cz;
                    }
                }
                
                // fprintf(stderr, "-[M::%s::] is_mz::%u, qn::%u, tn::%u\n", __func__, (uint32_t)(!!mz), mz->qn, mz->tn);
                if((mz) && (mz->qn != mz->tn)) {
                    ///need to check it cover enough reads
                    kv_pushp(u_trans_t, *res, &cz); (*cz) = (*mz);
                    if(mz->qn != id) {
                        cz->qn = mz->tn; cz->qs = mz->ts; cz->qe = mz->te;
                        cz->tn = mz->qn; cz->ts = mz->qs; cz->te = mz->qe;
                    } 

                    if((cz->nw >= 0) && ((!trans_ovlp_connect1(cz, s->ug)) 
                                    || (!ovlp_rocc(cz, s->ug, s->rg, s->small_ov_rate, s->ov_cutoff)))) {  
                        // if(mz->qn == 43 && mz->tn == 45) {
                        //     fprintf(stderr, "-[M::%s::] utg%.6u%c\t%u\t%u\t%u\t%c\tutg%.6u%c\t%u\t%u\t%u\n", __func__,
                        //     mz->qn+1, "lc"[s->ug->u.a[mz->qn].circ], s->ug->u.a[mz->qn].len, mz->qs, mz->qe, 
                        //     "+-"[mz->rev],
                        //     mz->tn+1, "lc"[s->ug->u.a[mz->tn].circ], s->ug->u.a[mz->tn].len, mz->ts, mz->te);
                        // } 
                        
                        res->n--;
                    } 
                    // else {
                    //     if(mz->qn == 43 && mz->tn == 45) {
                    //         fprintf(stderr, "+[M::%s::] utg%.6u%c\t%u\t%u\t%u\t%c\tutg%.6u%c\t%u\t%u\t%u\tf::%u\n", __func__,
                    //         mz->qn+1, "lc"[s->ug->u.a[mz->qn].circ], s->ug->u.a[mz->qn].len, mz->qs, mz->qe, 
                    //         "+-"[mz->rev], mz->tn+1, "lc"[s->ug->u.a[mz->tn].circ], s->ug->u.a[mz->tn].len, mz->ts, mz->te, mz->f);
                    //     }
                    // }
                }
            }
            l = k;
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq 0x18(%rdi), %r8
movslq %edx, %rax
imulq $0x30, %rax, %rax
movq %rdi, 0x18(%rsp)
addq 0x10(%rdi), %rax
movq %rax, 0x8(%rsp)
leaq 0x28(%rsp), %rax
andq $0x0, (%rax)
movq 0x28(%r8), %rax
movq %rsi, 0x20(%rsp)
movl %esi, %ecx
movq (%rax,%rcx,8), %r9
movq %r9, %rax
shrq $0x20, %rax
imulq $0x30, %rax, %rbx
movq %r8, 0x30(%rsp)
addq 0x10(%r8), %rbx
xorl %ecx, %ecx
pushq $0x1
popq %r13
movq %r9, (%rsp)
cmpl %r9d, %r13d
ja 0x88df1
movl %ecx, %r15d
movl %r13d, %r12d
je 0x88b94
imulq $0x30, %r15, %rax
movl 0x14(%rbx,%rax), %eax
imulq $0x30, %r12, %rdx
cmpl 0x14(%rbx,%rdx), %eax
je 0x88de9
cmpl %ecx, %r13d
movl %r13d, %ecx
jbe 0x88de9
imulq $0x30, %r15, %r14
movl 0x8(%rbx,%r14), %edx
movl 0x14(%rbx,%r14), %ebp
movq 0x30(%rsp), %rdi
movl %ebp, %esi
leaq 0x28(%rsp), %rcx
leaq 0x14(%rsp), %r8
callq 0x8feef
movq (%rsp), %r9
movl 0x14(%rsp), %eax
testq %rax, %rax
je 0x88bde
movl %r13d, %ecx
cmpl 0x20(%rsp), %ebp
jb 0x88de9
addq %rbx, %r14
xorl %ebp, %ebp
cmpq %r12, %r15
jae 0x88c5c
testq %rbp, %rbp
je 0x88c50
movzbl 0x28(%rbp), %ecx
andl $0x3f, %ecx
movb 0x28(%r14), %dl
cmpl $0x1, %ecx
je 0x88c08
testl %ecx, %ecx
jne 0x88c14
testb $0x3f, %dl
jne 0x88c53
jmp 0x88c14
movl %edx, %esi
andb $0x3e, %sil
cmpb $0x2, %sil
je 0x88c53
andb $0x3f, %dl
cmpb %cl, %dl
setb %cl
cmpb $0x2, %dl
setb %dl
testb %dl, %cl
jne 0x88c50
movsd 0x20(%rbp), %xmm0
movsd 0x20(%r14), %xmm1
ucomisd %xmm0, %xmm1
ja 0x88c50
ucomisd %xmm1, %xmm0
jne 0x88c53
jp 0x88c53
movl 0x4(%rbp), %ecx
subl (%rbp), %ecx
movl 0x4(%r14), %edx
subl (%r14), %edx
cmpl %edx, %ecx
jae 0x88c53
movq %r14, %rbp
incq %r15
addq $0x30, %r14
jmp 0x88be3
movq 0x28(%rsp), %rcx
subq $0x1, %rax
jb 0x88cdc
testq %rbp, %rbp
je 0x88cd3
movzbl 0x28(%rbp), %edx
andl $0x3f, %edx
movb 0x28(%rcx), %sil
cmpl $0x1, %edx
je 0x88c88
testl %edx, %edx
jne 0x88c94
testb $0x3f, %sil
jne 0x88cd6
jmp 0x88c94
movl %esi, %edi
andb $0x3e, %dil
cmpb $0x2, %dil
je 0x88cd6
andb $0x3f, %sil
cmpb %dl, %sil
setb %dl
cmpb $0x2, %sil
setb %sil
testb %sil, %dl
jne 0x88cd3
movsd 0x20(%rbp), %xmm0
movsd 0x20(%rcx), %xmm1
ucomisd %xmm0, %xmm1
ja 0x88cd3
ucomisd %xmm1, %xmm0
jne 0x88cd6
jp 0x88cd6
movl 0x4(%rbp), %edx
subl (%rbp), %edx
movl 0x10(%rcx), %esi
subl 0xc(%rcx), %esi
cmpl %esi, %edx
jae 0x88cd6
movq %rcx, %rbp
addq $0x30, %rcx
jmp 0x88c61
movl %r13d, %ecx
testq %rbp, %rbp
je 0x88de9
movl 0x8(%rbp), %eax
movl %r13d, %ecx
cmpl 0x14(%rbp), %eax
je 0x88de9
movq 0x8(%rsp), %rsi
movq (%rsi), %rcx
movq 0x10(%rsi), %rax
cmpq 0x8(%rsi), %rcx
jne 0x88d37
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x8(%rsi)
imulq $0x30, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq (%rsp), %r9
movq 0x8(%rsp), %rsi
movq %rax, 0x10(%rsi)
movq (%rsi), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rsi)
imulq $0x30, %rcx, %rcx
leaq (%rax,%rcx), %r15
movups (%rbp), %xmm0
movupd 0x10(%rbp), %xmm1
movups 0x20(%rbp), %xmm2
movups %xmm2, 0x20(%rax,%rcx)
movupd %xmm1, 0x10(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movq 0x20(%rsp), %rax
cmpl %eax, 0x8(%rbp)
je 0x88d89
movl 0x14(%rbp), %eax
movl %eax, 0x8(%r15)
movq 0xc(%rbp), %rax
movq %rax, (%r15)
movl 0x8(%rbp), %eax
movl %eax, 0x14(%r15)
movq (%rbp), %rax
movq %rax, 0xc(%r15)
movsd 0x20(%r15), %xmm0
ucomisd 0x15a7d1(%rip), %xmm0   # 0x1e3568
movl %r13d, %ecx
jb 0x88de9
movq 0x18(%rsp), %rax
movq (%rax), %r14
movq %r15, %rdi
movq %r14, %rsi
callq 0x875c0
movq (%rsp), %r9
testl %eax, %eax
je 0x88dde
movq 0x18(%rsp), %rax
movq 0x8(%rax), %rdx
movsd 0x30(%rax), %xmm0
movl 0x28(%rax), %ecx
movq %r15, %rdi
movq %r14, %rsi
callq 0x8775f
movq (%rsp), %r9
movl %r13d, %ecx
testl %eax, %eax
jne 0x88de9
movq 0x8(%rsp), %rax
decq (%rax)
movl %r13d, %ecx
incl %r13d
jmp 0x88b6d
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq