// File: /workspace/github_cpp_makefile_star2_O1/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 $0x228, %rsp            # imm = 0x228
movq %r9, 0xc8(%rsp)
movq %r8, 0xc0(%rsp)
movq %rcx, 0xb8(%rsp)
movq %rdx, 0x88(%rsp)
movq %rsi, (%rsp)
movq %rdi, %rbx
callq 0x300fc
movl 0x14(%rbx), %eax
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
movapd %xmm0, 0xe0(%rsp)
movapd %xmm0, 0xf0(%rsp)
movapd %xmm0, 0x100(%rsp)
movapd %xmm0, 0x110(%rsp)
movapd %xmm0, 0x120(%rsp)
movapd %xmm0, 0x130(%rsp)
movq %rcx, 0x140(%rsp)
movapd %xmm0, 0x1c0(%rsp)
movapd %xmm0, 0x1d0(%rsp)
movapd %xmm0, 0x1e0(%rsp)
movapd %xmm0, 0x1f0(%rsp)
movapd %xmm0, 0x200(%rsp)
movapd %xmm0, 0x210(%rsp)
movq %rcx, 0x220(%rsp)
movapd %xmm0, 0x150(%rsp)
movapd %xmm0, 0x160(%rsp)
movapd %xmm0, 0x170(%rsp)
movapd %xmm0, 0x180(%rsp)
movapd %xmm0, 0x190(%rsp)
movapd %xmm0, 0x1a0(%rsp)
movq $0x0, 0x20(%rsp)
movq %rcx, 0x1b0(%rsp)
addl %eax, %eax
je 0xced00
movl 0x260(%rsp), %ecx
addl $-0x3, %ecx
movl %ecx, 0x74(%rsp)
movl %eax, %r9d
xorl %r10d, %r10d
movq $0x0, 0x20(%rsp)
movq %r9, 0x48(%rsp)
movq 0x28(%rbx), %rax
movq (%rax,%r10,8), %rsi
cmpl $0x2, %esi
jb 0xcecf4
movq 0x20(%rbx), %rax
movl %r10d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xcecf4
cmpb $0x1, 0x4(%rax,%rcx,8)
je 0xcecf4
movq 0x8(%rbx), %rax
movq %rsi, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
movq %rsi, 0x8(%rsp)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdx, %rsi
je 0xce665
leaq (%rax,%rcx,8), %rdx
addq $0xc, %rdx
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rsi
xorl %edi, %edi
xorl %ebp, %ebp
movl (%rdx,%rdi), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %ebp
addq $0x18, %rdi
cmpq %rdi, %rsi
jne 0xce64c
jmp 0xce667
xorl %ebp, %ebp
cmpl $0x2, %ebp
jb 0xcecf4
movq %r10, 0x50(%rsp)
leaq (%rax,%rcx,8), %rdx
movq %rdx, 0x28(%rsp)
movq $-0x1, %r13
movq %r13, 0xa8(%rsp)
movq %r13, 0x40(%rsp)
movq 0x8(%rsp), %rdx
cmpl $0x1, %edx
movl %edx, %r12d
adcl $0x0, %r12d
leaq (%rax,%rcx,8), %r14
addq $0xc, %r14
xorl %r15d, %r15d
movl $0x0, 0x38(%rsp)
movq $-0x1, 0x10(%rsp)
cmpl $0x0, (%r14)
js 0xce727
movl -0x4(%r14), %edx
movq %rbx, %rdi
movq (%rsp), %rsi
leaq 0x1c(%rsp), %rcx
leaq 0x90(%rsp), %r8
leaq 0x68(%rsp), %r9
pushq $0x0
pushq $0x1
leaq 0xa8(%rsp), %rax
pushq %rax
leaq 0xb8(%rsp), %rax
pushq %rax
callq 0x10109f
addq $0x20, %rsp
cmpl $0x7, %eax
je 0xce727
cmpl $0x5, %eax
jne 0xce70d
incl 0x38(%rsp)
movq 0x68(%rsp), %rax
cmpq %rax, %r13
movq 0x10(%rsp), %rcx
cmovlq %r15, %rcx
movq %rcx, 0x10(%rsp)
cmovleq %rax, %r13
incq %r15
addq $0x18, %r14
cmpq %r15, %r12
jne 0xce6bd
movq %r13, 0xa8(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x40(%rsp)
movl 0x38(%rsp), %eax
testl %eax, %eax
movq 0x268(%rsp), %r14
je 0xcecea
cmpl %eax, %ebp
movq 0x270(%rsp), %r13
movq 0x8(%rsp), %r15
movq 0x28(%rsp), %r12
jne 0xce7aa
subq $0x8, %rsp
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
movl %r15d, %ecx
leaq 0xb0(%rsp), %r8
leaq 0x48(%rsp), %r9
movl 0x268(%rsp), %eax
pushq %rax
leaq 0xf0(%rsp), %rax
pushq %rax
pushq $0x1
callq 0xce1cd
addq $0x20, %rsp
movq 0x40(%rsp), %rbp
leaq (,%rbp,2), %rax
addq %rbp, %rax
leaq 0x8(%r12,%rax,8), %rcx
movq %rcx, 0xb0(%rsp)
leaq (%r12,%rax,8), %rax
addq $0xc, %rax
movq %rax, 0x80(%rsp)
cmpl $0x1, %r15d
adcl $0x0, %r15d
xorl %ecx, %ecx
movl $0x0, 0x18(%rsp)
movq %r15, 0x8(%rsp)
movq %rbp, 0x58(%rsp)
cmpq %rcx, %rbp
je 0xcec40
leaq (%rcx,%rcx,2), %rax
cmpl $0x0, 0xc(%r12,%rax,8)
js 0xcec40
movq %rcx, 0x30(%rsp)
leaq (%r12,%rax,8), %rax
movq $0x0, 0x118(%rsp)
movq %rax, 0x60(%rsp)
movl 0x8(%rax), %edx
movq %rbx, %rdi
movq (%rsp), %rsi
leaq 0x1c(%rsp), %rcx
leaq 0x90(%rsp), %r8
leaq 0x68(%rsp), %r9
leaq 0xe0(%rsp), %rax
pushq %rax
pushq $0x1
leaq 0xa8(%rsp), %rax
pushq %rax
leaq 0xb8(%rsp), %rax
pushq %rax
callq 0x10109f
addq $0x20, %rsp
cmpl $0x5, %eax
jne 0xcec3b
cmpl $-0x2, 0x74(%rsp)
jb 0xce9b9
movl 0x118(%rsp), %r14d
testq %r14, %r14
je 0xce90e
movq 0x128(%rsp), %rax
movq %rax, 0x38(%rsp)
movq (%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0xd0(%rsp)
xorl %r12d, %r12d
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %esi, %esi
movl %esi, 0x10(%rsp)
movq 0x38(%rsp), %rax
movl (%rax,%r12,4), %eax
shrl %eax
leaq (%rax,%rax,4), %rax
movq 0xd0(%rsp), %rsi
leaq (%rsi,%rax,8), %r13
movq %r13, %rdi
movl 0x260(%rsp), %esi
leaq 0x7c(%rsp), %rdx
leaq 0x78(%rsp), %rcx
leaq 0xdc(%rsp), %r8
callq 0xcf440
movl 0x10(%rsp), %esi
addl 0x7c(%rsp), %esi
addl 0x78(%rsp), %ebp
addl 0x10(%r13), %r15d
incq %r12
cmpq %r12, %r14
jne 0xce8b4
jmp 0xce915
xorl %esi, %esi
xorl %ebp, %ebp
xorl %r15d, %r15d
movl %ebp, %eax
addl %esi, %eax
movq 0x270(%rsp), %r13
je 0xce9a2
movl %esi, %ecx
cvtsi2sd %rcx, %xmm0
movl %eax, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x156bf4(%rip), %xmm1   # 0x225530
ucomisd %xmm0, %xmm1
jae 0xce9a2
testl %ebp, %ebp
sete %al
cmpl $0x14, %esi
setae %cl
testb %al, %cl
jne 0xcec24
cmpl $0x64, %r15d
jb 0xce970
movl %r15d, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x156262(%rip), %xmm1   # 0x224bd0
jmp 0xce998
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
mulsd 0x156250(%rip), %xmm1   # 0x224bd0
cmpl $0x32, %r15d
jb 0xce990
mulsd 0x156b62(%rip), %xmm1   # 0x2254f0
jmp 0xce998
mulsd 0x156b38(%rip), %xmm1   # 0x2254d0
ucomisd %xmm0, %xmm1
jbe 0xcec24
movq 0x268(%rsp), %r14
movq 0x8(%rsp), %r15
movq 0x28(%rsp), %r12
movq 0x58(%rsp), %rbp
movq 0xb0(%rsp), %rax
movl (%rax), %ecx
movq 0x60(%rsp), %rax
movl 0x8(%rax), %r8d
movq %rbx, %rdi
movq (%rsp), %rsi
movq 0x88(%rsp), %rdx
movq 0xb8(%rsp), %r9
pushq $0x1
pushq 0xc8(%rsp)
pushq 0xa0(%r14)
pushq 0xe0(%rsp)
leaq 0x170(%rsp), %rax
pushq %rax
leaq 0x1e8(%rsp), %rax
pushq %rax
callq 0x1015d1
addq $0x30, %rsp
testl %eax, %eax
jne 0xcec3b
movq 0x118(%rsp), %rax
testq %rax, %rax
je 0xcea4c
movq 0x20(%rbx), %rcx
movq 0x128(%rsp), %rdx
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
shrl %edi
movb $0x1, 0x4(%rcx,%rdi,8)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rax
ja 0xcea38
cmpq $0x0, 0x118(%rsp)
je 0xceb64
xorl %eax, %eax
movq 0x128(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, %edx
shrl %edx
movq 0x20(%rbx), %rsi
cmpb $0x1, 0x4(%rsi,%rdx,8)
jne 0xceb54
andl $-0x2, %ecx
xorl %edx, %edx
leaq (%rdx,%rcx), %rsi
movq 0x28(%rbx), %rdi
movq (%rdi,%rsi,8), %r8
movq %r8, %rdi
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
andq %r9, %rdi
je 0xceb44
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 0xceb38
leaq (%r8,%r11,8), %r14
movq 0x20(%rbx), %r15
movl 0x8(%r14), %r11d
movl %r11d, %r12d
shrl %r12d
cmpb $0x1, 0x4(%r15,%r12,8)
je 0xceb38
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 0xceb38
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 0xceb2f
orb $-0x80, 0x3(%r11,%r14)
addq $0x18, %r14
cmpq %r14, %r10
jne 0xceb1d
incq %r9
cmpq %rdi, %r9
jne 0xceab1
leaq 0x1(%rdx), %rsi
testq %rdx, %rdx
movq %rsi, %rdx
je 0xcea80
incl %eax
cmpq %rax, 0x118(%rsp)
ja 0xcea5d
movq 0x268(%rsp), %r14
testq %r14, %r14
je 0xcebb5
movq 0x80(%rsp), %rax
movl (%rax), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rdx
movq 0x60(%rsp), %rcx
movl 0xc(%rcx), %r8d
andq %rax, %r8
leaq 0x1c0(%rsp), %rsi
leaq 0x150(%rsp), %rcx
movq (%rsp), %r9
pushq %r14
pushq 0x90(%rsp)
callq 0xbd407
addq $0x10, %rsp
testq %r13, %r13
movq 0x8(%rsp), %r15
movq 0x28(%rsp), %r12
movq 0x58(%rsp), %rbp
movq 0x60(%rsp), %rcx
je 0xcec12
movq 0x80(%rsp), %rax
movl (%rax), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rdx
movl 0xc(%rcx), %r8d
andq %rax, %r8
subq $0x8, %rsp
leaq 0x15c543(%rip), %rdi    # 0x22b135
leaq 0x1c8(%rsp), %rsi
leaq 0x158(%rsp), %rcx
movq 0x8(%rsp), %r9
pushq %r13
callq 0x1902f0
addq $0x10, %rsp
movq 0x20(%rsp), %rax
incl %eax
movq %rax, 0x20(%rsp)
incl 0x18(%rsp)
jmp 0xcec3b
movq 0x268(%rsp), %r14
movq 0x8(%rsp), %r15
movq 0x28(%rsp), %r12
movq 0x58(%rsp), %rbp
movq 0x30(%rsp), %rcx
incq %rcx
cmpq %r15, %rcx
jne 0xce7f3
cmpl $0x0, 0x18(%rsp)
je 0xcecea
movl 0x40(%rsp), %eax
movq $0x0, 0x118(%rsp)
leaq (%rax,%rax,2), %rax
movl 0x8(%r12,%rax,8), %edx
movq %rbx, %rdi
movq (%rsp), %rsi
leaq 0x1c(%rsp), %rcx
leaq 0x90(%rsp), %r8
leaq 0x68(%rsp), %r9
leaq 0xe0(%rsp), %rax
pushq %rax
pushq $0x1
leaq 0xa8(%rsp), %rax
pushq %rax
leaq 0xb8(%rsp), %rax
pushq %rax
callq 0x10109f
addq $0x20, %rsp
movq 0x118(%rsp), %rax
testq %rax, %rax
movq 0x48(%rsp), %r9
movq 0x50(%rsp), %r10
je 0xcecf4
movq 0x20(%rbx), %rcx
movq 0x128(%rsp), %rdx
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
shrl %edi
movb $0x2, 0x4(%rcx,%rdi,8)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rax
ja 0xcecd4
jmp 0xcecf4
movq 0x48(%rsp), %r9
movq 0x50(%rsp), %r10
incq %r10
cmpq %r9, %r10
jne 0xce5eb
movq %rbx, %rdi
callq 0xa02fa
movq %rbx, %rdi
callq 0xa0333
movq %rbx, %rdi
callq 0xa03e9
orb $-0x80, 0x17(%rbx)
movq 0x128(%rsp), %rdi
callq 0x2220
movq 0x208(%rsp), %rdi
callq 0x2220
movq 0x198(%rsp), %rdi
callq 0x2220
movq 0x20(%rsp), %rax
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq