// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: delete_all_edges_carefully(ma_hit_t_alloc*, ma_sub_t*, int, int, unsigned int)
uint32_t delete_all_edges_carefully(ma_hit_t_alloc* sources, ma_sub_t *coverage_cut, 
int max_hang, int min_ovlp, uint32_t qn)
{
    if(coverage_cut[qn].del) return 0;

    int32_t r;
    asg_arc_t t;
    ma_hit_t *h = NULL;
    ma_sub_t *sq = NULL;
    ma_sub_t *st = NULL;
    ma_hit_t_alloc* x = &(sources[qn]);
    uint32_t i, keep_edge = 0;
    uint32_t flag[2];
    flag[0] = flag[1] = 0;
    for (i = 0; i < x->length; i++)
    {
        h = &(x->buffer[i]);
        if(h->del) continue;
        ///now the edge has not been removed
        sq = &(coverage_cut[Get_qn(*h)]);
        st = &(coverage_cut[Get_tn(*h)]);
        if(sq->del || st->del)
        {
            h->del = 1;
            delete_single_edge(sources, coverage_cut, Get_tn(*h), Get_qn(*h));
            continue;
        }
        
        r = ma_hit2arc(h, sq->e - sq->s, st->e - st->s, max_hang, 
                                asm_opt.max_hang_rate, min_ovlp, &t);
        ///if it is a contained read
        if(r < 0)
        {
            h->del = 1;
            delete_single_edge(sources, coverage_cut, Get_tn(*h), Get_qn(*h));
            continue;
        }
        
        if(get_real_sources_length(sources, coverage_cut, max_hang, min_ovlp, (t.v^1))==1)
        {
            flag[((t.ul>>32)^1)&1] = 1;
            keep_edge++;
            continue;
        }

        // h->del = 1;
        // delete_single_edge(sources, coverage_cut, Get_tn(*h), Get_qn(*h));
    }


    if(keep_edge != 0)
    {
        for (i = 0; i < x->length; i++)
        {
            h = &(x->buffer[i]);
            if(h->del) continue;
            ///now the edge has not been removed
            sq = &(coverage_cut[Get_qn(*h)]);
            st = &(coverage_cut[Get_tn(*h)]);
            if(sq->del || st->del) continue;
            
            r = ma_hit2arc(h, sq->e - sq->s, st->e - st->s, max_hang, 
                                    asm_opt.max_hang_rate, min_ovlp, &t);
            ///if it is a contained read
            if(r < 0) continue;

            if(flag[(t.ul>>32)&1] == 1) continue;
            
            if(get_real_sources_length(sources, coverage_cut, max_hang, min_ovlp, (t.v^1))==1) continue;
            
            h->del = 1;
            delete_single_edge(sources, coverage_cut, Get_tn(*h), Get_qn(*h));
        }
    }

    if(keep_edge == 0) coverage_cut[qn].del = 1;
    return keep_edge;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movl %ecx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xd064e
movl $0x0, -0x4(%rbp)
jmp 0xd09fd
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq -0x10(%rbp), %rax
movl -0x24(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movl $0x0, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x70(%rbp)
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x60(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0xd0853
movq -0x60(%rbp), %rax
movq (%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x3f, %rax
cmpl $0x0, %eax
je 0xd06cf
jmp 0xd0845
movq -0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movq (%rcx), %rcx
shrq $0x20, %rcx
movl %ecx, %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movl 0xc(%rcx), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0xd071d
movq -0x58(%rbp), %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xd0766
movq -0x48(%rbp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
andq 0x18(%rax), %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
orq %rdx, %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x48(%rbp), %rax
movl 0xc(%rax), %edx
movq -0x48(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %ecx
callq 0xd0020
jmp 0xd0845
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rax
movl 0x4(%rax), %esi
movq -0x50(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subl %eax, %esi
movq -0x58(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x58(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subl %eax, %edx
movl -0x1c(%rbp), %ecx
leaq 0x2f405c(%rip), %rax    # 0x3c47f8
movss 0x158(%rax), %xmm0
movl -0x20(%rbp), %r8d
leaq -0x40(%rbp), %r9
callq 0xd0300
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jge 0xd0800
movq -0x48(%rbp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
andq 0x18(%rax), %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
orq %rdx, %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x48(%rbp), %rax
movl 0xc(%rax), %edx
movq -0x48(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %ecx
callq 0xd0020
jmp 0xd0845
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movl -0x38(%rbp), %r8d
xorl $0x1, %r8d
callq 0xd0160
cmpl $0x1, %eax
jne 0xd0843
movq -0x40(%rbp), %rax
shrq $0x20, %rax
xorq $0x1, %rax
andq $0x1, %rax
movl $0x1, -0x70(%rbp,%rax,4)
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0xd0845
jmp 0xd0845
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xd0694
cmpl $0x0, -0x68(%rbp)
je 0xd09d3
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x60(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0xd09d1
movq -0x60(%rbp), %rax
movq (%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x3f, %rax
cmpl $0x0, %eax
je 0xd089f
jmp 0xd09c3
movq -0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movq (%rcx), %rcx
shrq $0x20, %rcx
movl %ecx, %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq -0x48(%rbp), %rcx
movl 0xc(%rcx), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0xd08ed
movq -0x58(%rbp), %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0xd08f2
jmp 0xd09c3
movq -0x48(%rbp), %rdi
movq -0x50(%rbp), %rax
movl 0x4(%rax), %esi
movq -0x50(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subl %eax, %esi
movq -0x58(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x58(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subl %eax, %edx
movl -0x1c(%rbp), %ecx
leaq 0x2f3ed0(%rip), %rax    # 0x3c47f8
movss 0x158(%rax), %xmm0
movl -0x20(%rbp), %r8d
leaq -0x40(%rbp), %r9
callq 0xd0300
movl %eax, -0x28(%rbp)
cmpl $0x0, -0x28(%rbp)
jge 0xd0948
jmp 0xd09c3
movq -0x40(%rbp), %rax
shrq $0x20, %rax
andq $0x1, %rax
cmpl $0x1, -0x70(%rbp,%rax,4)
jne 0xd095d
jmp 0xd09c3
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movl -0x20(%rbp), %ecx
movl -0x38(%rbp), %r8d
xorl $0x1, %r8d
callq 0xd0160
cmpl $0x1, %eax
jne 0xd097f
jmp 0xd09c3
movq -0x48(%rbp), %rax
movabsq $0x7fffffffffffffff, %rcx # imm = 0x7FFFFFFFFFFFFFFF
andq 0x18(%rax), %rcx
movabsq $-0x8000000000000000, %rdx # imm = 0x8000000000000000
orq %rdx, %rcx
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x48(%rbp), %rax
movl 0xc(%rax), %edx
movq -0x48(%rbp), %rax
movq (%rax), %rax
shrq $0x20, %rax
movl %eax, %ecx
callq 0xd0020
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0xd0864
jmp 0xd09d3
cmpl $0x0, -0x68(%rbp)
jne 0xd09f7
movq -0x18(%rbp), %rax
movl -0x24(%rbp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movl (%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, (%rax)
movl -0x68(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)