// File: /workspace/github_cpp_makefile_star2_O2/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:
movl %r8d, %eax
imulq $0xc, %rax, %r8
cmpl $0x0, (%rsi,%r8)
js 0x6a8cb
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %edx, 0x10(%rsp)
movl %ecx, 0x14(%rsp)
addq %rsi, %r8
movq %r8, 0x38(%rsp)
imulq $0x18, %rax, %r9
movq %rdi, 0x28(%rsp)
addq %rdi, %r9
andq $0x0, 0x30(%rsp)
xorl %ebp, %ebp
xorl %r15d, %r15d
movl $0x0, 0x24(%rsp)
movq %rsi, 0x8(%rsp)
movq %r9, 0x18(%rsp)
movl 0xc(%r9), %eax
cmpq %rax, %r15
jae 0x6a7b0
movq (%r9), %r14
movq 0x18(%r14,%rbp), %rbx
testq %rbx, %rbx
js 0x6a775
movq (%r14,%rbp), %r13
shrq $0x20, %r13
imulq $0xc, %r13, %rax
movl 0xc(%r14,%rbp), %r12d
movl (%rsi,%rax), %ecx
testl %ecx, %ecx
js 0x6a744
imulq $0xc, %r12, %rdx
addq %rsi, %rdx
movl (%rdx), %r8d
testl %r8d, %r8d
js 0x6a744
leaq (%r14,%rbp), %rdi
addq %rsi, %rax
movl 0x4(%rax), %esi
subl %ecx, %esi
movl 0x4(%rdx), %edx
subl %r8d, %edx
leaq 0x1e906f(%rip), %rax    # 0x253758
movss 0x158(%rax), %xmm0
movl 0x10(%rsp), %ecx
movl 0x14(%rsp), %r8d
leaq 0x40(%rsp), %r9
callq 0x6a4a7
testl %eax, %eax
js 0x6a781
movl 0x48(%rsp), %r8d
xorl $0x1, %r8d
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x10(%rsp), %edx
movl 0x14(%rsp), %ecx
callq 0x6a3c1
cmpl $0x1, %eax
jne 0x6a76b
movl 0x44(%rsp), %eax
notl %eax
andl $0x1, %eax
movl $0x1, 0x30(%rsp,%rax,4)
incl 0x24(%rsp)
jmp 0x6a76b
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
orq %rax, %rbx
movq %rbx, 0x18(%r14,%rbp)
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl %r12d, %edx
movl %r13d, %ecx
callq 0x6a334
movq 0x8(%rsp), %rsi
movq 0x18(%rsp), %r9
incq %r15
addq $0x28, %rbp
jmp 0x6a687
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
orq %rax, %rbx
movq %rbx, 0x18(%r14,%rbp)
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
movl %r12d, %edx
movl %r13d, %ecx
callq 0x6a334
movq %rbx, %rsi
jmp 0x6a770
cmpl $0x0, 0x24(%rsp)
je 0x6a8ce
xorl %r15d, %r15d
leaq 0x40(%rsp), %r13
xorl %r12d, %r12d
movl %eax, %eax
cmpq %rax, %r12
jae 0x6a8d7
movq (%r9), %rbp
cmpq $0x0, 0x18(%rbp,%r15)
js 0x6a8bb
movl 0x4(%rbp,%r15), %eax
imulq $0xc, %rax, %rcx
movl (%rsi,%rcx), %eax
testl %eax, %eax
js 0x6a8bb
movl 0xc(%rbp,%r15), %edx
imulq $0xc, %rdx, %rdx
addq %rsi, %rdx
movl (%rdx), %r8d
testl %r8d, %r8d
js 0x6a8bb
leaq (%r15,%rbp), %rdi
addq %rsi, %rcx
movl 0x4(%rcx), %esi
subl %eax, %esi
movl 0x4(%rdx), %edx
subl %r8d, %edx
leaq 0x1e8f33(%rip), %rax    # 0x253758
movss 0x158(%rax), %xmm0
movl 0x10(%rsp), %ecx
movl 0x14(%rsp), %r8d
movq %r13, %r9
callq 0x6a4a7
movq 0x18(%rsp), %r9
movq 0x8(%rsp), %rsi
testl %eax, %eax
js 0x6a8bb
movl 0x44(%rsp), %eax
andl $0x1, %eax
cmpl $0x1, 0x30(%rsp,%rax,4)
je 0x6a8bb
movl 0x48(%rsp), %r8d
xorl $0x1, %r8d
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl 0x10(%rsp), %edx
movl 0x14(%rsp), %ecx
callq 0x6a3c1
movq 0x18(%rsp), %r9
movq 0x8(%rsp), %rsi
cmpl $0x1, %eax
je 0x6a8bb
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
orq %rax, 0x18(%rbp,%r15)
movl 0x4(%rbp,%r15), %ecx
movl 0xc(%rbp,%r15), %edx
movq 0x28(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x6a334
movq 0x18(%rsp), %r9
movq 0x8(%rsp), %rsi
incq %r12
movl 0xc(%r9), %eax
addq $0x28, %r15
jmp 0x6a7c6
xorl %eax, %eax
retq
movq 0x38(%rsp), %rax
orb $-0x80, 0x3(%rax)
movl 0x24(%rsp), %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq