// File: /workspace/github_cpp_makefile_star2_O2/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, %ebp
andq $0x0, (%r9)
movq %rsi, %r15
movl %edx, %r13d
cmpq %r13, 0x8(%r9)
jae 0x87bda
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 0x40(%rsp), %r12d
movl %ebp, %ecx
imulq $0x30, %r13, %rax
imulq $0x30, %rcx, %r13
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x87c29
cmpq %rcx, %r13
je 0x87c23
cmpl $-0x1, 0x18(%r15,%rcx)
je 0x87c23
movl (%r15,%rcx), %edx
movq (%r14), %rsi
movq 0x10(%r14), %rdi
movq %rdx, (%rdi,%rsi,8)
movq (%r14), %rdx
shlq $0x20, (%rdi,%rdx,8)
movl 0x4(%r15,%rcx), %edx
movq (%r14), %rsi
orq %rdx, (%rdi,%rsi,8)
incq (%r14)
addq $0x30, %rcx
jmp 0x87beb
movq (%r14), %rax
movq 0x10(%r14), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x66c25
xorl %eax, %eax
movabsq $-0x100000000, %rcx     # imm = 0xFFFFFFFF00000000
xorl %edx, %edx
movl %edx, %edx
movl %eax, %r8d
cmpq %rdx, (%r14)
jbe 0x87c8e
movq 0x10(%r14), %rsi
movq (%rsi,%rdx,8), %rdi
testl %eax, %eax
je 0x87c71
movq %rdi, %r11
shrq $0x20, %r11
leal -0x1(%rax), %r9d
movq (%rsi,%r9,8), %r10
cmpl %r10d, %r11d
jbe 0x87c7b
incl %eax
movq %rdi, (%rsi,%r8,8)
incl %edx
jmp 0x87c47
cmpl %r10d, %edi
jbe 0x87c77
andq %rcx, %r10
movl %edi, %edi
orq %r10, %rdi
movq %rdi, (%rsi,%r9,8)
jmp 0x87c77
movq %r8, (%r14)
movl (%r15,%r13), %edx
movl 0x4(%r15,%r13), %esi
movl %esi, %ecx
subl %edx, %ecx
xorl %edi, %edi
cmpl %edi, %eax
jbe 0x87cde
testl %ecx, %ecx
je 0x87cde
movq 0x10(%r14), %r8
movq (%r8,%rdi,8), %r8
movq %r8, %r10
shrq $0x20, %r10
movl %edx, %r9d
cmpl %r10d, %edx
ja 0x87cc2
movl %r10d, %r9d
cmpl %r8d, %esi
cmovbl %esi, %r8d
xorl %r10d, %r10d
subl %r9d, %r8d
jb 0x87cd4
movl %r8d, %r10d
subl %r10d, %ecx
jb 0x87d10
incq %rdi
jmp 0x87ca0
cmpl %r12d, %ecx
jbe 0x87cfe
movl %ecx, %eax
cvtsi2sd %rax, %xmm0
movl %ebx, %eax
cvtsi2sd %rax, %xmm1
mulsd (%rsp), %xmm1
xorl %eax, %eax
ucomisd %xmm1, %xmm0
ja 0x87d01
pushq $0x1
popq %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x160d48(%rip), %rdi    # 0x1e8a5f
leaq 0x160073(%rip), %rsi    # 0x1e7d91
leaq 0x160d43(%rip), %rcx    # 0x1e8a68
movl $0x3b1d, %edx           # imm = 0x3B1D
callq 0x2110