// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: worker_for_trans_sec_cut(void*, long, int)
static void worker_for_trans_sec_cut(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;
    asg64_v *srt = &(s->srt[tid]);
    u_trans_t *a = NULL, *mz, *cz, t;
    uint32_t n, r_n, id = i, k, l, z, m, wm, wl, len;
    uint32_t ovq, os, oe; uint64_t *ss, *hs, *bu, *wu;

    if(!(s->cu)) {
        a = u_trans_a(*ta, id); n = u_trans_n(*ta, id);
        for (k = r_n = 0; k < n; k++) {///RC_0/RC_1 to a[0, r_n)
            if((a[k].f == RC_0) || (a[k].f == RC_1)) {
                if(k != r_n) {
                    t = a[k]; a[k] = a[r_n]; a[r_n] = t;
                }
                r_n++;
            }
        }
        if(r_n >= n) return;
        if(n-r_n > 1) qsort(a+r_n, n-r_n, sizeof((*a)), cmp_u_trans_weight);
        // if(id == 3924 || id == 160) {
        //     fprintf(stderr, "[M::%s::]\tutg%.6u%c\tr_n::%u\tn::%u\n", __func__,
        //              id + 1, "lc"[s->ug->u.a[id].circ], r_n, n);
        //     for (k = 0; k < n; k++) {
        //         fprintf(stderr, "+[%u]\tutg%.6u%c\t%u\t%u\t%u\t%c\tutg%.6u%c\t%u\t%u\t%u\tnw::%f\tf::%u\n", k,
        //              a[k].qn+1, "lc"[s->ug->u.a[a[k].qn].circ], s->ug->u.a[a[k].qn].len, a[k].qs, a[k].qe, "+-"[a[k].rev],
        //              a[k].tn+1, "lc"[s->ug->u.a[a[k].tn].circ], s->ug->u.a[a[k].tn].len, a[k].ts, a[k].te, a[k].nw, a[k].f);
        //     }
        // }
        srt->n = 0; kv_resize(uint64_t, *srt, (n<<2));
        for (k = 0; k < n; k++) {
            srt->a[srt->n] = a[k].qs;
            srt->a[srt->n] <<= 32;
            srt->a[srt->n] |= k;
            srt->n++;
        }
        ss = srt->a; hs = ss + srt->n; bu = hs + srt->n; wu = bu + srt->n;
        radix_sort_arch64(ss, ss+n);
        for (k = 0; k < n; k++) {
            ss[k] = (uint32_t)ss[k]; hs[ss[k]] = k;
        }
        for (k = r_n; k < n; k++) {
            cz = &(a[k]); len = (cz->qe-cz->qs)*s->sec_rate; m = wm = 0;
            for (z = l = wl = 0; z < n; z++) {
                if(z == hs[k]) {
                    assert(ss[z] == k);
                    continue;
                }
                if(ss[z] > k) continue;///smaller nw than a[k]
                mz = &(a[ss[z]]);
                if(mz->qs >= cz->qe) break;
                if(mz->occ == ((uint32_t)-1)) continue;///has been deleted
                if((mz->f != RC_0) && (mz->f != RC_1) && (cz->nw > (mz->nw*s->sc_sec_rate/**0.95**/))) continue;
                os = MAX(cz->qs, mz->qs); oe = MIN(cz->qe, mz->qe);
                ovq = ((oe > os)? (oe - os):0);
                if(!ovq) continue;
                if(is_connect_arc(cz, mz, s->ug, 0.04) || is_connect_arc(mz, cz, s->ug, 0.04)) continue;

                if((m > 0) && (((uint32_t)bu[m-1]) >= os)) {
                    if(oe > ((uint32_t)bu[m-1])) {
                        l += (oe - ((uint32_t)bu[m-1]));
                        bu[m-1] += (oe - ((uint32_t)bu[m-1]));
                    }
                } else {
                    l += oe - os;
                    bu[m] = os; bu[m] <<= 32; bu[m] |= oe; m++;
                }

                if((wm > 0) && (((uint32_t)wu[wm-1]) >= mz->qs)) {
                    if(mz->qe > ((uint32_t)wu[wm-1])) {
                        wl += (mz->qe - ((uint32_t)wu[wm-1]));
                        wu[wm-1] += (mz->qe - ((uint32_t)wu[wm-1]));
                    }
                } else {
                    wl += mz->qe - mz->qs;
                    wu[wm] = mz->qs; wu[wm] <<= 32; wu[wm] |= mz->qe; wm++;
                }

                if((l > 0) && ((l>=len) || (l>=(wl*s->sec_rate)))) {
                    // if((cz->qn == 3924 && cz->tn == 160) || (cz->tn == 3924 && cz->qn == 160)) {
                    //     fprintf(stderr, "[M::%s]\tutg%.6u%c\t->\tutg%.6u%c\tl::%u\tlen::%u\twl::%u\tsec_rate::%f\n", __func__, 
                    //     cz->qn+1, "lc"[s->ug->u.a[cz->qn].circ], 
                    //     cz->tn+1, "lc"[s->ug->u.a[cz->tn].circ],
                    //     l, len, wl, s->sec_rate);
                    // }
                    cz->occ = ((uint32_t)-1);
                    break;
                }
            }        
        }
        // if(id == 3924 || id == 160) {
        //     for (k = 0; k < n; k++) {
        //         fprintf(stderr, "-[%u]\tutg%.6u%c\t%u\t%u\t%u\t%c\tutg%.6u%c\t%u\t%u\t%u\tnw::%f\tf::%u\tdel::%u\n", k,
        //              a[k].qn+1, "lc"[s->ug->u.a[a[k].qn].circ], s->ug->u.a[a[k].qn].len, a[k].qs, a[k].qe, "+-"[a[k].rev],
        //              a[k].tn+1, "lc"[s->ug->u.a[a[k].tn].circ], s->ug->u.a[a[k].tn].len, a[k].ts, a[k].te, a[k].nw, a[k].f,
        //              (a[k].occ == ((uint32_t)-1))?1:0);
        //     }
        // }
    } else {
        assert(((uint32_t)(s->cu->idx.a[id])) > (s->cu->idx.a[id]>>32)+1);
        for (z = (s->cu->idx.a[id]>>32); z < ((uint32_t)(s->cu->idx.a[id])); z++) {
            a = u_trans_a(*ta, ((uint32_t)s->cu->z.a[z])); 
            n = u_trans_n(*ta, ((uint32_t)s->cu->z.a[z])); 
            for (k = 0; k < n; k++) deep_clean_u_trans(ta, &(a[k]), s->ug, srt, 3000000, 0.5);
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %rbx
movq 0x18(%rdi), %r14
movslq %edx, %rax
imulq $0x18, %rax, %r15
addq 0x48(%rdi), %r15
movq 0x50(%rdi), %rax
testq %rax, %rax
je 0x89dca
movq 0x28(%rax), %rcx
movl %esi, %edx
movq %rdx, 0x18(%rsp)
movq (%rcx,%rdx,8), %rcx
movl %ecx, %edx
movq %rcx, %rbp
shrq $0x20, %rbp
leaq 0x1(%rbp), %rsi
cmpq %rsi, %rdx
ja 0x89dbe
leaq 0x16130c(%rip), %rdi    # 0x1eb056
leaq 0x15e040(%rip), %rsi    # 0x1e7d91
leaq 0x1612cd(%rip), %rcx    # 0x1eb025
movl $0x3bad, %edx           # imm = 0x3BAD
callq 0x2110
movq 0x28(%r14), %rcx
movq 0x10(%rax), %rax
movl (%rax,%rbp,8), %eax
movq (%rcx,%rax,8), %rax
movl %eax, %r13d
shrq $0x20, %rax
imulq $0x30, %rax, %r12
addq 0x10(%r14), %r12
subq $0x1, %r13
jb 0x89dab
movq (%rbx), %rdx
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rcx
movl $0x2dc6c0, %r8d         # imm = 0x2DC6C0
movsd 0x1597a8(%rip), %xmm0   # 0x1e3548
callq 0x87d2f
addq $0x30, %r12
jmp 0x89d80
incq %rbp
movq 0x50(%rbx), %rax
movq 0x28(%rax), %rcx
movq 0x18(%rsp), %rdx
movl (%rcx,%rdx,8), %ecx
movl %ecx, %ecx
cmpq %rcx, %rbp
jb 0x89d62
jmp 0x8a2e6
movq 0x28(%r14), %rax
movl %esi, %ecx
movq (%rax,%rcx,8), %rcx
movq %rcx, %rax
shrq $0x20, %rax
imulq $0x30, %rax, %rsi
addq 0x10(%r14), %rsi
movq %rcx, 0x38(%rsp)
movl %ecx, %r8d
xorl %eax, %eax
movq %rsi, %rcx
xorl %ebp, %ebp
movl %ebp, %edx
cmpq %rax, %r8
je 0x89e80
testb $0x3e, 0x28(%rcx)
jne 0x89e74
cmpq %rdx, %rax
je 0x89e72
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movaps %xmm2, 0xc0(%rsp)
movaps %xmm1, 0xb0(%rsp)
movaps %xmm0, 0xa0(%rsp)
imulq $0x30, %rdx, %rdx
movups (%rsi,%rdx), %xmm0
movups 0x10(%rsi,%rdx), %xmm1
movups 0x20(%rsi,%rdx), %xmm2
movups %xmm2, 0x20(%rcx)
movups %xmm1, 0x10(%rcx)
movups %xmm0, (%rcx)
movaps 0xa0(%rsp), %xmm0
movapd 0xb0(%rsp), %xmm1
movapd 0xc0(%rsp), %xmm2
movupd %xmm2, 0x20(%rsi,%rdx)
movupd %xmm1, 0x10(%rsi,%rdx)
movups %xmm0, (%rsi,%rdx)
incl %ebp
incq %rax
addq $0x30, %rcx
jmp 0x89df2
movq 0x38(%rsp), %rax
subl %ebp, %eax
jbe 0x8a2e6
cmpl $0x2, %eax
movq %rsi, 0x28(%rsp)
movq %r8, 0x20(%rsp)
jb 0x89ebe
imulq $0x30, %rdx, %rdi
addq %rsi, %rdi
movl %eax, %esi
leaq -0x25fa(%rip), %rcx     # 0x878b2
pushq $0x30
popq %rdx
callq 0x23f0
movq 0x20(%rsp), %r8
movq 0x28(%rsp), %rsi
andq $0x0, (%r15)
movq 0x38(%rsp), %rax
leal (,%rax,4), %eax
cmpq %rax, 0x8(%r15)
jae 0x89f34
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%r15)
movq 0x10(%r15), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq 0x20(%rsp), %r8
movq 0x28(%rsp), %rsi
movq %rax, %rdi
movq %rax, 0x10(%r15)
jmp 0x89f38
movq 0x10(%r15), %rdi
xorl %eax, %eax
movq %rsi, %rcx
cmpq %rax, %r8
je 0x89f66
movl (%rcx), %edx
movq (%r15), %rsi
movq %rdx, (%rdi,%rsi,8)
movq (%r15), %rdx
shlq $0x20, (%rdi,%rdx,8)
movq (%r15), %rdx
orq %rax, (%rdi,%rdx,8)
incq (%r15)
incq %rax
addq $0x30, %rcx
jmp 0x89f3d
movq (%r15), %r14
leaq (%rdi,%r14,8), %r15
leaq (%r15,%r14,8), %rax
movq %rax, 0x30(%rsp)
movl 0x38(%rsp), %eax
leaq (%rdi,%rax,8), %rsi
movq %rdi, 0x40(%rsp)
callq 0x66c25
movq %r15, %r8
movq 0x40(%rsp), %r10
movq 0x20(%rsp), %rsi
xorl %eax, %eax
cmpq %rax, %rsi
je 0x89fad
movl (%r10,%rax,8), %ecx
movq %rcx, (%r10,%rax,8)
movq %rax, (%r8,%rcx,8)
incq %rax
jmp 0x89f97
movq 0x30(%rsp), %rax
leaq (%rax,%r14,8), %rax
movq %rax, 0x48(%rsp)
movsd 0x159575(%rip), %xmm0   # 0x1e3538
movq 0x28(%rsp), %rdx
movq %r8, 0x58(%rsp)
cmpl 0x38(%rsp), %ebp
jae 0x8a2e6
movl %ebp, 0x64(%rsp)
movl %ebp, %ebp
imulq $0x30, %rbp, %rax
leaq (%rdx,%rax), %rdi
movl (%rdx,%rax), %ecx
movl 0x4(%rdx,%rax), %r9d
movl %r9d, %eax
subl %ecx, %eax
cvtsi2sd %rax, %xmm1
movsd 0x38(%rbx), %xmm2
movsd %xmm2, 0x88(%rsp)
mulsd %xmm2, %xmm1
cvttsd2si %xmm1, %rax
movq %rax, 0x90(%rsp)
xorl %r15d, %r15d
movl $0x0, 0x14(%rsp)
movq $0x0, 0x50(%rsp)
movq $0x0, 0x68(%rsp)
movl $0x0, 0xc(%rsp)
movl %ecx, 0x18(%rsp)
movl %r9d, 0x10(%rsp)
movq %rdi, 0x80(%rsp)
cmpq %r15, %rsi
je 0x8a2db
movq (%r10,%r15,8), %rax
cmpq (%r8,%rbp,8), %r15
jne 0x8a06d
cmpq %rbp, %rax
je 0x8a171
jmp 0x8a2f8
cmpq %rbp, %rax
ja 0x8a171
imulq $0x30, %rax, %r12
movl (%rdx,%r12), %r14d
cmpl %r9d, %r14d
jae 0x8a2db
addq %rdx, %r12
cmpl $-0x1, 0x18(%r12)
je 0x8a171
testb $0x3e, 0x28(%r12)
je 0x8a0b9
movsd 0x20(%rdi), %xmm2
movsd 0x20(%r12), %xmm1
mulsd 0x40(%rbx), %xmm1
ucomisd %xmm1, %xmm2
ja 0x8a171
cmpl %r14d, %ecx
movl %r14d, %r13d
cmoval %ecx, %r13d
movl 0x4(%r12), %eax
cmpl %eax, %r9d
movl %eax, %r11d
cmovbl %r9d, %r11d
cmpl %r13d, %r11d
jbe 0x8a171
movq %r11, 0x70(%rsp)
movq %rax, 0x78(%rsp)
movq (%rbx), %rdx
movq %r12, %rsi
movq %rdx, 0x98(%rsp)
callq 0x87a7b
testl %eax, %eax
je 0x8a122
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rsi
movq 0x40(%rsp), %r10
movq 0x58(%rsp), %r8
movsd 0x159420(%rip), %xmm0   # 0x1e3538
movq 0x80(%rsp), %rdi
jmp 0x8a168
movq %r12, %rdi
movq 0x80(%rsp), %rsi
movq %rsi, %r12
movq 0x98(%rsp), %rdx
movsd 0x1593f8(%rip), %xmm0   # 0x1e3538
callq 0x87a7b
testl %eax, %eax
je 0x8a179
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rsi
movq 0x40(%rsp), %r10
movq 0x58(%rsp), %r8
movsd 0x1593d3(%rip), %xmm0   # 0x1e3538
movq %r12, %rdi
movl 0x18(%rsp), %ecx
movl 0x10(%rsp), %r9d
incq %r15
jmp 0x8a04c
movq 0x68(%rsp), %rdi
testl %edi, %edi
movq 0x28(%rsp), %rdx
movq 0x20(%rsp), %rsi
movq 0x40(%rsp), %r10
movq 0x58(%rsp), %r8
je 0x8a1ab
leal -0x1(%rdi), %eax
movq 0x30(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
cmpl %ecx, %r13d
jbe 0x8a27f
movl 0xc(%rsp), %eax
subl %r13d, %eax
movq 0x70(%rsp), %rcx
addl %ecx, %eax
movl %eax, 0xc(%rsp)
movl %edi, %eax
shlq $0x20, %r13
movl %ecx, %ecx
orq %r13, %rcx
movq 0x30(%rsp), %r9
movq %rcx, (%r9,%rax,8)
incl %edi
movq %rdi, 0x68(%rsp)
movsd 0x159358(%rip), %xmm0   # 0x1e3538
movq 0x50(%rsp), %rdi
movq 0x78(%rsp), %r11
testl %edi, %edi
je 0x8a203
leal -0x1(%rdi), %eax
movq 0x48(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
cmpl %ecx, %r14d
jbe 0x8a2b5
movl 0x14(%rsp), %eax
subl %r14d, %eax
addl %r11d, %eax
movl %eax, 0x14(%rsp)
movl %edi, %eax
shlq $0x20, %r14
orq %r11, %r14
movq 0x48(%rsp), %rcx
movq %r14, (%rcx,%rax,8)
incl %edi
movq %rdi, 0x50(%rsp)
movq %r12, %rdi
movl 0x18(%rsp), %ecx
movl 0x10(%rsp), %r9d
movl 0xc(%rsp), %eax
testl %eax, %eax
je 0x8a272
cmpl 0x90(%rsp), %eax
jae 0x8a2d7
movl 0xc(%rsp), %eax
cvtsi2sd %rax, %xmm2
movl 0x14(%rsp), %eax
cvtsi2sd %rax, %xmm1
mulsd 0x88(%rsp), %xmm1
ucomisd %xmm1, %xmm2
jb 0x8a171
jmp 0x8a2d7
movl $0x0, 0xc(%rsp)
jmp 0x8a171
movq 0x70(%rsp), %r9
subl %ecx, %r9d
movsd 0x1592a9(%rip), %xmm0   # 0x1e3538
movq 0x50(%rsp), %rdi
movq 0x78(%rsp), %r11
jbe 0x8a1ea
addl %r9d, 0xc(%rsp)
addq %r9, %rcx
movq 0x30(%rsp), %r9
movq %rcx, (%r9,%rax,8)
jmp 0x8a1ea
cmpl %ecx, %r11d
jbe 0x8a22a
subl %ecx, %r11d
addl %r11d, 0x14(%rsp)
addq %r11, %rcx
movq 0x48(%rsp), %r9
movq %rcx, (%r9,%rax,8)
jmp 0x8a22a
orl $-0x1, 0x18(%rdi)
movl 0x64(%rsp), %ebp
incl %ebp
jmp 0x89fcd
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x15e83e(%rip), %rdi    # 0x1e8b3d
leaq 0x15da8b(%rip), %rsi    # 0x1e7d91
leaq 0x160d18(%rip), %rcx    # 0x1eb025
movl $0x3b77, %edx           # imm = 0x3B77
callq 0x2110