// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movsd %xmm0, -0x38(%rbp)
movq -0x30(%rbp), %rax
movq $0x0, (%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x1c(%rbp), %ecx
cmpq %rcx, %rax
jae 0x10298d
movl -0x1c(%rbp), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
shrq %rcx
movq -0x30(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x2, %rcx
movq -0x30(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x4, %rcx
movq -0x30(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x8, %rcx
movq -0x30(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
shrq $0x10, %rcx
movq -0x30(%rbp), %rax
orq 0x8(%rax), %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rcx
addq $0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x10(%rax)
jmp 0x10298f
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jae 0x102a4b
movl -0x3c(%rbp), %eax
cmpl -0x20(%rbp), %eax
jne 0x1029af
jmp 0x102a3d
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
cmpl $-0x1, 0x18(%rax)
jne 0x1029c5
jmp 0x102a3d
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, %edx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
movq (%rax,%rcx,8), %rdx
shlq $0x20, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x18(%rbp), %rax
movl -0x3c(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, %edx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x30(%rbp), %rcx
movq (%rcx), %rcx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x102996
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x30(%rbp), %rax
movq (%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0xc90e0
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x30(%rbp), %rcx
cmpq (%rcx), %rax
jae 0x102b83
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x40(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x48(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x40(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x4c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jbe 0x102b4b
movl -0x48(%rbp), %eax
movq -0x30(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x3c(%rbp), %edx
subl $0x1, %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
ja 0x102b4b
movl -0x4c(%rbp), %eax
movq -0x30(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x3c(%rbp), %edx
subl $0x1, %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
jbe 0x102b49
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
shrq $0x20, %rdx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rdx
shlq $0x20, %rdx
movq %rdx, (%rax,%rcx,8)
movl -0x4c(%rbp), %eax
movl %eax, %edx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x3c(%rbp), %ecx
subl $0x1, %ecx
movl %ecx, %ecx
orq (%rax,%rcx,8), %rdx
movq %rdx, (%rax,%rcx,8)
jmp 0x102b73
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x40(%rbp), %ecx
movq (%rax,%rcx,8), %rdx
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x3c(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x3c(%rbp)
movl %ecx, %ecx
movq %rdx, (%rax,%rcx,8)
jmp 0x102b75
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x102a7c
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x18(%rbp), %rcx
movl -0x20(%rbp), %edx
imulq $0x30, %rdx, %rdx
addq %rdx, %rcx
subl (%rcx), %eax
movl %eax, -0x44(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rdx
xorl %eax, %eax
cmpq (%rdx), %rcx
movb %al, -0x51(%rbp)
jae 0x102bd7
cmpl $0x0, -0x44(%rbp)
seta %al
movb %al, -0x51(%rbp)
movb -0x51(%rbp), %al
testb $0x1, %al
jne 0x102be3
jmp 0x102cef
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movq -0x30(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x3c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpl %ecx, %eax
jb 0x102c1f
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x58(%rbp)
jmp 0x102c35
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
shrq $0x20, %rax
movl %eax, -0x58(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movq -0x30(%rbp), %rcx
movq 0x10(%rcx), %rcx
movl -0x3c(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
cmpl %ecx, %eax
ja 0x102c75
movq -0x18(%rbp), %rax
movl -0x20(%rbp), %ecx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
movl %eax, -0x5c(%rbp)
jmp 0x102c87
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x3c(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x5c(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x48(%rbp), %eax
jbe 0x102ca0
movl -0x4c(%rbp), %eax
subl -0x48(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0x102ca7
xorl %eax, %eax
movl %eax, -0x60(%rbp)
jmp 0x102ca7
movl -0x60(%rbp), %eax
movl %eax, -0x50(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x50(%rbp), %eax
jb 0x102cb7
jmp 0x102cd6
leaq 0x2848cf(%rip), %rdi    # 0x38758d
leaq 0x283bf8(%rip), %rsi    # 0x3868bd
movl $0x3b1d, %edx           # imm = 0x3B1D
leaq 0x2848c5(%rip), %rcx    # 0x387596
callq 0x2130
movl -0x50(%rbp), %ecx
movl -0x44(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x44(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x102bba
movl -0x44(%rbp), %eax
cmpl 0x10(%rbp), %eax
jbe 0x102d1b
movl -0x44(%rbp), %eax
cvtsi2sd %rax, %xmm0
movl -0x24(%rbp), %eax
cvtsi2sd %rax, %xmm1
mulsd -0x38(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x102d1b
movl $0x0, -0x4(%rbp)
jmp 0x102d22
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nopl (%rax,%rax)