// File: /workspace/github_cpp_makefile_star2_O1/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 $0xc8, %rsp
movq 0x18(%rdi), %r15
movslq %edx, %rax
leaq (%rax,%rax,2), %r14
shlq $0x3, %r14
addq 0x48(%rdi), %r14
movq 0x50(%rdi), %rax
testq %rax, %rax
movq %rdi, 0x30(%rsp)
je 0xc5463
movq 0x28(%rax), %rax
movl %esi, %r13d
movq (%rax,%r13,8), %rbp
movl %ebp, %eax
shrq $0x20, %rbp
leaq 0x1(%rbp), %rcx
cmpq %rcx, %rax
jbe 0xc59ce
movq 0x50(%rdi), %rax
movq 0x28(%rax), %rcx
cmpl (%rcx,%r13,8), %ebp
jae 0xc599d
movq 0x28(%r15), %rcx
movq 0x10(%rax), %rax
movl (%rax,%rbp,8), %eax
movq (%rcx,%rax,8), %rax
testl %eax, %eax
je 0xc544a
movq %rax, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %r12
shlq $0x4, %r12
addq 0x10(%r15), %r12
movl %eax, %ebx
movq (%rdi), %rdx
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rcx
movl $0x2dc6c0, %r8d         # imm = 0x2DC6C0
movsd 0x1600b9(%rip), %xmm0   # 0x2254f0
callq 0xc3400
movq 0x30(%rsp), %rdi
addq $0x30, %r12
decq %rbx
jne 0xc541d
incq %rbp
movq 0x50(%rdi), %rax
movq 0x28(%rax), %rcx
movl (%rcx,%r13,8), %ecx
cmpq %rcx, %rbp
jb 0xc53f5
jmp 0xc599d
movq 0x28(%r15), %rax
movl %esi, %ecx
movq (%rax,%rcx,8), %r12
movq %r12, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %r8
shlq $0x4, %r8
addq 0x10(%r15), %r8
testl %r12d, %r12d
je 0xc5528
movl %r12d, %eax
xorl %ecx, %ecx
movq %r8, %rdx
xorl %ebp, %ebp
testb $0x3e, 0x28(%rdx)
jne 0xc5516
movl %ebp, %esi
cmpq %rsi, %rcx
je 0xc5514
movups (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
movups 0x20(%rdx), %xmm2
movaps %xmm2, 0xb0(%rsp)
movaps %xmm1, 0xa0(%rsp)
movaps %xmm0, 0x90(%rsp)
leaq (%rsi,%rsi,2), %rsi
shlq $0x4, %rsi
movups (%r8,%rsi), %xmm0
movups 0x10(%r8,%rsi), %xmm1
movups 0x20(%r8,%rsi), %xmm2
movups %xmm2, 0x20(%rdx)
movups %xmm1, 0x10(%rdx)
movups %xmm0, (%rdx)
movaps 0x90(%rsp), %xmm0
movapd 0xa0(%rsp), %xmm1
movapd 0xb0(%rsp), %xmm2
movupd %xmm2, 0x20(%r8,%rsi)
movupd %xmm1, 0x10(%r8,%rsi)
movups %xmm0, (%r8,%rsi)
incl %ebp
incq %rcx
addq $0x30, %rdx
cmpq %rcx, %rax
jne 0xc5493
jmp 0xc552a
xorl %ebp, %ebp
movl %r12d, %eax
subl %ebp, %eax
jbe 0xc599d
movl %ebp, %r15d
cmpl $0x2, %eax
movq %r8, 0x18(%rsp)
jb 0xc5565
leaq (%r15,%r15,2), %rdi
shlq $0x4, %rdi
addq %r8, %rdi
movl %eax, %esi
leaq -0x2639(%rip), %rcx     # 0xc2f1d
movl $0x30, %edx
callq 0x23f0
movq 0x18(%rsp), %r8
movq $0x0, (%r14)
leal (,%r12,4), %eax
cmpq %rax, 0x8(%r14)
jae 0xc55d0
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(%r14)
movq 0x10(%r14), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq 0x18(%rsp), %r8
movq %rax, 0x10(%r14)
movq 0x10(%r14), %rax
cmpl $0x1, %r12d
movl %r12d, %ebx
adcl $0x0, %ebx
xorl %ecx, %ecx
movq %r8, %rdx
movl (%rdx), %esi
movq (%r14), %rdi
movq %rsi, (%rax,%rdi,8)
movq (%r14), %rsi
shlq $0x20, (%rax,%rsi,8)
movq (%r14), %rsi
orq %rcx, (%rax,%rsi,8)
incq (%r14)
incq %rcx
addq $0x30, %rdx
cmpq %rcx, %rbx
jne 0xc55e3
movq (%r14), %rax
movq 0x10(%r14), %r14
leaq (%r14,%rax,8), %r13
movq %rax, 0x28(%rsp)
leaq (,%rax,8), %rax
addq %r13, %rax
movq %rax, 0x38(%rsp)
movl %r12d, %eax
leaq (%r14,%rax,8), %rsi
movq %r14, %rdi
callq 0x9d53f
movq %r13, %r8
movq %r14, %r10
xorl %eax, %eax
movl (%r10,%rax,8), %ecx
movq %rcx, (%r10,%rax,8)
movq %rax, (%r8,%rcx,8)
incq %rax
cmpq %rax, %rbx
jne 0xc5641
cmpl %ebp, %r12d
movq 0x30(%rsp), %rdx
movq 0x18(%rsp), %rsi
jbe 0xc599d
movq 0x38(%rsp), %rax
movq 0x28(%rsp), %rcx
leaq (%rax,%rcx,8), %rax
movq %rax, 0x48(%rsp)
movsd 0x38(%rdx), %xmm0
movsd %xmm0, 0x60(%rsp)
movl %r12d, %ecx
movsd 0x15fe57(%rip), %xmm0   # 0x2254e8
movq %r10, 0x58(%rsp)
movq %r8, 0x50(%rsp)
movq %rcx, 0x20(%rsp)
leaq (%r15,%r15,2), %rax
shlq $0x4, %rax
leaq (%rsi,%rax), %rdi
movl (%rsi,%rax), %r9d
movl 0x4(%rsi,%rax), %r11d
movl %r11d, %eax
subl %r9d, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x60(%rsp), %xmm1
cvttsd2si %xmm1, %rax
movq %rax, 0x80(%rsp)
xorl %ebp, %ebp
movl $0x0, 0xc(%rsp)
movq $0x0, 0x68(%rsp)
movq $0x0, 0x40(%rsp)
movl $0x0, 0x14(%rsp)
movl %r9d, 0x10(%rsp)
movl %r11d, 0x28(%rsp)
movq %rdi, 0x78(%rsp)
movq (%r10,%rbp,8), %rax
cmpq (%r8,%r15,8), %rbp
jne 0xc5721
cmpq %r15, %rax
je 0xc5829
jmp 0xc59af
cmpq %r15, %rax
ja 0xc5829
leaq (%rax,%rax,2), %r12
shlq $0x4, %r12
movl (%rsi,%r12), %r13d
cmpl %r11d, %r13d
jae 0xc5991
addq %rsi, %r12
cmpl $-0x1, 0x18(%r12)
je 0xc5829
testb $0x3e, 0x28(%r12)
je 0xc5771
movsd 0x20(%rdi), %xmm2
movsd 0x20(%r12), %xmm1
mulsd 0x40(%rdx), %xmm1
ucomisd %xmm1, %xmm2
ja 0xc5829
cmpl %r13d, %r9d
movl %r13d, %ebx
cmoval %r9d, %ebx
movl 0x4(%r12), %eax
cmpl %eax, %r11d
movl %eax, %r14d
cmovbl %r11d, %r14d
cmpl %ebx, %r14d
jbe 0xc5829
movq %rax, 0x70(%rsp)
movq (%rdx), %rdx
movq %r12, %rsi
movq %rdx, 0x88(%rsp)
callq 0xc30f8
testl %eax, %eax
je 0xc57d7
movq 0x30(%rsp), %rdx
movq 0x18(%rsp), %rsi
movq 0x58(%rsp), %r10
movq 0x50(%rsp), %r8
movq 0x20(%rsp), %rcx
movsd 0x15fd18(%rip), %xmm0   # 0x2254e8
movq 0x78(%rsp), %rdi
jmp 0xc581f
movq %r12, %rdi
movq 0x78(%rsp), %rsi
movq %rsi, %r12
movq 0x88(%rsp), %rdx
movsd 0x15fcf6(%rip), %xmm0   # 0x2254e8
callq 0xc30f8
testl %eax, %eax
je 0xc583a
movq 0x30(%rsp), %rdx
movq 0x18(%rsp), %rsi
movq 0x58(%rsp), %r10
movq 0x50(%rsp), %r8
movq 0x20(%rsp), %rcx
movsd 0x15fccc(%rip), %xmm0   # 0x2254e8
movq %r12, %rdi
movl 0x10(%rsp), %r9d
movl 0x28(%rsp), %r11d
incq %rbp
cmpq %rbp, %rcx
jne 0xc5709
jmp 0xc5991
movq 0x68(%rsp), %rdi
testl %edi, %edi
movq 0x30(%rsp), %rdx
movq 0x18(%rsp), %rsi
movq 0x58(%rsp), %r10
movq 0x50(%rsp), %r8
movl 0x28(%rsp), %r11d
je 0xc5870
leal -0x1(%rdi), %eax
movq 0x38(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
cmpl %ecx, %ebx
jbe 0xc593d
movl 0xc(%rsp), %eax
subl %ebx, %eax
addl %r14d, %eax
movl %eax, 0xc(%rsp)
movl %edi, %eax
shlq $0x20, %rbx
movl %r14d, %ecx
orq %rbx, %rcx
movq 0x38(%rsp), %r9
movq %rcx, (%r9,%rax,8)
incl %edi
movq %rdi, 0x68(%rsp)
movsd 0x15fc47(%rip), %xmm0   # 0x2254e8
movq %r12, %rdi
movq 0x40(%rsp), %r9
testl %r9d, %r9d
je 0xc58c4
leal -0x1(%r9), %eax
movq 0x48(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
cmpl %ecx, %r13d
jbe 0xc5967
movl 0x14(%rsp), %eax
subl %r13d, %eax
movq 0x70(%rsp), %rcx
addl %ecx, %eax
movl %eax, 0x14(%rsp)
movl %r9d, %eax
shlq $0x20, %r13
orq %rcx, %r13
movq 0x48(%rsp), %rcx
movq %r13, (%rcx,%rax,8)
incl %r9d
movq %r9, 0x40(%rsp)
movq 0x20(%rsp), %rcx
movl 0x10(%rsp), %r9d
movl 0xc(%rsp), %eax
testl %eax, %eax
je 0xc5930
cmpl 0x80(%rsp), %eax
jae 0xc598a
movl 0xc(%rsp), %eax
cvtsi2sd %rax, %xmm2
movl 0x14(%rsp), %eax
cvtsi2sd %rax, %xmm1
mulsd 0x60(%rsp), %xmm1
ucomisd %xmm1, %xmm2
jb 0xc5829
jmp 0xc598a
movl $0x0, 0xc(%rsp)
jmp 0xc5829
subl %ecx, %r14d
movsd 0x15fba0(%rip), %xmm0   # 0x2254e8
movq %r12, %rdi
jbe 0xc58a4
addl %r14d, 0xc(%rsp)
addq %r14, %rcx
movq 0x38(%rsp), %r9
movq %rcx, (%r9,%rax,8)
jmp 0xc58a4
movq 0x70(%rsp), %r9
cmpl %ecx, %r9d
jbe 0xc58f1
subl %ecx, %r9d
addl %r9d, 0x14(%rsp)
addq %r9, %rcx
movq 0x48(%rsp), %r9
movq %rcx, (%r9,%rax,8)
jmp 0xc58f1
movl $0xffffffff, 0x18(%rdi) # imm = 0xFFFFFFFF
incq %r15
cmpq %rcx, %r15
jne 0xc56a0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x165097(%rip), %rdi    # 0x22aa4d
leaq 0x1642e4(%rip), %rsi    # 0x229ca1
leaq 0x167571(%rip), %rcx    # 0x22cf35
movl $0x3b77, %edx           # imm = 0x3B77
callq 0x2110
leaq 0x167591(%rip), %rdi    # 0x22cf66
leaq 0x1642c5(%rip), %rsi    # 0x229ca1
leaq 0x167552(%rip), %rcx    # 0x22cf35
movl $0x3bad, %edx           # imm = 0x3BAD
callq 0x2110