// File: /workspace/github_cpp_makefile_star2_O3/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 $0x218, %rsp            # imm = 0x218
movq %r9, 0xb8(%rsp)
movq %r8, 0xb0(%rsp)
movq %rcx, 0xa8(%rsp)
movq %rdx, 0x80(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
callq 0x2f3fc
movl 0x14(%rbx), %eax
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
movapd %xmm0, 0xd0(%rsp)
movapd %xmm0, 0xe0(%rsp)
movapd %xmm0, 0xf0(%rsp)
movapd %xmm0, 0x100(%rsp)
movapd %xmm0, 0x110(%rsp)
movapd %xmm0, 0x120(%rsp)
movq %rcx, 0x130(%rsp)
movapd %xmm0, 0x1b0(%rsp)
movapd %xmm0, 0x1c0(%rsp)
movapd %xmm0, 0x1d0(%rsp)
movapd %xmm0, 0x1e0(%rsp)
movapd %xmm0, 0x1f0(%rsp)
movapd %xmm0, 0x200(%rsp)
movq %rcx, 0x210(%rsp)
movapd %xmm0, 0x140(%rsp)
movapd %xmm0, 0x150(%rsp)
movapd %xmm0, 0x160(%rsp)
movapd %xmm0, 0x170(%rsp)
movapd %xmm0, 0x180(%rsp)
movapd %xmm0, 0x190(%rsp)
movq $0x0, 0x40(%rsp)
movq %rcx, 0x1a0(%rsp)
addl %eax, %eax
je 0xcff6a
movq %r14, %rsi
movl 0x250(%rsp), %ecx
addl $-0x3, %ecx
movl %ecx, 0x74(%rsp)
movl %eax, %r8d
xorl %r9d, %r9d
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq $0x0, 0x40(%rsp)
movq %r14, (%rsp)
movq %r8, 0x30(%rsp)
movq 0x28(%rbx), %rax
movq (%rax,%r9,8), %rdi
cmpl $0x2, %edi
jb 0xcff5e
movq 0x20(%rbx), %rax
movl %r9d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xcff5e
cmpb $0x1, 0x4(%rax,%rcx,8)
je 0xcff5e
movq %rdi, %rbp
andq %r13, %rbp
je 0xcff5e
movq %r9, 0x38(%rsp)
movq 0x8(%rbx), %rax
movq %rdi, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdx
movq %rdx, 0x8(%rsp)
leaq (%rax,%rcx,8), %r14
addq $0xc, %r14
leaq (,%rbp,8), %rax
leaq (%rax,%rax,2), %rax
xorl %ecx, %ecx
xorl %r15d, %r15d
movl (%r14,%rcx), %edx
notl %edx
shrl $0x1f, %edx
addl %edx, %r15d
addq $0x18, %rcx
cmpq %rcx, %rax
jne 0xcf8fc
cmpl $0x2, %r15d
jb 0xcff54
movq %rdi, 0x18(%rsp)
movq $-0x1, 0x20(%rsp)
xorl %r12d, %r12d
movl $0x0, 0x50(%rsp)
movq $-0x1, 0x10(%rsp)
cmpl $0x0, (%r14)
js 0xcf9b7
movl -0x4(%r14), %edx
movq %rbx, %rdi
leaq 0x2c(%rsp), %rcx
leaq 0x88(%rsp), %r8
leaq 0x68(%rsp), %r9
pushq $0x0
pushq $0x1
leaq 0xa0(%rsp), %rax
pushq %rax
leaq 0xb0(%rsp), %rax
pushq %rax
callq 0x1053a7
addq $0x20, %rsp
cmpl $0x7, %eax
je 0xcf9b3
cmpl $0x5, %eax
jne 0xcf989
incl 0x50(%rsp)
movq (%rsp), %rsi
movq 0x68(%rsp), %rax
movq 0x20(%rsp), %rdx
cmpq %rax, %rdx
movq 0x10(%rsp), %rcx
cmovlq %r12, %rcx
movq %rcx, 0x10(%rsp)
cmovleq %rax, %rdx
movq %rdx, 0x20(%rsp)
jmp 0xcf9b7
movq (%rsp), %rsi
incq %r12
addq $0x18, %r14
cmpq %r12, %rbp
jne 0xcf93d
movq 0x20(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0xa0(%rsp)
movl 0x50(%rsp), %eax
testl %eax, %eax
movq 0x8(%rsp), %rcx
je 0xcff54
cmpl %eax, %r15d
movq 0x260(%rsp), %r14
movq 0x18(%rsp), %r15
jne 0xcfa5b
subq $0x8, %rsp
movq %rbx, %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
movl %r15d, %ecx
leaq 0xc8(%rsp), %r8
leaq 0xa8(%rsp), %r9
movl 0x258(%rsp), %eax
pushq %rax
leaq 0xe0(%rsp), %rax
pushq %rax
pushq $0x1
callq 0xcf495
movq 0x28(%rsp), %rcx
movq 0x20(%rsp), %rsi
addq $0x20, %rsp
movq 0xa0(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x10(%rsp), %rax
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rax
addq $0x8, %rax
movq %rax, 0x58(%rsp)
movl %r15d, %edx
xorl %edi, %edi
movl $0x0, 0x28(%rsp)
movq %rdx, 0x48(%rsp)
cmpq %rdi, 0x10(%rsp)
je 0xcfe9f
leaq (%rdi,%rdi,2), %rax
cmpl $0x0, 0xc(%rcx,%rax,8)
js 0xcfe9f
movq %rdi, 0x18(%rsp)
leaq (%rcx,%rax,8), %rax
movq $0x0, 0x108(%rsp)
movq %rax, 0x60(%rsp)
movl 0x8(%rax), %edx
movq %rbx, %rdi
leaq 0x2c(%rsp), %rcx
leaq 0x88(%rsp), %r8
leaq 0x68(%rsp), %r9
leaq 0xd0(%rsp), %rax
pushq %rax
pushq $0x1
leaq 0xa0(%rsp), %rax
pushq %rax
leaq 0xb0(%rsp), %rax
pushq %rax
callq 0x1053a7
addq $0x20, %rsp
cmpl $0x5, %eax
jne 0xcfe8c
cmpl $-0x2, 0x74(%rsp)
movq (%rsp), %rsi
jb 0xcfc3b
movl 0x108(%rsp), %r13d
testq %r13, %r13
je 0xcfb9f
movq 0x118(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x10(%rsi), %rax
xorl %r12d, %r12d
xorl %edi, %edi
xorl %r15d, %r15d
xorl %r14d, %r14d
movl %edi, 0x20(%rsp)
movq 0x50(%rsp), %rbp
movl (%rbp,%r12,4), %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rdi
movl 0x250(%rsp), %esi
leaq 0x7c(%rsp), %rdx
leaq 0x78(%rsp), %rcx
leaq 0xcc(%rsp), %r8
callq 0xd0648
movl 0x20(%rsp), %edi
movq (%rsp), %rsi
addl 0x7c(%rsp), %r14d
addl 0x78(%rsp), %r15d
movq 0x10(%rsi), %rax
movl (%rbp,%r12,4), %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
addl 0x10(%rax,%rcx,8), %edi
incq %r12
cmpq %r12, %r13
jne 0xcfb3a
jmp 0xcfba7
xorl %r14d, %r14d
xorl %r15d, %r15d
xorl %edi, %edi
movl %r15d, %eax
addl %r14d, %eax
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
je 0xcfc33
movl %r14d, %ecx
cvtsi2sd %rcx, %xmm0
movl %eax, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x161a61(%rip), %xmm1   # 0x231630
ucomisd %xmm0, %xmm1
jae 0xcfc33
testl %r15d, %r15d
sete %al
cmpl $0x14, %r14d
setae %cl
testb %al, %cl
jne 0xcfead
cmpl $0x64, %edi
jb 0xcfc03
movl %edi, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x16100f(%rip), %xmm1   # 0x230c10
jmp 0xcfc29
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
mulsd 0x160ffe(%rip), %xmm1   # 0x230c10
cmpl $0x32, %edi
jb 0xcfc21
mulsd 0x1619d1(%rip), %xmm1   # 0x2315f0
jmp 0xcfc29
mulsd 0x1619a7(%rip), %xmm1   # 0x2315d0
ucomisd %xmm0, %xmm1
jbe 0xcfead
movq 0x260(%rsp), %r14
movq 0x58(%rsp), %rax
movl (%rax), %ecx
movq 0x60(%rsp), %rax
movl 0x8(%rax), %r8d
movq %rbx, %rdi
movq 0x80(%rsp), %rdx
movq 0xa8(%rsp), %r9
pushq $0x1
pushq 0xb8(%rsp)
movq 0x268(%rsp), %rax
pushq 0xa0(%rax)
pushq 0xd0(%rsp)
leaq 0x160(%rsp), %rax
pushq %rax
leaq 0x1d8(%rsp), %rax
pushq %rax
callq 0x105913
addq $0x30, %rsp
testl %eax, %eax
jne 0xcfe8c
movq 0x108(%rsp), %rdx
testq %rdx, %rdx
je 0xcfde9
movq 0x20(%rbx), %rax
movq 0x118(%rsp), %rcx
xorl %esi, %esi
movl (%rcx,%rsi,4), %edi
shrl %edi
movb $0x1, 0x4(%rax,%rdi,8)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rdx
ja 0xcfcbe
xorl %eax, %eax
movq 0x118(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, %esi
shrl %esi
movq 0x20(%rbx), %rdi
cmpb $0x1, 0x4(%rdi,%rsi,8)
jne 0xcfdd3
andl $-0x2, %ecx
movb $0x1, %dl
xorl %esi, %esi
orq %rcx, %rsi
movq 0x28(%rbx), %rdi
movq (%rdi,%rsi,8), %r8
movq %r8, %rdi
andq %r13, %rdi
je 0xcfdb0
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 0xcfda4
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 0xcfda4
orl $0x80000000, %r10d      # imm = 0x80000000
movl %r10d, 0xc(%r14)
xorq $0x1, %r11
movq 0x28(%rbx), %r10
movq (%r10,%r11,8), %r11
movq %r11, %r10
andq %r13, %r10
je 0xcfda4
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 0xcfd9b
orb $-0x80, 0x3(%r11,%r14)
addq $0x18, %r14
cmpq %r14, %r10
jne 0xcfd89
incq %r9
cmpq %rdi, %r9
jne 0xcfd23
movl $0x1, %esi
testb $0x1, %dl
movl $0x0, %edx
jne 0xcfcf9
movq 0x108(%rsp), %rdx
movq 0x260(%rsp), %r14
incl %eax
cmpq %rax, %rdx
ja 0xcfcd4
cmpq $0x0, 0x258(%rsp)
je 0xcfe30
movq 0x58(%rsp), %rax
movl 0x4(%rax), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rdx
movq 0x60(%rsp), %rcx
movl 0xc(%rcx), %r8d
andq %rax, %r8
leaq 0x1b0(%rsp), %rsi
leaq 0x140(%rsp), %rcx
movq (%rsp), %r9
pushq 0x258(%rsp)
pushq 0x88(%rsp)
callq 0xbe511
addq $0x10, %rsp
testq %r14, %r14
movq 0x60(%rsp), %rcx
je 0xcfe7c
movq 0x58(%rsp), %rax
movl 0x4(%rax), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rdx
movl 0xc(%rcx), %r8d
andq %rax, %r8
subq $0x8, %rsp
leaq 0x1674c9(%rip), %rdi    # 0x237325
leaq 0x1b8(%rsp), %rsi
leaq 0x148(%rsp), %rcx
movq 0x8(%rsp), %r9
pushq %r14
callq 0x1990ae
addq $0x10, %rsp
movq 0x40(%rsp), %rax
incl %eax
movq %rax, 0x40(%rsp)
incl 0x28(%rsp)
movq (%rsp), %rsi
movq 0x8(%rsp), %rcx
movq 0x48(%rsp), %rdx
movq 0x18(%rsp), %rdi
incq %rdi
cmpq %rdx, %rdi
jne 0xcfa83
jmp 0xcfeb7
movq 0x260(%rsp), %r14
jmp 0xcfe90
cmpl $0x0, 0x28(%rsp)
je 0xcff54
movq $0x0, 0x108(%rsp)
movl 0x10(%rsp), %eax
leaq (%rax,%rax,2), %rax
movl 0x8(%rcx,%rax,8), %edx
movq %rbx, %rdi
leaq 0x2c(%rsp), %rcx
leaq 0x88(%rsp), %r8
leaq 0x68(%rsp), %r9
leaq 0xd0(%rsp), %rax
pushq %rax
pushq $0x1
leaq 0xa0(%rsp), %rax
pushq %rax
leaq 0xb0(%rsp), %rax
pushq %rax
callq 0x1053a7
addq $0x20, %rsp
movq 0x108(%rsp), %rax
testq %rax, %rax
movq 0x30(%rsp), %r8
movq 0x38(%rsp), %r9
je 0xcff4e
movq 0x20(%rbx), %rcx
movq 0x118(%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 0xcff3a
movq (%rsp), %rsi
jmp 0xcff5e
movq 0x30(%rsp), %r8
movq 0x38(%rsp), %r9
incq %r9
cmpq %r8, %r9
jne 0xcf88b
movq %rbx, %rdi
callq 0xa0a7d
movq %rbx, %rdi
callq 0xa0ab6
movq %rbx, %rdi
callq 0xa0b79
orb $-0x80, 0x17(%rbx)
movq 0x118(%rsp), %rdi
callq 0x2220
movq 0x1f8(%rsp), %rdi
callq 0x2220
movq 0x188(%rsp), %rdi
callq 0x2220
movq 0x40(%rsp), %rax
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq