// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: test_arc_rm(ma_ug_t*, u_trans_t*, unsigned int, unsigned int, unsigned int, asg64_v*, unsigned int, double)
uint32_t test_arc_rm(ma_ug_t *ug, u_trans_t *a, uint32_t a_n, uint32_t a_k, uint32_t len, asg64_v *srt, uint32_t len_cut, double rate_cut)
{
    uint32_t z, i, l, os, oe, ovq;

    srt->n = 0; kv_resize(uint64_t, *srt, a_n); 
    for (z = 0; z < a_n; z++) {
        if(z == a_k) continue;
        if(a[z].occ == ((uint32_t)-1)) continue;
        srt->a[srt->n] = a[z].qs;
        srt->a[srt->n] <<= 32;
        srt->a[srt->n] |= a[z].qe;
        srt->n++;
    }
    radix_sort_arch64(srt->a, srt->a+srt->n);
    for (i = z = 0; i < srt->n; i++) {
        os = (uint32_t)(srt->a[i]>>32); oe = (uint32_t)srt->a[i];
        if(z > 0 && os <= ((uint32_t)srt->a[z-1])) {
            if(oe > ((uint32_t)srt->a[z-1])) {
                srt->a[z-1] >>= 32; srt->a[z-1] <<= 32; srt->a[z-1] |= oe;
            }
        } else {
            srt->a[z++] = srt->a[i];
        }
    }
    srt->n = z; l = (a[a_k].qe - a[a_k].qs);
    for (z = 0; (z < srt->n) && (l > 0); z++) {
        os = MAX(a[a_k].qs, ((uint32_t)(srt->a[z]>>32))); 
        oe = MIN(a[a_k].qe, ((uint32_t)srt->a[z]));
        ovq = ((oe > os)? (oe - os):0);
        assert(l >= ovq); l -= ovq;
    }
    // if((a[a_k].qn == 3924 && a[a_k].tn == 160) || (a[a_k].tn == 3924 && a[a_k].qn == 160)) {
    //     fprintf(stderr, "[M::%s::]\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\tlen::%u\tlen_cut::%u\trate_cut::%f\tl::%u\n", __func__,
    //                 a[a_k].qn+1, "lc"[ug->u.a[a[a_k].qn].circ], ug->u.a[a[a_k].qn].len, a[a_k].qs, a[a_k].qe, "+-"[a[a_k].rev],
    //                 a[a_k].tn+1, "lc"[ug->u.a[a[a_k].tn].circ], ug->u.a[a[a_k].tn].len, a[a_k].ts, a[a_k].te, a[a_k].nw, a[a_k].f,
    //                 (a[a_k].occ == ((uint32_t)-1))?1:0, len, len_cut, rate_cut, l);
    // }
    if((l > len_cut) && (l > (len*rate_cut))) return 0;///cannot be dropped
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movsd %xmm0, (%rsp)
movq %r9, %r14
movl %r8d, %ebx
movl %ecx, %r12d
movl %edx, %ebp
movq %rsi, %r15
movq $0x0, (%r9)
movl %edx, %r13d
cmpq %r13, 0x8(%r9)
jae 0xc4174
leaq -0x1(%r13), %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 %rax, 0x10(%r14)
movl %r12d, %r12d
testl %ebp, %ebp
je 0xc41d3
movq %r12, %rax
shlq $0x4, %rax
leaq (%rax,%rax,2), %rax
shlq $0x4, %r13
leaq (,%r13,2), %rcx
addq %r13, %rcx
xorl %edx, %edx
cmpq %rdx, %rax
je 0xc41ca
cmpl $-0x1, 0x18(%r15,%rdx)
je 0xc41ca
movl (%r15,%rdx), %esi
movq (%r14), %rdi
movq 0x10(%r14), %r8
movq %rsi, (%r8,%rdi,8)
movq (%r14), %rsi
shlq $0x20, (%r8,%rsi,8)
movl 0x4(%r15,%rdx), %esi
movq (%r14), %rdi
orq %rsi, (%r8,%rdi,8)
incq (%r14)
addq $0x30, %rdx
cmpq %rdx, %rcx
jne 0xc4197
movq (%r14), %rax
movq 0x10(%r14), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x9dc69
cmpq $0x0, (%r14)
je 0xc423f
movq 0x10(%r14), %rcx
xorl %edi, %edi
movl $0x1, %edx
movabsq $-0x100000000, %rsi     # imm = 0xFFFFFFFF00000000
xorl %eax, %eax
movq (%rcx,%rdi,8), %rdi
testl %eax, %eax
je 0xc421c
movq %rdi, %r10
shrq $0x20, %r10
leal -0x1(%rax), %r8d
movq (%rcx,%r8,8), %r9
cmpl %r9d, %r10d
jbe 0xc4230
movl %eax, %r8d
incl %eax
movq %rdi, (%rcx,%r8,8)
movl %edx, %edi
incl %edx
cmpq %rdi, (%r14)
ja 0xc4200
jmp 0xc4241
cmpl %r9d, %edi
jbe 0xc4225
andq %rsi, %r9
movl %edi, %edi
orq %r9, %rdi
jmp 0xc4221
xorl %eax, %eax
movl %eax, %ecx
movq %rcx, (%r14)
leaq (%r12,%r12,2), %rcx
shlq $0x4, %rcx
movl (%r15,%rcx), %edx
movl 0x4(%r15,%rcx), %esi
movl %esi, %ecx
subl %edx, %ecx
testl %eax, %eax
je 0xc429e
testl %ecx, %ecx
je 0xc429e
movq 0x10(%r14), %rdi
xorl %r8d, %r8d
xorl %r9d, %r9d
movq (%rdi,%r9,8), %r10
movq %r10, %r11
shrq $0x20, %r11
cmpl %r11d, %edx
cmoval %edx, %r11d
cmpl %r10d, %esi
cmovbl %esi, %r10d
subl %r11d, %r10d
cmovbl %r8d, %r10d
subl %r10d, %ecx
jb 0xc42d6
incq %r9
cmpl %r9d, %eax
jbe 0xc429e
testl %ecx, %ecx
jne 0xc426d
cmpl 0x40(%rsp), %ecx
jbe 0xc42c2
movl %ecx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
movl %ebx, %eax
cvtsi2sd %rax, %xmm1
mulsd (%rsp), %xmm1
xorl %eax, %eax
ucomisd %xmm1, %xmm0
ja 0xc42c7
movl $0x1, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x172882(%rip), %rdi    # 0x236b5f
leaq 0x171bad(%rip), %rsi    # 0x235e91
leaq 0x17287d(%rip), %rcx    # 0x236b68
movl $0x3b1d, %edx           # imm = 0x3B1D
callq 0x2110