// File: /workspace/github_cpp_makefile_star2_O2/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, 0x14(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, %rbx
callq 0x251c
movl 0x14(%rbx), %r15d
addl %r15d, %r15d
xorl %r13d, %r13d
movl $0x0, 0xc(%rsp)
movq %r15, 0x18(%rsp)
cmpq %r15, %r13
je 0xaac45
movq 0x30(%rbx), %rax
cmpb $0x0, (%rax,%r13)
je 0xaab4b
incq %r13
jmp 0xaab32
movq 0x28(%rbx), %rax
movq (%rax,%r13,8), %r14
testl $0xfffffffe, %r14d      # imm = 0xFFFFFFFE
je 0xaab46
movq 0x20(%rbx), %rax
movl %r13d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xaab46
movq 0x8(%rbx), %r12
movq %rbx, %rdi
movl %r13d, %esi
xorl %edx, %edx
callq 0xc2e7a
cmpl $0x2, %eax
jb 0xaab46
movq %r14, %rax
shrq $0x20, %rax
movl %r14d, %ecx
imulq $0x18, %rcx, %r15
imulq $0x18, %rax, %rax
addq %rax, %r12
addq $0xc, %r12
xorl %r14d, %r14d
movl $0x0, 0x10(%rsp)
pushq $-0x1
popq %rbp
cmpq %r14, %r15
je 0xaac3b
movl (%r12,%r14), %eax
testl %eax, %eax
js 0xaac32
movl -0x4(%r12,%r14), %esi
cmpl $-0x1, %ebp
je 0xaac2c
movl %ebp, %edi
movq %rbx, %rdx
movq 0x20(%rsp), %rcx
movq 0x28(%rsp), %r8
movq 0x30(%rsp), %r9
callq 0x70fd8
testq %rax, %rax
jne 0xaac32
movl (%r12,%r14), %eax
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cvtsi2ss %ecx, %xmm0
cvtsi2ssl 0x10(%rsp), %xmm1
mulss 0x14(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0xaac32
orl $0x80000000, %eax       # imm = 0x80000000
movl %eax, (%r12,%r14)
movl -0x8(%r12,%r14), %edx
movl -0x4(%r12,%r14), %esi
xorl $0x1, %esi
xorl $0x1, %edx
movq %rbx, %rdi
pushq $0x1
popq %rcx
callq 0x6db50
incl 0xc(%rsp)
jmp 0xaac32
movl %eax, 0x10(%rsp)
movl %esi, %ebp
addq $0x18, %r14
jmp 0xaaba8
movq 0x18(%rsp), %r15
jmp 0xaab46
movl 0xc(%rsp), %ebp
testl %ebp, %ebp
je 0xaac5d
movq %rbx, %rdi
callq 0x694eb
movq %rbx, %rdi
callq 0x69638
movl %ebp, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq