// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: asg_arc_del_orthology_multiple_way(asg_t*, ma_hit_t_alloc*, float, long long, R_to_U*)
int asg_arc_del_orthology_multiple_way(asg_t *g, ma_hit_t_alloc* reverse_sources, float drop_ratio, 
long long miniedgeLen, R_to_U* ruIndex)
{
    double startTime = Get_T();
    ///the reason is that each read has two direction (query->target, target->query)
    uint32_t v, v_max, v_maxLen, n_vtx = g->n_seq * 2, n_reduced = 0;

    for (v = 0; v < n_vtx; ++v) 
    {
        if (g->seq_vis[v] != 0) continue;
        uint32_t i, n_arc = 0, nv = asg_arc_n(g, v);
        asg_arc_t *av = asg_arc_a(g, v);
        ///some node could be deleted
        if (nv < 2 || g->seq[v>>1].del) continue;
        n_arc = get_real_length(g, v, NULL);
        if (n_arc < 2) continue;
        v_max = (uint32_t)-1;
        v_maxLen = 0;

        for (i = 0, n_arc = 0; i < nv; i++)
        {
            if (!av[i].del)
            {
                if(v_max == (uint32_t)-1)
                {
                    v_max = av[i].v;
                    v_maxLen = av[i].ol;
                }
                else if(check_if_diploid(v_max, av[i].v, g, reverse_sources, miniedgeLen, ruIndex) == 0)
                {
                    if(av[i].ol < drop_ratio * v_maxLen)
                    {
                        ///fprintf(stderr, "v: %u, v_max: %u, av[%d].v: %u\n", v>>1, v_max>>1, i, av[i].v>>1);
                        
                        // av[i].ol = 1;///should be a bug
                        av[i].del = 1;
                        asg_arc_del(g, av[i].v^1, av[i].ul>>32^1, 1);
                        n_reduced++;
                    }
                }
            }
        }
    }

    if (n_reduced) {
        asg_cleanup(g);
        asg_symm(g);
    }

    if(VERBOSE >= 1)
    {
        fprintf(stderr, "[M::%s] removed %d different hap overlaps\n", 
        __func__, n_reduced);
        fprintf(stderr, "[M::%s] takes %0.2f s\n\n", __func__, Get_T()-startTime);
    }

    return n_reduced;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, 0x30(%rsp)
movq %rdx, 0x28(%rsp)
movss %xmm0, 0x1c(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, %rbx
callq 0x300fc
movq %rbx, %rdx
movl 0x14(%rbx), %eax
addl %eax, %eax
je 0xe78c9
movl %eax, %r8d
xorl %r14d, %r14d
movl $0x0, 0x4(%rsp)
movq %r8, 0x10(%rsp)
movq 0x30(%rdx), %rax
cmpb $0x0, (%rax,%r14)
jne 0xe78bb
movq 0x28(%rdx), %rax
movq (%rax,%r14,8), %r15
cmpl $0x2, %r15d
jb 0xe78bb
movq 0x20(%rdx), %rax
movl %r14d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xe78bb
movq %r15, %rax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
andq %rcx, %rax
je 0xe78bb
movq 0x8(%rdx), %rcx
movq %r15, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rcx,%rsi,8), %r12
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
xorl %edi, %edi
movl 0xc(%r12,%rcx), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %edi
addq $0x18, %rcx
cmpq %rcx, %rax
jne 0xe778b
cmpl $0x2, %edi
jb 0xe78bb
cmpl $0x1, %r15d
adcl $0x0, %r15d
xorl %ebp, %ebp
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl $0x0, 0xc(%rsp)
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
movl 0xc(%r12,%rcx,8), %eax
testl %eax, %eax
js 0xe78af
leaq (%r12,%rcx,8), %rbx
movl 0x8(%rbx), %esi
cmpl $-0x1, %edi
je 0xe78a9
movl %edi, 0x8(%rsp)
movq %rdx, %r13
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r9
callq 0xa9c9f
testq %rax, %rax
jne 0xe789b
movl 0xc(%rbx), %eax
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
xorps %xmm0, %xmm0
cvtsi2ss %ecx, %xmm0
xorps %xmm1, %xmm1
cvtsi2ssl 0xc(%rsp), %xmm1
mulss 0x1c(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0xe789b
orl $0x80000000, %eax       # imm = 0x80000000
movl %eax, 0xc(%rbx)
movl 0x8(%rbx), %eax
xorq $0x1, %rax
movq %r13, %rdx
movq 0x28(%r13), %rcx
movq (%rcx,%rax,8), %rdi
movq %rdi, %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %rcx
je 0xe7895
movl 0x4(%rbx), %eax
movq 0x8(%rdx), %rsi
shrq $0x20, %rdi
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rdi,%rdi,2), %rdi
leaq (%rsi,%rdi,8), %r8
addq $0xc, %r8
xorl %esi, %esi
movl -0x4(%r8,%rsi), %edi
xorl %eax, %edi
cmpl $0x1, %edi
jne 0xe788c
orb $-0x80, 0x3(%r8,%rsi)
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0xe787a
incl 0x4(%rsp)
jmp 0xe789e
movq %r13, %rdx
movq 0x10(%rsp), %r8
movl 0x8(%rsp), %edi
jmp 0xe78af
movl %eax, 0xc(%rsp)
movl %esi, %edi
incq %rbp
cmpq %r15, %rbp
jne 0xe77c0
incq %r14
cmpq %r8, %r14
jne 0xe7727
jmp 0xe78d1
movl $0x0, 0x4(%rsp)
movl 0x4(%rsp), %ebp
testl %ebp, %ebp
je 0xe78f8
movq %rdx, %rdi
movq %rdx, %rbx
callq 0xa02fa
movq %rbx, %rdi
callq 0xa0333
movq %rbx, %rdi
callq 0xa03e9
orb $-0x80, 0x17(%rbx)
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq