// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: asg_arc_cut_trio_long_equal_tips_assembly(asg_t*, ma_ug_t*, asg_t*, ma_hit_t_alloc*, long long, R_to_U*, unsigned int, hap_cov_t*, utg_trans_t*)
int asg_arc_cut_trio_long_equal_tips_assembly(asg_t *g, ma_ug_t *ug, asg_t *read_sg, 
ma_hit_t_alloc* reverse_sources, long long miniedgeLen, R_to_U* ruIndex, uint32_t trio_flag,
hap_cov_t *cov, utg_trans_t *o)
{
    double startTime = Get_T();
    uint32_t v, n_vtx = g->n_seq * 2, n_reduced = 0, convex, flag, is_hap, n_tips, return_flag, k;
    long long ll, base_maxLen, base_maxLen_i, max_stop_nodeLen, max_stop_baseLen, tmp;
    buf_t b, b_0, b_1;
    memset(&b, 0, sizeof(buf_t));
    memset(&b_0, 0, sizeof(buf_t));
    memset(&b_1, 0, sizeof(buf_t));

    for (v = 0; v < n_vtx; ++v) 
    {
        uint32_t i, n_arc = 0, nv = asg_arc_n(g, v);
        asg_arc_t *av = asg_arc_a(g, v);
        if (nv < 2 || g->seq[v>>1].del || g->seq[v>>1].c == ALTER_LABLE) continue;
        n_arc = get_real_length(g, v, NULL);
        if (n_arc < 2) continue;

        base_maxLen = -1;
        base_maxLen_i = -1;
        n_tips = 0;
        is_hap = 0;

        for (i = 0; i < nv; i++)
        {
            if(av[i].del) continue;
            return_flag = get_unitig(g, ug, av[i].v, &convex, &tmp, &ll, &max_stop_nodeLen, 
            &max_stop_baseLen, 1, NULL);

            if(return_flag==LOOP) continue;
            if(return_flag==END_TIPS) n_tips++;

            if(base_maxLen < ll)
            {
                base_maxLen = ll;
                base_maxLen_i = i;
            }
        }

        if(n_tips==0) continue;
        ///all the unitigs here are tips
        if(n_arc == n_tips)
        {
            renew_longest_tip_by_drop(g, ug, av, nv, &base_maxLen, 
            &base_maxLen_i, 1, &b, trio_flag);
        }

        for (i = 0; i < nv; i++)
        {
            if(i==base_maxLen_i) continue;
            if(av[i].del) continue;

            b.b.n = 0;
            return_flag = get_unitig(g, ug, av[i].v, &convex, &tmp, &ll, &max_stop_nodeLen, 
            &max_stop_baseLen, 1, &b);

            if(return_flag != END_TIPS) continue;
            if(trio_check(ug, b.b.a, b.b.n, trio_flag)) continue;

            flag = check_different_haps(g, ug, read_sg, av[base_maxLen_i].v, av[i].v,
            reverse_sources, &b_0, &b_1, ruIndex, cov->is_r_het, miniedgeLen, 1);

            // #define UNAVAILABLE (uint32_t)-1
            // #define PLOID 0
            // #define NON_PLOID 1
            if(flag != PLOID) continue;
            n_reduced++;

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

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

            if(cov)
            {
                collect_trans_cov(__func__, &b_0, av[base_maxLen_i].ol, &b_1, av[i].ol, ug, read_sg, cov);
            } 

            if(o)
            {
                collect_trans_ovlp(__func__, &b_0, av[base_maxLen_i].ol, &b_1, av[i].ol, ug, o);
            }
            

            is_hap++;
        }

        if(is_hap > 0)
        {
            i = base_maxLen_i;
            b.b.n = 0;
            get_unitig(g, ug, av[i].v, &convex, &tmp, &ll, &max_stop_nodeLen, 
            &max_stop_baseLen, 1, &b);

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

    asg_cleanup(g);
    asg_symm(g);
    free(b.b.a);
    free(b_0.b.a);
    free(b_1.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 $0x1d8, %rsp            # imm = 0x1D8
movq %r9, 0x80(%rsp)
movq %r8, 0x78(%rsp)
movq %rcx, 0x70(%rsp)
movq %rdx, 0x48(%rsp)
movq %rsi, %r13
movq %rdi, %rbx
callq 0x251c
movq %rbx, %rdi
movl 0x14(%rbx), %r12d
addl %r12d, %r12d
xorps %xmm0, %xmm0
leaq 0x90(%rsp), %rax
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
movaps %xmm0, 0x20(%rax)
movaps %xmm0, 0x30(%rax)
movaps %xmm0, 0x40(%rax)
movaps %xmm0, 0x50(%rax)
andq $0x0, 0x60(%rax)
leaq 0x170(%rsp), %rax
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
movaps %xmm0, 0x20(%rax)
movaps %xmm0, 0x30(%rax)
andq $0x0, 0x60(%rax)
movaps %xmm0, 0x40(%rax)
movaps %xmm0, 0x50(%rax)
leaq 0x100(%rsp), %rax
movaps %xmm0, (%rax)
movaps %xmm0, 0x10(%rax)
movaps %xmm0, 0x20(%rax)
movaps %xmm0, 0x30(%rax)
movaps %xmm0, 0x40(%rax)
movaps %xmm0, 0x50(%rax)
andq $0x0, 0x60(%rax)
xorl %r8d, %r8d
movl $0x0, 0x28(%rsp)
movq %r12, 0x38(%rsp)
movq %rbx, (%rsp)
cmpq %r12, %r8
je 0x94557
movq 0x28(%rdi), %rax
movq (%rax,%r8,8), %r15
cmpl $0x2, %r15d
jb 0x9454f
movq 0x20(%rdi), %rax
movl %r8d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0x9454f
cmpb $0x1, 0x4(%rax,%rcx,8)
je 0x9454f
movq %r8, %rsi
movq 0x8(%rdi), %r14
movq %r8, 0x30(%rsp)
xorl %edx, %edx
callq 0xc2e7a
cmpl $0x2, %eax
jae 0x94163
movq 0x30(%rsp), %r8
movq (%rsp), %rdi
jmp 0x9454f
movl %eax, 0xc(%rsp)
movq %r13, %r12
movq %r15, %rax
shrq $0x20, %rax
imulq $0x18, %rax, %rax
leaq (%r14,%rax), %rcx
movq %rcx, 0x18(%rsp)
movl %r15d, %edx
leaq (%r14,%rax), %rbp
addq $0xc, %rbp
xorl %r14d, %r14d
pushq $-0x1
popq %r13
movq %r13, %rbx
movl $0x0, 0x20(%rsp)
movq %rdx, 0x10(%rsp)
movq (%rsp), %rdi
cmpq %r14, %rdx
je 0x94218
cmpl $0x0, (%rbp)
js 0x9420f
movl -0x4(%rbp), %edx
movq %r12, %rsi
leaq 0x2c(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x40(%rsp), %r9
pushq $0x0
pushq $0x1
leaq 0x68(%rsp), %rax
pushq %rax
leaq 0x78(%rsp), %rax
pushq %rax
callq 0xc2ebf
addq $0x20, %rsp
cmpl $0x7, %eax
je 0x94206
cmpl $0x5, %eax
jne 0x941eb
incl 0x20(%rsp)
movq 0x10(%rsp), %rdx
movq (%rsp), %rdi
movq 0x40(%rsp), %rax
cmpq %rax, %r13
cmovlq %r14, %rbx
cmovleq %rax, %r13
jmp 0x9420f
movq 0x10(%rsp), %rdx
movq (%rsp), %rdi
incq %r14
addq $0x18, %rbp
jmp 0x941a4
movq %r13, 0x88(%rsp)
movq %rbx, 0x68(%rsp)
movl 0x20(%rsp), %eax
testl %eax, %eax
je 0x94542
cmpl %eax, 0xc(%rsp)
movq %r12, %r13
movq 0x218(%rsp), %r14
jne 0x94289
subq $0x8, %rsp
movq %r13, %rsi
movq 0x20(%rsp), %rdx
movl %r15d, %ecx
leaq 0x90(%rsp), %r8
leaq 0x70(%rsp), %r9
movl 0x218(%rsp), %eax
pushq %rax
leaq 0xa0(%rsp), %rax
pushq %rax
pushq $0x1
callq 0x93db2
movq 0x20(%rsp), %rdi
movq 0x30(%rsp), %rdx
addq $0x20, %rsp
movq 0x68(%rsp), %rbx
imulq $0x18, %rbx, %rax
movq 0x18(%rsp), %rcx
addq %rcx, %rax
addq $0x8, %rax
movq %rax, 0x20(%rsp)
movq %rcx, %rax
xorl %r15d, %r15d
movl $0x0, 0xc(%rsp)
movq 0x220(%rsp), %r12
cmpq %rdx, %r15
je 0x944b2
cmpq %r15, %rbx
je 0x9439d
imulq $0x18, %r15, %rbp
cmpl $0x0, 0xc(%rax,%rbp)
js 0x9439d
addq %rax, %rbp
andq $0x0, 0xc8(%rsp)
movl 0x8(%rbp), %edx
movq %r13, %rsi
leaq 0x2c(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x40(%rsp), %r9
leaq 0x90(%rsp), %rax
pushq %rax
pushq $0x1
leaq 0x68(%rsp), %rax
pushq %rax
leaq 0x78(%rsp), %rax
pushq %rax
callq 0xc2ebf
addq $0x20, %rsp
cmpl $0x5, %eax
jne 0x9438f
movq 0xd8(%rsp), %rsi
movl 0xc8(%rsp), %edx
movq %r13, %rdi
movl 0x210(%rsp), %ecx
callq 0xc3788
testl %eax, %eax
jne 0x9438f
movq 0x20(%rsp), %rax
movl (%rax), %ecx
movl 0x8(%rbp), %r8d
movq (%rsp), %rdi
movq %r13, %rsi
movq 0x48(%rsp), %rdx
movq 0x70(%rsp), %r9
pushq $0x1
pushq 0x80(%rsp)
pushq 0xa0(%r14)
pushq 0x98(%rsp)
leaq 0x120(%rsp), %rax
pushq %rax
leaq 0x198(%rsp), %rax
pushq %rax
callq 0xc3307
addq $0x30, %rsp
testl %eax, %eax
je 0x943a5
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rdx
movq (%rsp), %rdi
incq %r15
jmp 0x942b4
movq 0xc8(%rsp), %rax
movq 0xd8(%rsp), %rcx
xorl %edx, %edx
movq (%rsp), %rdi
movl %edx, %edx
cmpq %rdx, %rax
jbe 0x943d7
movq 0x20(%rdi), %rsi
movl (%rcx,%rdx,4), %r8d
shrl %r8d
movb $0x1, 0x4(%rsi,%r8,8)
incl %edx
jmp 0x943bb
xorl %ecx, %ecx
movl %ecx, %r14d
cmpq %r14, %rax
jbe 0x94406
movq 0xd8(%rsp), %rax
movl (%rax,%r14,4), %esi
shrl %esi
callq 0x80870
movq (%rsp), %rdi
leal 0x1(%r14), %ecx
movq 0xc8(%rsp), %rax
jmp 0x943d9
movq 0x218(%rsp), %r14
testq %r14, %r14
je 0x94451
movq 0x20(%rsp), %rax
movl 0x4(%rax), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rdx
movl 0xc(%rbp), %r8d
andq %rax, %r8
leaq 0x170(%rsp), %rsi
leaq 0x100(%rsp), %rcx
movq %r13, %r9
pushq %r14
pushq 0x50(%rsp)
callq 0x82b96
movq 0x10(%rsp), %rdi
addq $0x10, %rsp
testq %r12, %r12
je 0x9449b
movq 0x20(%rsp), %rax
movl 0x4(%rax), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rdx
movl 0xc(%rbp), %r8d
andq %rax, %r8
subq $0x8, %rsp
leaq 0x154dad(%rip), %rdi    # 0x1e9225
leaq 0x178(%rsp), %rsi
leaq 0x108(%rsp), %rcx
movq %r13, %r9
pushq %r12
callq 0x151bf8
movq 0x10(%rsp), %rdi
addq $0x10, %rsp
incl 0x28(%rsp)
incl 0xc(%rsp)
movq 0x18(%rsp), %rax
movq 0x10(%rsp), %rdx
jmp 0x9439d
cmpl $0x0, 0xc(%rsp)
je 0x94545
andq $0x0, 0xc8(%rsp)
movq %rax, %rcx
movl %ebx, %eax
imulq $0x18, %rax, %rax
movl 0x8(%rcx,%rax), %edx
movq %r13, %rsi
leaq 0x2c(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x40(%rsp), %r9
leaq 0x90(%rsp), %rax
pushq %rax
pushq $0x1
leaq 0x68(%rsp), %rax
pushq %rax
leaq 0x78(%rsp), %rax
pushq %rax
callq 0xc2ebf
movq 0x20(%rsp), %rdi
addq $0x20, %rsp
movq 0xc8(%rsp), %rax
movq 0xd8(%rsp), %rcx
xorl %edx, %edx
movq 0x38(%rsp), %r12
movq 0x30(%rsp), %r8
movl %edx, %edx
cmpq %rdx, %rax
jbe 0x9454f
movq 0x20(%rdi), %rsi
movl (%rcx,%rdx,4), %r9d
shrl %r9d
movb $0x2, 0x4(%rsi,%r9,8)
incl %edx
jmp 0x94526
movq %r12, %r13
movq 0x38(%rsp), %r12
movq 0x30(%rsp), %r8
incq %r8
jmp 0x94104
movq %rdi, %rbx
callq 0x694eb
movq %rbx, %rdi
callq 0x69638
movq 0xd8(%rsp), %rdi
callq 0x2220
movq 0x1b8(%rsp), %rdi
callq 0x2220
movq 0x148(%rsp), %rdi
callq 0x2220
movl 0x28(%rsp), %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq