// File: 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
movq %rsp, %rbp
subq $0xf0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
callq 0x2510
movsd %xmm0, -0x30(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
leaq -0xc0(%rbp), %rdi
xorl %esi, %esi
movl $0x68, %edx
callq 0x2100
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0xfb655
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0xfb249
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl 0x4(%rax,%rcx,8), %eax
cmpl $0x1, %eax
jne 0xfb24e
jmp 0xfb647
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x0, %eax
je 0xfb268
jmp 0xfb647
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x166b50
cmpl $0x1, %eax
je 0xfb285
jmp 0xfb647
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
xorl $0x1, %esi
leaq -0x40(%rbp), %rdx
leaq -0x50(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0xdb740
movl %eax, -0x44(%rbp)
cmpl $0x1, -0x44(%rbp)
je 0xfb2b5
cmpl $0x3, -0x44(%rbp)
je 0xfb2b5
jmp 0xfb647
movl -0x40(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x40(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x40(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0xc8(%rbp)
movl $0xffffffff, -0xcc(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0xd0(%rbp) # imm = 0xFFFFFFFF
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x40(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0xd8(%rbp)
movl $0x0, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
cmpl -0xc8(%rbp), %eax
jae 0xfb3b0
movq -0xd8(%rbp), %rax
movl -0xc4(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0xfb39a
movq -0x8(%rbp), %rdi
movq -0xd8(%rbp), %rax
movl -0xc4(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
leaq -0x40(%rbp), %rdx
leaq -0x50(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
callq 0xdb740
movl -0x40(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0xfb398
movq -0x50(%rbp), %rax
movl %eax, -0xcc(%rbp)
movl -0xc4(%rbp), %eax
movl %eax, -0xd0(%rbp)
jmp 0xfb3b0
jmp 0xfb39a
jmp 0xfb39c
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0xfb31a
movl $0x0, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
cmpl -0xc8(%rbp), %eax
jae 0xfb645
movq -0xd8(%rbp), %rax
movl -0xc4(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0xfb62f
movl -0xc4(%rbp), %eax
cmpl -0xd0(%rbp), %eax
jne 0xfb402
jmp 0xfb631
movq -0x8(%rbp), %rdi
movq -0xd8(%rbp), %rax
movl -0xc4(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
movl -0x1c(%rbp), %eax
leaq -0x40(%rbp), %rdx
leaq -0x50(%rbp), %rcx
leaq -0x58(%rbp), %r8
xorl %r9d, %r9d
movl %eax, (%rsp)
callq 0xdbba0
movq -0x50(%rbp), %rax
movl -0xcc(%rbp), %ecx
cmpq %rcx, %rax
jle 0xfb62d
cvtsi2sdq -0x58(%rbp), %xmm0
movsd 0x28b3e8(%rip), %xmm1   # 0x386840
mulsd %xmm1, %xmm0
cvtsi2sdq -0x50(%rbp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0xfb62d
movq $0x0, -0x88(%rbp)
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %esi
xorl $0x1, %esi
leaq -0x40(%rbp), %rdx
leaq -0x50(%rbp), %rcx
leaq -0xc0(%rbp), %r8
callq 0xdb740
cmpq $0x2, -0x88(%rbp)
jae 0xfb4a4
jmp 0xfb645
movq -0x88(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x88(%rbp)
movl -0x34(%rbp), %edi
xorl $0x1, %edi
movq -0xd8(%rbp), %rax
movl -0xc4(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
movq -0x8(%rbp), %rdx
movq -0x10(%rbp), %rcx
movq -0x18(%rbp), %r8
movl -0x1c(%rbp), %r9d
movq -0x28(%rbp), %rax
movl $0x1, (%rsp)
movq %rax, 0x8(%rsp)
callq 0xdc410
cmpq $0x1, %rax
jne 0xfb62b
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
movq $0x0, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
cmpq -0x88(%rbp), %rax
jae 0xfb555
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x78(%rbp), %rcx
movq -0xe0(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movb $0x1, 0x4(%rax,%rcx,8)
movq -0xe0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe0(%rbp)
jmp 0xfb516
movq $0x0, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
cmpq -0x88(%rbp), %rax
jae 0xfb59b
movq -0x8(%rbp), %rdi
movq -0x78(%rbp), %rax
movq -0xe0(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0xf6800
movq -0xe0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe0(%rbp)
jmp 0xfb560
movq $0x0, -0x88(%rbp)
movq -0x8(%rbp), %rdi
movq -0xd8(%rbp), %rax
movl -0xc4(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
movl -0x1c(%rbp), %eax
leaq -0x40(%rbp), %rdx
leaq -0x50(%rbp), %rcx
leaq -0x58(%rbp), %r8
leaq -0xc0(%rbp), %r9
movl %eax, (%rsp)
callq 0xdbba0
movq $0x0, -0xe0(%rbp)
movq -0xe0(%rbp), %rax
cmpq -0x88(%rbp), %rax
jae 0xfb629
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x78(%rbp), %rcx
movq -0xe0(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movb $0x2, 0x4(%rax,%rcx,8)
movq -0xe0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xe0(%rbp)
jmp 0xfb5ea
jmp 0xfb645
jmp 0xfb62d
jmp 0xfb62f
jmp 0xfb631
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0xfb3ba
jmp 0xfb647
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xfb20a
movq -0x8(%rbp), %rdi
callq 0xcdd10
movq -0x8(%rbp), %rdi
callq 0xce020
movq -0x78(%rbp), %rdi
callq 0x2210
movl -0x3c(%rbp), %eax
addq $0xf0, %rsp
popq %rbp
retq
nopl (%rax)