// File: /workspace/github_cpp_makefile_star2_O3/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 $0xb8, %rsp
movq 0x18(%rdi), %r14
movslq %edx, %rax
leaq (%rax,%rax,2), %r15
shlq $0x3, %r15
addq 0x48(%rdi), %r15
movq 0x50(%rdi), %rax
testq %rax, %rax
movq %rdi, 0x28(%rsp)
je 0xc6226
movq 0x28(%rax), %rcx
movl %esi, %ebx
movq (%rcx,%rbx,8), %rcx
movl %ecx, %edx
movq %rcx, %r13
shrq $0x20, %r13
leaq 0x1(%r13), %rsi
cmpq %rsi, %rdx
jbe 0xc676b
cmpl %ecx, %r13d
jae 0xc673a
movq 0x28(%r14), %rcx
movq 0x10(%rax), %rdx
movl (%rdx,%r13,8), %edx
movq (%rcx,%rdx,8), %rcx
testl %ecx, %ecx
je 0xc6212
movq %rcx, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %r12
shlq $0x4, %r12
addq 0x10(%r14), %r12
movl %ecx, %ebp
movq (%rdi), %rdx
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rcx
movl $0x2dc6c0, %r8d         # imm = 0x2DC6C0
movsd 0x16b3f5(%rip), %xmm0   # 0x2315f0
callq 0xc42f5
movq 0x28(%rsp), %rdi
addq $0x30, %r12
decq %rbp
jne 0xc61e1
movq 0x50(%rdi), %rax
incq %r13
movq 0x28(%rax), %rcx
movl (%rcx,%rbx,8), %ecx
cmpq %rcx, %r13
jb 0xc61b8
jmp 0xc673a
movq 0x28(%r14), %rax
movl %esi, %ecx
movq (%rax,%rcx,8), %rbx
movq %rbx, %rax
shrq $0x20, %rax
leaq (%rax,%rax,2), %r9
shlq $0x4, %r9
addq 0x10(%r14), %r9
movl %ebx, %eax
testl %ebx, %ebx
je 0xc62ec
movl %ebx, %edx
xorl %esi, %esi
movq %r9, %rdi
xorl %ecx, %ecx
testb $0x3e, 0x28(%rdi)
jne 0xc62da
movl %ecx, %r8d
cmpq %r8, %rsi
je 0xc62d8
movups (%rdi), %xmm0
movups 0x10(%rdi), %xmm1
movups 0x20(%rdi), %xmm2
movaps %xmm2, 0xa0(%rsp)
movaps %xmm1, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
leaq (%r8,%r8,2), %r8
shlq $0x4, %r8
movups (%r9,%r8), %xmm0
movups 0x10(%r9,%r8), %xmm1
movups 0x20(%r9,%r8), %xmm2
movups %xmm2, 0x20(%rdi)
movups %xmm1, 0x10(%rdi)
movups %xmm0, (%rdi)
movaps 0x80(%rsp), %xmm0
movapd 0x90(%rsp), %xmm1
movapd 0xa0(%rsp), %xmm2
movupd %xmm2, 0x20(%r9,%r8)
movupd %xmm1, 0x10(%r9,%r8)
movups %xmm0, (%r9,%r8)
incl %ecx
incq %rsi
addq $0x30, %rdi
cmpq %rsi, %rdx
jne 0xc6256
jmp 0xc62ee
xorl %ecx, %ecx
subl %ecx, %eax
jbe 0xc673a
movl %ecx, %ebp
cmpl $0x2, %eax
movq %r9, 0x10(%rsp)
jb 0xc632c
leaq (,%rbp,2), %rdi
addq %rbp, %rdi
shlq $0x4, %rdi
addq %r9, %rdi
movl %eax, %esi
leaq -0x24fb(%rip), %rcx     # 0xc3e22
movl $0x30, %edx
callq 0x23f0
movq 0x10(%rsp), %r9
movq $0x0, (%r15)
leal (,%rbx,4), %eax
cmpq %rax, 0x8(%r15)
jae 0xc639b
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 0x10(%rsp), %r9
movq %rax, 0x10(%r15)
movq (%r15), %r14
jmp 0xc63a2
movq 0x10(%r15), %rax
xorl %r14d, %r14d
movl %ebx, %r12d
xorl %esi, %esi
movq %r9, %rcx
movl (%rcx), %edx
movq %rdx, (%rax,%r14,8)
movq (%r15), %rdx
shlq $0x20, (%rax,%rdx,8)
movq (%r15), %rdx
orq %rsi, (%rax,%rdx,8)
movq (%r15), %r14
incq %r14
movq %r14, (%r15)
incq %rsi
addq $0x30, %rcx
cmpq %rsi, %r12
jne 0xc63aa
leaq (%rax,%r14,8), %r15
leaq (%r15,%r14,8), %rcx
movq %rcx, 0x30(%rsp)
movl %ebx, %ecx
leaq (%rax,%rcx,8), %rsi
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rdi
callq 0x9dc69
movq %r15, %r8
movq 0x20(%rsp), %r10
xorl %eax, %eax
movl (%r10,%rax,8), %ecx
movq %rcx, (%r10,%rax,8)
movq %rax, (%r8,%rcx,8)
incq %rax
cmpq %rax, %r12
jne 0xc6400
movq 0x30(%rsp), %rax
leaq (%rax,%r14,8), %rax
movq %rax, 0x40(%rsp)
movq 0x28(%rsp), %rdx
movsd 0x38(%rdx), %xmm0
movsd %xmm0, 0x50(%rsp)
movl %ebx, %ecx
movsd 0x16b1ac(%rip), %xmm0   # 0x2315e8
movq 0x10(%rsp), %rsi
movq %r8, 0x48(%rsp)
movq %rcx, 0x18(%rsp)
leaq (,%rbp,2), %rax
addq %rbp, %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 0x50(%rsp), %xmm1
cvttsd2si %xmm1, %rax
movq %rax, 0x70(%rsp)
xorl %r15d, %r15d
movl $0x0, (%rsp)
movq $0x0, 0x58(%rsp)
movq $0x0, 0x38(%rsp)
movl $0x0, 0x8(%rsp)
movl %r9d, 0x4(%rsp)
movl %r11d, 0xc(%rsp)
movq %rdi, 0x68(%rsp)
movq (%r10,%r15,8), %rax
cmpq (%r8,%rbp,8), %r15
jne 0xc64d0
cmpq %rbp, %rax
je 0xc65d1
jmp 0xc674c
cmpq %rbp, %rax
ja 0xc65d1
leaq (%rax,%rax,2), %r12
shlq $0x4, %r12
movl (%rsi,%r12), %r14d
cmpl %r11d, %r14d
jae 0xc672e
addq %rsi, %r12
cmpl $-0x1, 0x18(%r12)
je 0xc65d1
testb $0x3e, 0x28(%r12)
je 0xc6520
movsd 0x20(%rdi), %xmm2
movsd 0x20(%r12), %xmm1
mulsd 0x40(%rdx), %xmm1
ucomisd %xmm1, %xmm2
ja 0xc65d1
cmpl %r14d, %r9d
movl %r14d, %r13d
cmoval %r9d, %r13d
movl 0x4(%r12), %eax
cmpl %eax, %r11d
movl %eax, %ebx
cmovbl %r11d, %ebx
cmpl %r13d, %ebx
jbe 0xc65d1
movq %rax, 0x60(%rsp)
movq (%rdx), %rdx
movq %r12, %rsi
movq %rdx, 0x78(%rsp)
callq 0xc3ffd
testl %eax, %eax
je 0xc6582
movq 0x28(%rsp), %rdx
movq 0x10(%rsp), %rsi
movq 0x20(%rsp), %r10
movq 0x48(%rsp), %r8
movq 0x18(%rsp), %rcx
movsd 0x16b06d(%rip), %xmm0   # 0x2315e8
movq 0x68(%rsp), %rdi
jmp 0xc65c7
movq %r12, %rdi
movq 0x68(%rsp), %rsi
movq %rsi, %r12
movq 0x78(%rsp), %rdx
movsd 0x16b04e(%rip), %xmm0   # 0x2315e8
callq 0xc3ffd
testl %eax, %eax
je 0xc65e2
movq 0x28(%rsp), %rdx
movq 0x10(%rsp), %rsi
movq 0x20(%rsp), %r10
movq 0x48(%rsp), %r8
movq 0x18(%rsp), %rcx
movsd 0x16b024(%rip), %xmm0   # 0x2315e8
movq %r12, %rdi
movl 0x4(%rsp), %r9d
movl 0xc(%rsp), %r11d
incq %r15
cmpq %r15, %rcx
jne 0xc64b8
jmp 0xc672e
movq 0x58(%rsp), %rdi
testl %edi, %edi
movq 0x28(%rsp), %rdx
movq 0x10(%rsp), %rsi
movq 0x20(%rsp), %r10
movq 0x48(%rsp), %r8
movl 0xc(%rsp), %r11d
je 0xc6619
leal -0x1(%rdi), %eax
movq 0x30(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
cmpl %ecx, %r13d
jbe 0xc66dd
movl (%rsp), %eax
subl %r13d, %eax
addl %ebx, %eax
movl %eax, (%rsp)
movl %edi, %eax
shlq $0x20, %r13
movl %ebx, %ecx
orq %r13, %rcx
movq 0x30(%rsp), %r9
movq %rcx, (%r9,%rax,8)
incl %edi
movq %rdi, 0x58(%rsp)
movsd 0x16afa1(%rip), %xmm0   # 0x2315e8
movq %r12, %rdi
movq 0x38(%rsp), %r9
testl %r9d, %r9d
je 0xc666a
leal -0x1(%r9), %eax
movq 0x40(%rsp), %rcx
movq (%rcx,%rax,8), %rcx
cmpl %ecx, %r14d
jbe 0xc6704
movl 0x8(%rsp), %eax
subl %r14d, %eax
movq 0x60(%rsp), %rcx
addl %ecx, %eax
movl %eax, 0x8(%rsp)
movl %r9d, %eax
shlq $0x20, %r14
orq %rcx, %r14
movq 0x40(%rsp), %rcx
movq %r14, (%rcx,%rax,8)
incl %r9d
movq %r9, 0x38(%rsp)
movq 0x18(%rsp), %rcx
movl 0x4(%rsp), %r9d
movl (%rsp), %eax
testl %eax, %eax
je 0xc66d1
cmpl 0x70(%rsp), %eax
jae 0xc6727
movl (%rsp), %eax
cvtsi2sd %rax, %xmm2
movl 0x8(%rsp), %eax
cvtsi2sd %rax, %xmm1
mulsd 0x50(%rsp), %xmm1
ucomisd %xmm1, %xmm2
jb 0xc65d1
jmp 0xc6727
movl $0x0, (%rsp)
jmp 0xc65d1
subl %ecx, %ebx
movsd 0x16af01(%rip), %xmm0   # 0x2315e8
movq %r12, %rdi
jbe 0xc664a
addl %ebx, (%rsp)
addq %rbx, %rcx
movq 0x30(%rsp), %r9
movq %rcx, (%r9,%rax,8)
jmp 0xc664a
movq 0x60(%rsp), %r9
cmpl %ecx, %r9d
jbe 0xc6697
subl %ecx, %r9d
addl %r9d, 0x8(%rsp)
addq %r9, %rcx
movq 0x40(%rsp), %r9
movq %rcx, (%r9,%rax,8)
jmp 0xc6697
movl $0xffffffff, 0x18(%rdi) # imm = 0xFFFFFFFF
incq %rbp
cmpq %rcx, %rbp
jne 0xc644b
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1704ea(%rip), %rdi    # 0x236c3d
leaq 0x16f737(%rip), %rsi    # 0x235e91
leaq 0x1729c4(%rip), %rcx    # 0x239125
movl $0x3b77, %edx           # imm = 0x3B77
callq 0x2110
leaq 0x1729e4(%rip), %rdi    # 0x239156
leaq 0x16f718(%rip), %rsi    # 0x235e91
leaq 0x1729a5(%rip), %rcx    # 0x239125
movl $0x3bad, %edx           # imm = 0x3BAD
callq 0x2110