// File: /workspace/github_cpp_makefile_star2_O1/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 $0xe8, %rsp
movq %r8, 0x78(%rsp)
movl %ecx, 0x24(%rsp)
movq %rdx, 0x70(%rsp)
movq %rsi, 0x68(%rsp)
movq %rdi, %rbx
callq 0x300fc
movl 0x14(%rbx), %eax
xorpd %xmm0, %xmm0
movapd %xmm0, 0xd0(%rsp)
movapd %xmm0, 0xc0(%rsp)
movapd %xmm0, 0xb0(%rsp)
movapd %xmm0, 0xa0(%rsp)
movapd %xmm0, 0x90(%rsp)
movapd %xmm0, 0x80(%rsp)
movq $0x0, 0xe0(%rsp)
addl %eax, %eax
je 0xbddc3
movl %eax, %r15d
xorl %r12d, %r12d
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
xorl %ebp, %ebp
movq 0x20(%rbx), %rax
movl %r12d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xbdbea
cmpb $0x1, 0x4(%rax,%rcx,8)
je 0xbdbea
movq 0x28(%rbx), %rax
movq (%rax,%r12,8), %rcx
movq %rcx, %rdx
andq %r14, %rdx
je 0xbd97f
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 0xbd960
testl %edi, %edi
jne 0xbdbea
movl %r12d, %r13d
xorl $0x1, %r13d
movq (%rax,%r13,8), %rax
movq %rax, %rcx
andq %r14, %rcx
je 0xbdbea
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 0xbd9b6
cmpl $0x1, %esi
jne 0xbdbea
movq %rbx, %rdi
movl %r13d, %esi
leaq 0x1c(%rsp), %rdx
leaq 0x30(%rsp), %rcx
xorl %r8d, %r8d
callq 0xa96f6
andl $0x5, %eax
cmpl $0x1, %eax
jne 0xbdbea
movq %r15, 0x38(%rsp)
movl %ebp, 0x20(%rsp)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0x40(%rsp)
movl 0x1c(%rsp), %eax
xorq $0x1, %rax
movl %eax, 0x1c(%rsp)
movq 0x8(%rbx), %rdx
movq 0x28(%rbx), %rcx
movq (%rcx,%rax,8), %rax
movq %rax, %rcx
shrq $0x20, %rcx
testl %eax, %eax
movq %r13, 0x60(%rsp)
movq %rdx, 0x28(%rsp)
movq %rcx, 0x58(%rsp)
je 0xbda8e
movq %rax, 0x48(%rsp)
movl %eax, %ebp
leaq (%rcx,%rcx,2), %rax
leaq (%rdx,%rax,8), %r13
addq $0xc, %r13
xorl %r15d, %r15d
cmpl $0x0, (%r13)
js 0xbda7a
movl -0x4(%r13), %esi
movq %rbx, %rdi
leaq 0x1c(%rsp), %rdx
leaq 0x30(%rsp), %rcx
xorl %r8d, %r8d
callq 0xa96f6
movl 0x1c(%rsp), %eax
cmpq %rax, %r12
je 0xbda96
incq %r15
addq $0x18, %r13
cmpq %r15, %rbp
jne 0xbda51
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0xbda9f
movl $0xffffffff, %r15d      # imm = 0xFFFFFFFF
jmp 0xbdaa4
movl 0x30(%rsp), %eax
movq %rax, 0x40(%rsp)
movq 0x48(%rsp), %rax
testl %eax, %eax
je 0xbdbe1
movl %eax, %eax
movq 0x58(%rsp), %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x28(%rsp), %rdx
leaq (%rdx,%rcx,8), %rcx
addq $0x8, %rcx
movq %rcx, 0x28(%rsp)
shlq $0x3, %r15
leaq (%r15,%r15,2), %rbp
shlq $0x3, %rax
leaq (%rax,%rax,2), %r13
xorl %r15d, %r15d
cmpq %r15, %rbp
je 0xbdbd4
movq 0x28(%rsp), %rax
cmpl $0x0, 0x4(%rax,%r15)
js 0xbdbd4
movq 0x28(%rsp), %rax
movl (%rax,%r15), %esi
movl 0x24(%rsp), %eax
movl %eax, (%rsp)
movq %rbx, %rdi
leaq 0x1c(%rsp), %rdx
leaq 0x30(%rsp), %rcx
leaq 0x50(%rsp), %r8
xorl %r9d, %r9d
callq 0xa99b4
movq 0x30(%rsp), %rax
cmpq 0x40(%rsp), %rax
jle 0xbdbd4
xorps %xmm0, %xmm0
cvtsi2sdq 0x50(%rsp), %xmm0
mulsd 0x16c026(%rip), %xmm0   # 0x229b68
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xbdbd4
movq $0x0, 0xb8(%rsp)
movq %rbx, %rdi
movq 0x60(%rsp), %r14
movl %r14d, %esi
leaq 0x1c(%rsp), %rdx
leaq 0x30(%rsp), %rcx
leaq 0x80(%rsp), %r8
callq 0xa96f6
movq 0xb8(%rsp), %rax
cmpq $0x2, %rax
jb 0xbdbfb
decq %rax
movq %rax, 0xb8(%rsp)
movq 0x28(%rsp), %rax
movl (%rax,%r15), %esi
movq 0x78(%rsp), %rax
movq %rax, 0x8(%rsp)
movl %r14d, %edi
movq %rbx, %rdx
movq 0x68(%rsp), %rcx
movq 0x70(%rsp), %r8
movl 0x24(%rsp), %r9d
callq 0xa9f5e
cmpq $0x1, %rax
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
je 0xbdc0c
addq $0x18, %r15
cmpq %r15, %r13
jne 0xbdadc
movl 0x20(%rsp), %ebp
movq 0x38(%rsp), %r15
incq %r12
cmpq %r15, %r12
jne 0xbd912
jmp 0xbddc5
movl 0x20(%rsp), %ebp
movq 0x38(%rsp), %r15
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0xbdbea
movq 0xb8(%rsp), %rax
testq %rax, %rax
je 0xbdc37
movq 0x20(%rbx), %rcx
movq 0xc8(%rsp), %rdx
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
movb $0x1, 0x4(%rcx,%rdi,8)
incq %rsi
cmpq %rsi, %rax
jne 0xbdc27
cmpq $0x0, 0xb8(%rsp)
je 0xbdd49
xorl %eax, %eax
movq 0xc8(%rsp), %rcx
movq %rax, 0x40(%rsp)
movl (%rcx,%rax,4), %ecx
movq 0x20(%rbx), %rdx
cmpb $0x1, 0x4(%rdx,%rcx,8)
jne 0xbdd33
addl %ecx, %ecx
xorl %edx, %edx
leaq (%rdx,%rcx), %rsi
movq 0x28(%rbx), %rdi
movq (%rdi,%rsi,8), %r8
movq %r8, %rdi
andq %r14, %rdi
je 0xbdd23
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 0xbdd17
leaq (%r8,%r11,8), %r13
movq 0x20(%rbx), %rbp
movl 0x8(%r13), %eax
movl %eax, %r11d
shrl %r11d
cmpb $0x1, 0x4(%rbp,%r11,8)
je 0xbdd17
orl $0x80000000, %r10d      # imm = 0x80000000
movl %r10d, 0xc(%r13)
xorq $0x1, %rax
movq 0x28(%rbx), %r10
movq (%r10,%rax,8), %r11
movq %r11, %r10
andq %r14, %r10
je 0xbdd17
movq 0x8(%rbx), %rax
shrq $0x20, %r11
shlq $0x3, %r10
leaq (%r10,%r10,2), %r10
leaq (%r11,%r11,2), %r11
leaq (%rax,%r11,8), %r11
addq $0xc, %r11
xorl %r13d, %r13d
movl -0x4(%r11,%r13), %eax
xorl %esi, %eax
cmpl $0x1, %eax
jne 0xbdd0e
orb $-0x80, 0x3(%r11,%r13)
addq $0x18, %r13
cmpq %r13, %r10
jne 0xbdcfc
incq %r9
cmpq %rdi, %r9
jne 0xbdc96
leaq 0x1(%rdx), %rax
testq %rdx, %rdx
movq %rax, %rdx
je 0xbdc6b
movq 0x40(%rsp), %rax
incq %rax
cmpq 0xb8(%rsp), %rax
jb 0xbdc48
movl 0x20(%rsp), %ebp
incl %ebp
movq $0x0, 0xb8(%rsp)
movq 0x28(%rsp), %rax
movl (%rax,%r15), %esi
movl 0x24(%rsp), %eax
movl %eax, (%rsp)
movq %rbx, %rdi
leaq 0x1c(%rsp), %rdx
leaq 0x30(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x80(%rsp), %r9
callq 0xa99b4
movq 0xb8(%rsp), %rax
testq %rax, %rax
je 0xbdbe5
movq 0x20(%rbx), %rcx
movq 0xc8(%rsp), %rdx
xorl %esi, %esi
movq 0x38(%rsp), %r15
movl (%rdx,%rsi,4), %edi
movb $0x2, 0x4(%rcx,%rdi,8)
incq %rsi
cmpq %rsi, %rax
jne 0xbddae
jmp 0xbdbea
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0xa02fa
movq %rbx, %rdi
callq 0xa0333
movq %rbx, %rdi
callq 0xa03e9
orb $-0x80, 0x17(%rbx)
movq 0xc8(%rsp), %rdi
callq 0x2220
movl %ebp, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq