// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %ecx, 0x8(%rsp)
movl %edx, 0xc(%rsp)
movl %r8d, %eax
leaq (%rax,%rax,2), %rdx
cmpl $0x0, (%rsi,%rdx,4)
js 0xa241b
movq %rsi, %r12
movq %rdi, %r15
movq $0x0, 0x48(%rsp)
cmpl $0x0, 0xc(%rdi,%rdx,8)
je 0xa2413
movq %rdx, 0x50(%rsp)
leaq (%r15,%rdx,8), %r14
xorl %r13d, %r13d
movl $0x18, %ebx
movl $0x0, 0x24(%rsp)
movq %r12, 0x18(%rsp)
movq %r14, 0x30(%rsp)
movq %r15, 0x38(%rsp)
movq (%r14), %rsi
movq (%rsi,%rbx), %rax
testq %rax, %rax
js 0xa20fc
movq -0x18(%rsi,%rbx), %rdi
movq %rdi, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %r10
movl -0xc(%rsi,%rbx), %edx
movl (%r12,%r10,4), %ebp
testl %ebp, %ebp
js 0xa1fe6
leaq (%rdx,%rdx,2), %r8
leaq (%r12,%r8,4), %r8
movl (%r8), %r9d
testl %r9d, %r9d
js 0xa1fe6
movl 0x4(%r8), %r8d
subl %r9d, %r8d
testl %eax, %eax
js 0xa2014
movl -0x8(%rsi,%rbx), %r11d
movl -0x4(%rsi,%rbx), %r9d
movq %r9, 0x10(%rsp)
subl %r9d, %r8d
movl %r8d, %r9d
movl %r11d, 0x28(%rsp)
movl %r11d, %r8d
jmp 0xa202e
movabsq $-0x8000000000000000, %rbp # imm = 0x8000000000000000
orq %rbp, %rax
movq %rax, (%rsi,%rbx)
movq %r15, %rdi
movq %r12, %rsi
callq 0xa1aa3
testq %rax, %rax
je 0xa20fc
orq %rbp, 0x18(%rax)
jmp 0xa20fc
movl -0x8(%rsi,%rbx), %r11d
movl -0x4(%rsi,%rbx), %r9d
movq %r9, 0x10(%rsp)
subl %r9d, %r8d
movl %r11d, 0x28(%rsp)
movl %r11d, %r9d
leaq (%r12,%r10,4), %r10
movl 0x4(%r10), %r11d
subl %ebp, %r11d
cmpl %edi, %r8d
movl %edi, %r14d
cmovll %r8d, %r14d
movl -0x10(%rsi,%rbx), %r15d
movl %r11d, %r10d
subl %r15d, %r10d
cmpl %r9d, %r10d
movl %r9d, %ebp
cmovll %r10d, %ebp
cmpl 0xc(%rsp), %r14d
jg 0xa20c8
cmpl 0xc(%rsp), %ebp
jg 0xa20c8
movl %r15d, %r12d
subl %edi, %r12d
cvtsi2ss %r12, %xmm1
addl %r14d, %r12d
addl %ebp, %r12d
cvtsi2ss %r12, %xmm2
movl %r15d, 0x40(%rsp)
movl %r9d, %r15d
leaq 0x1f36ce(%rip), %r9     # 0x295758
movss 0x158(%r9), %xmm0
mulss %xmm0, %xmm2
ucomiss %xmm1, %xmm2
ja 0xa20c8
movl %r15d, %r9d
movq 0x10(%rsp), %r15
subl 0x28(%rsp), %r15d
xorps %xmm1, %xmm1
cvtsi2ss %r15, %xmm1
addl %r14d, %ebp
addl %r15d, %ebp
xorps %xmm2, %xmm2
cvtsi2ss %rbp, %xmm2
mulss %xmm2, %xmm0
ucomiss %xmm1, %xmm0
jbe 0xa2115
movabsq $-0x8000000000000000, %r14 # imm = 0x8000000000000000
orq %r14, %rax
movq %rax, (%rsi,%rbx)
movq 0x38(%rsp), %r15
movq %r15, %rdi
movq 0x18(%rsp), %r12
movq %r12, %rsi
callq 0xa1aa3
testq %rax, %rax
je 0xa20f7
orq %r14, 0x18(%rax)
movq 0x30(%rsp), %r14
incq %r13
movl 0xc(%r14), %ecx
addq $0x28, %rbx
cmpq %rcx, %r13
jb 0xa1f80
jmp 0xa21c5
cmpl %r9d, %r10d
setl 0x10(%rsp)
setg %r15b
cmpl %r8d, %edi
setg %r10b
setl %r14b
orb %r15b, %r10b
movl 0x40(%rsp), %r15d
cmpb $0x1, %r10b
jne 0xa20c8
orb 0x10(%rsp), %r14b
je 0xa20c8
cmpl 0x8(%rsp), %r12d
jl 0xa20c8
cmpl 0x8(%rsp), %ebp
jl 0xa20c8
addl %r15d, %r9d
subl %r9d, %r11d
xorl %r14d, %r14d
movl %edi, %r9d
subl %r8d, %r9d
setg %bpl
cmovlel %r11d, %r9d
testl %r9d, %r9d
js 0xa20c8
cmpl %r8d, %edi
setg %cl
testl %eax, %eax
setns %al
xorb %cl, %al
movzbl %al, %eax
leal (%rax,%rdx,2), %r8d
xorl $0x1, %r8d
movq 0x38(%rsp), %r15
movq %r15, %rdi
movq 0x18(%rsp), %r12
movq %r12, %rsi
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %ecx
callq 0xa1bb1
cmpl $0x1, %eax
jne 0xa20f7
movb %bpl, %r14b
movl $0x1, 0x48(%rsp,%r14,4)
incl 0x24(%rsp)
jmp 0xa20f7
movl 0x24(%rsp), %eax
testl %eax, %eax
movq 0x50(%rsp), %rdx
je 0xa2413
testl %ecx, %ecx
je 0xa241d
movl $0x18, %ebp
xorl %r15d, %r15d
movq (%r14), %rbx
movq (%rbx,%rbp), %rcx
movq %rcx, 0x10(%rsp)
testq %rcx, %rcx
js 0xa231d
movq -0x18(%rbx,%rbp), %rax
movq %rax, %r13
shrq $0x20, %r13
leaq (,%r13,2), %rsi
addq %r13, %rsi
movq 0x18(%rsp), %rcx
movl (%rcx,%rsi,4), %edi
testl %edi, %edi
js 0xa231d
movl -0xc(%rbx,%rbp), %ecx
movq %rcx, 0x28(%rsp)
leaq (%rcx,%rcx,2), %rcx
movq 0x18(%rsp), %rdx
leaq (%rdx,%rcx,4), %rcx
movl (%rcx), %edx
testl %edx, %edx
js 0xa231d
movl 0x4(%rcx), %ecx
subl %edx, %ecx
cmpl $0x0, 0x10(%rsp)
js 0xa2262
movl -0x8(%rbx,%rbp), %r10d
movl -0x4(%rbx,%rbp), %r8d
subl %r8d, %ecx
movl %ecx, %edx
movl %r10d, %ecx
jmp 0xa2272
movl -0x8(%rbx,%rbp), %r10d
movl -0x4(%rbx,%rbp), %r8d
subl %r8d, %ecx
movl %r10d, %edx
movq 0x18(%rsp), %r9
leaq (%r9,%rsi,4), %rsi
movl 0x4(%rsi), %esi
subl %edi, %esi
cmpl %eax, %ecx
movl %eax, %r12d
cmovll %ecx, %r12d
movl -0x10(%rbx,%rbp), %edi
movl %esi, %r14d
subl %edi, %r14d
cmpl %edx, %r14d
movl %edx, %r9d
cmovll %r14d, %r9d
cmpl 0xc(%rsp), %r12d
jg 0xa231d
cmpl 0xc(%rsp), %r9d
jg 0xa231d
movl %edi, %r11d
subl %eax, %r11d
xorps %xmm1, %xmm1
cvtsi2ss %r11, %xmm1
addl %r12d, %r11d
addl %r9d, %r11d
xorps %xmm2, %xmm2
cvtsi2ss %r11, %xmm2
movq %r8, 0x40(%rsp)
movl %edx, %r8d
movl %r10d, %edx
movl %edi, %r10d
leaq 0x1f347c(%rip), %rdi    # 0x295758
movss 0x158(%rdi), %xmm0
movl %r10d, %edi
movl %edx, %r10d
movl %r8d, %edx
movq 0x40(%rsp), %r8
mulss %xmm0, %xmm2
ucomiss %xmm1, %xmm2
ja 0xa231d
subl %r10d, %r8d
xorps %xmm1, %xmm1
cvtsi2ss %r8, %xmm1
addl %r12d, %r9d
addl %r8d, %r9d
xorps %xmm2, %xmm2
cvtsi2ss %r9, %xmm2
mulss %xmm2, %xmm0
ucomiss %xmm1, %xmm0
jbe 0xa233b
incq %r15
movq 0x30(%rsp), %r14
movl 0xc(%r14), %eax
addq $0x28, %rbp
cmpq %rax, %r15
jb 0xa21e6
jmp 0xa242c
cmpl %edx, %r14d
setl %r8b
setg %r14b
cmpl %ecx, %eax
setg %r12b
setl %r10b
orb %r14b, %r12b
cmpb $0x1, %r12b
jne 0xa231d
orb %r8b, %r10b
je 0xa231d
cmpl 0x8(%rsp), %r11d
jl 0xa231d
cmpl 0x8(%rsp), %r9d
jl 0xa231d
cmpl $0x0, 0x10(%rsp)
setns %r8b
addl %edi, %edx
subl %edx, %esi
movl %eax, %edi
subl %ecx, %edi
setg %dl
cmovlel %esi, %edi
testl %edi, %edi
js 0xa231d
xorl %esi, %esi
cmpl %ecx, %eax
setle %sil
cmpl $0x1, 0x48(%rsp,%rsi,4)
je 0xa231d
xorb %dl, %r8b
movzbl %r8b, %eax
movq 0x28(%rsp), %rcx
leal (%rax,%rcx,2), %r8d
xorl $0x1, %r8d
movq 0x38(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0xc(%rsp), %edx
movl 0x8(%rsp), %ecx
callq 0xa1bb1
cmpl $0x1, %eax
je 0xa231d
movabsq $-0x8000000000000000, %rax # imm = 0x8000000000000000
movq 0x10(%rsp), %rcx
orq %rax, %rcx
movq %rcx, (%rbx,%rbp)
movq 0x38(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x28(%rsp), %rdx
movl %r13d, %ecx
callq 0xa1aa3
testq %rax, %rax
je 0xa231d
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
orq %rcx, 0x18(%rax)
jmp 0xa231d
leaq (%r12,%rdx,4), %rax
orb $-0x80, 0x3(%rax)
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x24(%rsp), %eax
jmp 0xa241d