// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: unitig_arc_del_short_diploid_by_length(asg_t*, float)
int unitig_arc_del_short_diploid_by_length(asg_t *g, float drop_ratio)
{
    double startTime = Get_T();
    kvec_t(uint64_t) b;
    memset(&b, 0, sizeof(b));

	uint32_t v, n_vtx = g->n_seq * 2;
    long long n_cut = 0;
    
    for (v = 0; v < n_vtx; ++v) 
    {
        if(g->seq[v>>1].c == ALTER_LABLE || g->seq[v>>1].del) continue;
        asg_arc_t *av = asg_arc_a(g, v);
        uint32_t nv = asg_arc_n(g, v);
        if (nv < 2) continue;
        uint64_t i;
        for (i = 0; i < nv; ++i)
        {
            kv_push(uint64_t, b, (uint64_t)((uint64_t)av[i].ol << 32 | (av - g->arc + i)));   
        }
	}

    radix_sort_arch64(b.a, b.a + b.n);

    uint64_t k;
    for (k = 0; k < b.n; k++)
    {
        
        asg_arc_t *a = &g->arc[(uint32_t)b.a[k]];
		///v is self id, w is the id of another end
		uint32_t i, v = (a->ul)>>32;
		uint32_t nv = asg_arc_n(g, v), kv;
		uint32_t ov_max = 0;
		asg_arc_t *av = NULL;
		///nv must be >= 2
		if (nv <= 1) continue;
        av = asg_arc_a(g, v);


        ///calculate the longest edge for v and w
		for (i = 0, kv = 0; i < nv; ++i) {
			if (av[i].del) continue;
			if (ov_max < av[i].ol) ov_max = av[i].ol; 
			++kv;
		}
        if (kv <= 1) continue;
		if (kv >= 2 && a->ol > ov_max * drop_ratio) continue;
        a->del = 1;
        asg_arc_del(g, a->v^1, av->ul>>32^1, 1);
        ++n_cut; 
    }
    
    free(b.a);
	if (n_cut) 
    {
		asg_cleanup(g);
		asg_symm(g);
	}

    if(VERBOSE >= 1)
    {
        fprintf(stderr, "[M::%s] removed %lld short overlaps\n", __func__, n_cut);
        fprintf(stderr, "[M::%s] takes %0.2f s\n\n", __func__, Get_T()-startTime);
    }
	return n_cut;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x8(%rbp)
movss %xmm0, -0xc(%rbp)
callq 0x2510
movsd %xmm0, -0x18(%rbp)
leaq -0x30(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2100
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0xde700
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
je 0xde5cd
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xde5d2
jmp 0xde6f2
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x34(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x34(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x4c(%rbp)
cmpl $0x2, -0x4c(%rbp)
jae 0xde615
jmp 0xde6f2
movq $0x0, -0x58(%rbp)
movq -0x58(%rbp), %rax
movl -0x4c(%rbp), %ecx
cmpq %rcx, %rax
jae 0xde6f0
jmp 0xde62f
movq -0x30(%rbp), %rax
cmpq -0x28(%rbp), %rax
jne 0xde67e
cmpq $0x0, -0x28(%rbp)
je 0xde650
movq -0x28(%rbp), %rax
shlq %rax
movq %rax, -0x90(%rbp)
jmp 0xde65e
movl $0x2, %eax
movq %rax, -0x90(%rbp)
jmp 0xde65e
movq -0x90(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
movq -0x28(%rbp), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, -0x20(%rbp)
movq -0x48(%rbp), %rax
imulq $0x18, -0x58(%rbp), %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
shlq $0x20, %rax
movq %rax, -0x98(%rbp)
movq -0x48(%rbp), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq %rcx, %rax
movl $0x18, %ecx
cqto
idivq %rcx
movq -0x98(%rbp), %rdx
addq -0x58(%rbp), %rax
orq %rax, %rdx
movq -0x20(%rbp), %rax
movq -0x30(%rbp), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, -0x30(%rbp)
movq %rdx, (%rax,%rcx,8)
jmp 0xde6df
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
jmp 0xde61d
jmp 0xde6f2
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xde58e
movq -0x20(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0xc90e0
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x30(%rbp), %rax
jae 0xde8cb
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x20(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, -0x70(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x70(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x74(%rbp)
movl $0x0, -0x7c(%rbp)
movq $0x0, -0x88(%rbp)
cmpl $0x1, -0x74(%rbp)
ja 0xde78c
jmp 0xde8ba
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x70(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x78(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x74(%rbp), %eax
jae 0xde83a
movq -0x88(%rbp), %rax
movl -0x6c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xde7e9
jmp 0xde82f
movl -0x7c(%rbp), %eax
movq -0x88(%rbp), %rcx
movl -0x6c(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0xc(%rcx), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpl %ecx, %eax
jae 0xde826
movq -0x88(%rbp), %rax
movl -0x6c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, -0x7c(%rbp)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
jmp 0xde7c3
cmpl $0x1, -0x78(%rbp)
ja 0xde842
jmp 0xde8ba
cmpl $0x2, -0x78(%rbp)
jb 0xde86c
movq -0x68(%rbp), %rax
movl 0xc(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cvtsi2ss %eax, %xmm0
movl -0x7c(%rbp), %eax
cvtsi2ss %rax, %xmm1
mulss -0xc(%rbp), %xmm1
ucomiss %xmm1, %xmm0
jbe 0xde86c
jmp 0xde8ba
movq -0x68(%rbp), %rax
movl 0xc(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0xc(%rax)
movq -0x8(%rbp), %rdi
movq -0x68(%rbp), %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
movq -0x88(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
xorq $0x1, %rax
movl %eax, %edx
movl $0x1, %ecx
callq 0xd6530
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0xde720
movq -0x20(%rbp), %rdi
callq 0x2210
cmpq $0x0, -0x40(%rbp)
je 0xde8ed
movq -0x8(%rbp), %rdi
callq 0xcdd10
movq -0x8(%rbp), %rdi
callq 0xce020
movq -0x40(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)