// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: asg_arc_cut_long_equal_tips_assembly_complex(asg_t*, ma_hit_t_alloc*, long long, unsigned int, R_to_U*)
int asg_arc_cut_long_equal_tips_assembly_complex(asg_t *g, ma_hit_t_alloc* reverse_sources, 
long long miniedgeLen, uint32_t stops_threshold, R_to_U* ruIndex)
{
    double startTime = Get_T();
    ///the reason is that each read has two direction (query->target, target->query)
    uint32_t v, n_vtx = g->n_seq * 2, n_reduced = 0, convex, flag;
    long long ll, max_stopLen;

    buf_t b;
    memset(&b, 0, sizeof(buf_t));

    for (v = 0; v < n_vtx; ++v) 
    {

        uint32_t i;
        ///some node could be deleted
        if (g->seq[v>>1].del || g->seq[v>>1].c == ALTER_LABLE) continue;
        ///tip
        if (get_real_length(g, v, NULL) != 0) continue;
        if(get_real_length(g, v^1, NULL) != 1) continue;
        flag = detect_single_path_with_dels_contigLen(g, v^1, &convex, &ll, NULL);
        if(flag != TWO_INPUT && flag != MUL_INPUT) continue;
        convex = convex^1;
        ///uint32_t n_convex = asg_arc_n(g, convex), convexLen = ll;
        uint32_t n_convex = asg_arc_n(g, convex), convexLen = (uint32_t)-1, convex_i = (uint32_t)-1;
        asg_arc_t *a_convex = asg_arc_a(g, convex);
        for (i = 0; i < n_convex; i++)
        {
            if (!a_convex[i].del)
            {
                detect_single_path_with_dels_contigLen(g, a_convex[i].v, &convex, &ll, NULL);
                if(convex == v)
                {
                    convexLen = ll;
                    convex_i = i;
                    break;
                }
            }
        }

        
        for (i = 0; i < n_convex; i++)
        {
            if (!a_convex[i].del)
            {
                if(i == convex_i) continue;
                
                detect_single_path_with_dels_contigLen_complex(g, a_convex[i].v, &convex, &ll, 
                &max_stopLen, NULL, stops_threshold);
                ///threshold = 0.8
                if(ll > convexLen  && max_stopLen*1.25>ll)
                {
                    ///keep all nodes of this tip
                    b.b.n = 0; 
                    detect_single_path_with_dels_contigLen(g, v^1, &convex, &ll, &b);
                    if(b.b.n < 2) break;
                    b.b.n--;
                    ///keep all nodes of this tip

                     //we can only cut tips
                    if(check_if_diploid_primary_complex(v^1, a_convex[i].v, g, 
                    reverse_sources, miniedgeLen, stops_threshold, 1, ruIndex)==1)
                    {
                        n_reduced++;
                        uint64_t k;

                        for (k = 0; k < b.b.n; k++)
                        {
                            g->seq[b.b.a[k]].c = ALTER_LABLE;
                        }
                        for (k = 0; k < b.b.n; k++)
                        {
                            asg_seq_drop(g, b.b.a[k]);
                        }


                        ///lable the primary one
                        b.b.n = 0; 
                        detect_single_path_with_dels_contigLen_complex(g, a_convex[i].v, &convex, 
                        &ll, &max_stopLen, &b, stops_threshold);
                        for (k = 0; k < b.b.n; k++)
                        {
                            g->seq[b.b.a[k]].c = HAP_LABLE;
                        }

                        break;
                    }

                }
                
            }
        }    
    }


    asg_cleanup(g);
    asg_symm(g);
    free(b.b.a);
    
    if(VERBOSE >= 1)
    {
        fprintf(stderr, "[M::%s] removed %d long tips\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 $0xd8, %rsp
movq %r8, %r14
movl %ecx, 0x24(%rsp)
movq %rdx, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movq %rdi, %rbx
callq 0x2f3fc
movl 0x14(%rbx), %eax
xorpd %xmm0, %xmm0
movapd %xmm0, 0xc0(%rsp)
movapd %xmm0, 0xb0(%rsp)
movapd %xmm0, 0xa0(%rsp)
movapd %xmm0, 0x90(%rsp)
movapd %xmm0, 0x80(%rsp)
movapd %xmm0, 0x70(%rsp)
movq $0x0, 0xd0(%rsp)
addl %eax, %eax
je 0xbedda
movl %eax, %r13d
xorl %r12d, %r12d
xorl %r15d, %r15d
movq %r13, 0x18(%rsp)
movq 0x20(%rbx), %rax
movl %r12d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xbec0f
cmpb $0x1, 0x4(%rax,%rcx,8)
je 0xbec0f
movq 0x28(%rbx), %rax
movq (%rax,%r12,8), %rcx
movq %rcx, %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rdx
je 0xbe9b9
movq 0x8(%rbx), %rsi
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rsi,%rcx,8), %rcx
addq $0xc, %rcx
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
xorl %esi, %esi
xorl %edi, %edi
movl (%rcx,%rsi), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %edi
addq $0x18, %rsi
cmpq %rsi, %rdx
jne 0xbe99a
testl %edi, %edi
jne 0xbec0f
movl %r12d, %ebp
xorl $0x1, %ebp
movq (%rax,%rbp,8), %rax
movq %rax, %rcx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rcx
je 0xbec0a
movq 0x8(%rbx), %rdx
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%rdx,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
xorl %esi, %esi
movl (%rax,%rdx), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %esi
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0xbe9f4
cmpl $0x1, %esi
jne 0xbec0a
movq %rbx, %rdi
movl %ebp, %esi
leaq 0x10(%rsp), %rdx
leaq 0x30(%rsp), %rcx
xorl %r8d, %r8d
callq 0xaa787
andl $0x5, %eax
cmpl $0x1, %eax
jne 0xbec0a
movl 0x10(%rsp), %eax
xorq $0x1, %rax
movl %eax, 0x10(%rsp)
movq 0x28(%rbx), %rcx
movq (%rcx,%rax,8), %rcx
testl %ecx, %ecx
je 0xbec0a
movl %r15d, 0x14(%rsp)
movq %r14, 0x40(%rsp)
movq 0x8(%rbx), %rdx
movq %rcx, %rax
shrq $0x20, %rax
movq %rcx, 0x28(%rsp)
movl %ecx, %r13d
shlq $0x3, %rax
leaq (%rax,%rax,2), %rax
movq %rdx, 0x38(%rsp)
movq %rax, 0x58(%rsp)
leaq (%rdx,%rax), %r14
addq $0xc, %r14
xorl %r15d, %r15d
cmpl $0x0, (%r14)
js 0xbeab1
movl -0x4(%r14), %esi
movq %rbx, %rdi
leaq 0x10(%rsp), %rdx
leaq 0x30(%rsp), %rcx
xorl %r8d, %r8d
callq 0xaa787
movl 0x10(%rsp), %eax
cmpq %rax, %r12
je 0xbeacf
incq %r15
addq $0x18, %r14
cmpq %r15, %r13
jne 0xbea89
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x48(%rsp)
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0xbead8
movl 0x30(%rsp), %eax
movq %rax, 0x48(%rsp)
cmpl $0x0, 0x28(%rsp)
movq 0x40(%rsp), %r14
je 0xbec05
movq 0x38(%rsp), %rax
movq 0x58(%rsp), %rcx
addq %rcx, %rax
addq $0x8, %rax
movq %rax, 0x28(%rsp)
shlq $0x3, %r15
leaq (%r15,%r15,2), %rax
movq %rax, 0x38(%rsp)
shlq $0x3, %r13
leaq (%r13,%r13,2), %r13
xorl %r15d, %r15d
cmpq %r15, 0x38(%rsp)
je 0xbebf8
movq 0x28(%rsp), %rax
cmpl $0x0, 0x4(%rax,%r15)
js 0xbebf8
movq 0x28(%rsp), %rax
movl (%rax,%r15), %esi
movl 0x24(%rsp), %eax
movl %eax, (%rsp)
movq %rbx, %rdi
leaq 0x10(%rsp), %rdx
leaq 0x30(%rsp), %rcx
leaq 0x50(%rsp), %r8
xorl %r9d, %r9d
callq 0xaaa5d
movq 0x30(%rsp), %rax
cmpq 0x48(%rsp), %rax
jle 0xbebf8
xorps %xmm0, %xmm0
cvtsi2sdq 0x50(%rsp), %xmm0
mulsd 0x1771e1(%rip), %xmm0   # 0x235d60
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xbebf8
movq $0x0, 0xa8(%rsp)
movq %rbx, %rdi
movl %ebp, %esi
leaq 0x10(%rsp), %rdx
leaq 0x30(%rsp), %rcx
leaq 0x70(%rsp), %r8
callq 0xaa787
movq 0xa8(%rsp), %rax
cmpq $0x2, %rax
jb 0xbec05
decq %rax
movq %rax, 0xa8(%rsp)
movq 0x28(%rsp), %rax
movl (%rax,%r15), %esi
movq %r14, 0x8(%rsp)
movl %ebp, %edi
movq %rbx, %rdx
movq 0x60(%rsp), %rcx
movq 0x68(%rsp), %r8
movl 0x24(%rsp), %r9d
callq 0xaafd5
cmpq $0x1, %rax
je 0xbec20
addq $0x18, %r15
cmpq %r15, %r13
jne 0xbeb17
movl 0x14(%rsp), %r15d
movq 0x18(%rsp), %r13
incq %r12
cmpq %r13, %r12
jne 0xbe947
jmp 0xbeddd
movq 0xa8(%rsp), %rdx
testq %rdx, %rdx
movq 0x18(%rsp), %r13
je 0xbed69
movq 0x20(%rbx), %rax
movq 0xb8(%rsp), %rcx
xorl %esi, %esi
movl (%rcx,%rsi,4), %edi
movb $0x1, 0x4(%rax,%rdi,8)
incq %rsi
cmpq %rsi, %rdx
jne 0xbec44
xorl %eax, %eax
movq 0xb8(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
movq 0x20(%rbx), %rsi
cmpb $0x1, 0x4(%rsi,%rcx,8)
jne 0xbed5d
addl %ecx, %ecx
movb $0x1, %dl
xorl %esi, %esi
orq %rcx, %rsi
movq 0x28(%rbx), %rdi
movq (%rdi,%rsi,8), %r8
movq %r8, %rdi
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
andq %r9, %rdi
je 0xbed38
shrq $0x20, %r8
leaq (%r8,%r8,2), %r8
shlq $0x3, %r8
addq 0x8(%rbx), %r8
xorl %r9d, %r9d
leaq (%r9,%r9,2), %r11
movl 0xc(%r8,%r11,8), %r10d
testl %r10d, %r10d
js 0xbed2c
leaq (%r8,%r11,8), %r14
movq 0x20(%rbx), %r13
movl 0x8(%r14), %r11d
movl %r11d, %ebp
shrl %ebp
cmpb $0x1, 0x4(%r13,%rbp,8)
je 0xbed2c
orl $0x80000000, %r10d      # imm = 0x80000000
movl %r10d, 0xc(%r14)
xorq $0x1, %r11
movq 0x28(%rbx), %r10
movq (%r10,%r11,8), %r11
movq %r11, %r10
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
andq %r14, %r10
je 0xbed2c
movq 0x8(%rbx), %r14
shrq $0x20, %r11
shlq $0x3, %r10
leaq (%r10,%r10,2), %r10
leaq (%r11,%r11,2), %r11
leaq (%r14,%r11,8), %r11
addq $0xc, %r11
xorl %r14d, %r14d
movl -0x4(%r11,%r14), %ebp
xorl %esi, %ebp
cmpl $0x1, %ebp
jne 0xbed23
orb $-0x80, 0x3(%r11,%r14)
addq $0x18, %r14
cmpq %r14, %r10
jne 0xbed11
incq %r9
cmpq %rdi, %r9
jne 0xbeca6
movl $0x1, %esi
testb $0x1, %dl
movl $0x0, %edx
jne 0xbec76
movq 0xa8(%rsp), %rdx
movq 0x40(%rsp), %r14
movq 0x18(%rsp), %r13
incq %rax
cmpq %rdx, %rax
jb 0xbec56
incl 0x14(%rsp)
movq $0x0, 0xa8(%rsp)
movq 0x28(%rsp), %rax
movl (%rax,%r15), %esi
movl 0x24(%rsp), %eax
movl %eax, (%rsp)
movq %rbx, %rdi
leaq 0x10(%rsp), %rdx
leaq 0x30(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x70(%rsp), %r9
callq 0xaaa5d
movq 0xa8(%rsp), %rax
testq %rax, %rax
je 0xbedd0
movq 0x20(%rbx), %rcx
movq 0xb8(%rsp), %rdx
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
movb $0x2, 0x4(%rcx,%rdi,8)
incq %rsi
cmpq %rsi, %rax
jne 0xbedc0
movl 0x14(%rsp), %r15d
jmp 0xbec0f
xorl %r15d, %r15d
movq %rbx, %rdi
callq 0xa0a7d
movq %rbx, %rdi
callq 0xa0ab6
movq %rbx, %rdi
callq 0xa0b79
orb $-0x80, 0x17(%rbx)
movq 0xb8(%rsp), %rdi
callq 0x2220
movl %r15d, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq