// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: asg_arc_cut_trio_long_equal_tips_assembly_complex(asg_t*, ma_ug_t*, asg_t*, ma_hit_t_alloc*, long long, R_to_U*, unsigned int, hap_cov_t*, utg_trans_t*, unsigned int)
int asg_arc_cut_trio_long_equal_tips_assembly_complex(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 stops_threshold, 
hap_cov_t *cov, utg_trans_t *o, uint32_t trio_flag)
{
    double startTime = Get_T();
    uint32_t v, n_vtx = g->n_seq * 2, n_reduced = 0, convex, in, flag;
    uint32_t return_flag, convex_i, k;
    long long ll, tmp, max_stop_nodeLen, max_stop_baseLen;

    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;
        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;

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

        if(return_flag != MUL_INPUT) continue;
        if(trio_check(ug, b.b.a, b.b.n, trio_flag)) continue;
        in = convex^1;
        get_real_length(g, convex, &convex);
        convex = convex^1;
        uint32_t n_convex = asg_arc_n(g, convex), convexLen = ll;
        asg_arc_t *a_convex = asg_arc_a(g, convex);
        for (i = 0; i < n_convex; i++)
        {
            if(a_convex[i].del) continue;
            if(a_convex[i].v == in) break;
        }
        convex_i = i;
        ///if(convex_i == n_convex) fprintf(stderr, "ERROR1\n");
        // if((v>>1) == 304 && (convex>>1) == 12875)
        // {
        //     fprintf(stderr, "\n++v-%u, convex-%u, n_convex-%u\n", v, convex, n_convex);
        // }

        for (i = 0; i < n_convex; i++)
        {
            if(a_convex[i].del) continue;
            if(i == convex_i) continue;

            return_flag = get_unitig(g, ug, a_convex[i].v, &convex, &tmp, &ll, &max_stop_nodeLen, 
            &max_stop_baseLen, stops_threshold, NULL);

            // if((v>>1) == 304 && n_convex == 2)
            // {
            //     fprintf(stderr, "---v-%u (len: %u), convex-%u, a_convex[i].v-%u (len: %lld), max_stop_baseLen: %lld\n", 
            //     v, convexLen, convex, a_convex[i].v, ll, max_stop_baseLen);
            // }

            if(ll>convexLen  && max_stop_baseLen>=ll*MAX_STOP_RATE)
            {
                flag = check_different_haps(g, ug, read_sg, a_convex[convex_i].v, a_convex[i].v,
                reverse_sources, &b_0, &b_1, ruIndex, cov->is_r_het, miniedgeLen, stops_threshold);
                // #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);
                }

                ///note: we need to remove b_0, insetad of b_1 here
                if(cov)
                {
                    collect_trans_cov(__func__, &b_1, a_convex[i].ol, &b_0, a_convex[convex_i].ol, ug, read_sg, cov);
                } 

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

                ///lable the primary one
                b_0.b.n = 0; 
                get_unitig(g, ug, a_convex[i].v, &convex, &tmp, &ll, &max_stop_nodeLen, 
                &max_stop_baseLen, stops_threshold, &b_0);
                for (k = 0; k < b_0.b.n; k++)
                {
                    g->seq[b_0.b.a[k]>>1].c = HAP_LABLE;
                }

                break;
            }
        }

    }

    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, %r14
movq %r8, %r15
movq %rcx, 0x88(%rsp)
movq %rdx, 0x70(%rsp)
movq %rsi, %r12
movq %rdi, %rbx
callq 0x300fc
movl 0x14(%rbx), %eax
xorl %r13d, %r13d
xorpd %xmm0, %xmm0
movapd %xmm0, 0x90(%rsp)
movapd %xmm0, 0xa0(%rsp)
movapd %xmm0, 0xb0(%rsp)
movapd %xmm0, 0xc0(%rsp)
movapd %xmm0, 0xd0(%rsp)
movapd %xmm0, 0xe0(%rsp)
movq %r13, 0xf0(%rsp)
movapd %xmm0, 0x100(%rsp)
movapd %xmm0, 0x110(%rsp)
movapd %xmm0, 0x120(%rsp)
movapd %xmm0, 0x130(%rsp)
movapd %xmm0, 0x140(%rsp)
movapd %xmm0, 0x150(%rsp)
movq %r13, 0x160(%rsp)
movapd %xmm0, 0x170(%rsp)
movapd %xmm0, 0x180(%rsp)
movapd %xmm0, 0x190(%rsp)
movapd %xmm0, 0x1a0(%rsp)
movapd %xmm0, 0x1b0(%rsp)
movapd %xmm0, 0x1c0(%rsp)
movq %r13, 0x1d0(%rsp)
addl %eax, %eax
je 0xcfcdf
movl 0x228(%rsp), %ecx
addl $-0x3, %ecx
movl %ecx, 0x60(%rsp)
movl %eax, %ebp
xorl %r11d, %r11d
xorl %r13d, %r13d
movq %r12, 0x10(%rsp)
movq 0x20(%rbx), %rax
movl %r11d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xcfcd3
cmpb $0x1, 0x4(%rax,%rcx,8)
je 0xcfcd3
movq 0x28(%rbx), %rax
movq (%rax,%r11,8), %rcx
movq %rcx, %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rdx
je 0xcf620
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 0xcf601
testl %edi, %edi
jne 0xcfcd3
movl %r11d, %edx
xorl $0x1, %edx
movq (%rax,%rdx,8), %rax
movq %rax, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0xcfcd3
movq 0x8(%rbx), %rsi
shrq $0x20, %rax
leaq (%rax,%rax,2), %rax
leaq (%rsi,%rax,8), %rax
addq $0xc, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %esi, %esi
xorl %edi, %edi
movl (%rax,%rsi), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %edi
addq $0x18, %rsi
cmpq %rsi, %rcx
jne 0xcf65b
cmpl $0x1, %edi
jne 0xcfcd3
movq %r11, 0x18(%rsp)
movq $0x0, 0xc8(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x4(%rsp), %rcx
leaq 0x80(%rsp), %r8
leaq 0x40(%rsp), %r9
leaq 0x90(%rsp), %rax
pushq %rax
pushq $0x1
leaq 0x68(%rsp), %rax
pushq %rax
leaq 0x90(%rsp), %rax
pushq %rax
callq 0x10109f
addq $0x20, %rsp
cmpl $0x3, %eax
jne 0xcfcce
cmpl $-0x2, 0x60(%rsp)
movq 0x18(%rsp), %r11
leaq 0x34(%rsp), %rdx
leaq 0x30(%rsp), %rcx
leaq 0x64(%rsp), %r8
movq %r13, 0x38(%rsp)
movq %rbp, 0x20(%rsp)
jb 0xcf822
movq %r15, 0x48(%rsp)
movq %r14, 0x68(%rsp)
movl 0xc8(%rsp), %ebp
testq %rbp, %rbp
je 0xcf788
movq 0xd8(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x10(%r12), %rax
movq %rax, 0x28(%rsp)
xorl %r15d, %r15d
xorl %edi, %edi
xorl %r14d, %r14d
xorl %r13d, %r13d
movl %edi, 0x8(%rsp)
movq 0x50(%rsp), %rax
movl (%rax,%r15,4), %eax
shrl %eax
leaq (%rax,%rax,4), %rax
movq 0x28(%rsp), %rdi
leaq (%rdi,%rax,8), %r12
movq %r12, %rdi
movl 0x228(%rsp), %esi
callq 0xcf440
movl 0x8(%rsp), %edi
leaq 0x64(%rsp), %r8
leaq 0x30(%rsp), %rcx
leaq 0x34(%rsp), %rdx
addl 0x34(%rsp), %r13d
addl 0x30(%rsp), %r14d
addl 0x10(%r12), %edi
incq %r15
cmpq %r15, %rbp
jne 0xcf731
jmp 0xcf790
xorl %r13d, %r13d
xorl %r14d, %r14d
xorl %edi, %edi
movl %r14d, %eax
addl %r13d, %eax
movq 0x48(%rsp), %r15
movq 0x18(%rsp), %r11
je 0xcf81d
movl %r13d, %ecx
cvtsi2sd %rcx, %xmm0
movl %eax, %eax
cvtsi2sd %rax, %xmm1
mulsd 0x155d77(%rip), %xmm1   # 0x225530
ucomisd %xmm0, %xmm1
jae 0xcf81d
testl %r14d, %r14d
sete %al
cmpl $0x14, %r13d
setae %cl
testb %al, %cl
jne 0xcfa20
cmpl $0x64, %edi
jb 0xcf7ed
movl %edi, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x1553e5(%rip), %xmm1   # 0x224bd0
jmp 0xcf813
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
mulsd 0x1553d4(%rip), %xmm1   # 0x224bd0
cmpl $0x32, %edi
jb 0xcf80b
mulsd 0x155ce7(%rip), %xmm1   # 0x2254f0
jmp 0xcf813
mulsd 0x155cbd(%rip), %xmm1   # 0x2254d0
ucomisd %xmm0, %xmm1
jbe 0xcfa20
movq 0x68(%rsp), %r14
movl 0x4(%rsp), %eax
movq 0x28(%rbx), %rcx
movq (%rcx,%rax,8), %rsi
movq %rsi, %rdx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %rdi, %rdx
je 0xcf872
movq 0x8(%rbx), %rdi
shrq $0x20, %rsi
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rsi,%rsi,2), %rsi
leaq (%rdi,%rsi,8), %rsi
addq $0xc, %rsi
xorl %edi, %edi
cmpl $0x0, (%rsi,%rdi)
js 0xcf869
movl -0x4(%rsi,%rdi), %r8d
movl %r8d, 0x4(%rsp)
addq $0x18, %rdi
cmpq %rdi, %rdx
jne 0xcf859
movl 0x4(%rsp), %edx
xorq $0x1, %rdx
movl %edx, 0x4(%rsp)
movq (%rcx,%rdx,8), %rcx
movq 0x8(%rbx), %rdx
movq %rcx, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
testl %ecx, %ecx
je 0xcf8c8
movl %ecx, %r8d
leaq (%rdx,%rsi,8), %r9
addq $0xc, %r9
xorl %edi, %edi
cmpl $0x0, (%r9)
js 0xcf8b5
movl -0x4(%r9), %r10d
xorl %eax, %r10d
cmpl $0x1, %r10d
je 0xcf8c4
incq %rdi
addq $0x18, %r9
cmpq %rdi, %r8
jne 0xcf8a2
movq %rcx, %rdi
movl %edi, %eax
jmp 0xcf8ca
xorl %eax, %eax
testl %ecx, %ecx
je 0xcfa0c
movl 0x40(%rsp), %edi
movq %rdi, 0x50(%rsp)
leaq (%rdx,%rsi,8), %rdi
shlq $0x3, %rax
leaq (%rax,%rax,2), %r12
addq %r12, %rdi
movq %rdi, 0x28(%rsp)
movl %ecx, %eax
leaq (%rdx,%rsi,8), %rdx
addq $0xc, %rdx
shlq $0x3, %rax
leaq (%rax,%rax,2), %r13
xorl %ebp, %ebp
movq %rdx, 0x8(%rsp)
cmpq %rbp, %r12
je 0xcf9ff
cmpl $0x0, (%rdx,%rbp)
js 0xcf9ff
movq 0x8(%rsp), %rax
movl -0x4(%rax,%rbp), %edx
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
leaq 0x4(%rsp), %rcx
leaq 0x80(%rsp), %r8
leaq 0x40(%rsp), %r9
pushq $0x0
movl 0x218(%rsp), %eax
pushq %rax
leaq 0x68(%rsp), %rax
pushq %rax
leaq 0x90(%rsp), %rax
pushq %rax
callq 0x10109f
movq 0x28(%rsp), %rdx
movq 0x38(%rsp), %r11
addq $0x20, %rsp
movq 0x40(%rsp), %rax
cmpq 0x50(%rsp), %rax
jle 0xcf9ff
xorps %xmm0, %xmm0
cvtsi2sdq 0x58(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x155af4(%rip), %xmm1   # 0x225488
ucomisd %xmm1, %xmm0
jb 0xcf9ff
movq 0x28(%rsp), %rax
movl 0x8(%rax), %ecx
movl -0x4(%rdx,%rbp), %r8d
movq %rbx, %rdi
movq 0x10(%rsp), %rsi
movq 0x70(%rsp), %rdx
movq 0x88(%rsp), %r9
movl 0x210(%rsp), %eax
pushq %rax
pushq %r15
movq 0x228(%rsp), %rax
pushq 0xa0(%rax)
pushq %r14
leaq 0x190(%rsp), %rax
pushq %rax
leaq 0x128(%rsp), %rax
pushq %rax
callq 0x1015d1
movq 0x38(%rsp), %rdx
movq 0x48(%rsp), %r11
addq $0x30, %rsp
testl %eax, %eax
je 0xcfa27
addq $0x18, %rbp
cmpq %rbp, %r13
jne 0xcf908
movq 0x10(%rsp), %r12
movq 0x38(%rsp), %r13
movq 0x20(%rsp), %rbp
jmp 0xcfcd3
movq 0x68(%rsp), %r14
jmp 0xcfa0c
movq %r15, 0x48(%rsp)
movq %r14, %r13
movq 0xc8(%rsp), %rax
testq %rax, %rax
je 0xcfa5e
movq 0x20(%rbx), %rcx
movq 0xd8(%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 0xcfa4a
cmpq $0x0, 0xc8(%rsp)
je 0xcfb78
xorl %eax, %eax
movq 0xd8(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, %edx
shrl %edx
movq 0x20(%rbx), %rsi
cmpb $0x1, 0x4(%rsi,%rdx,8)
jne 0xcfb68
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 0xcfb58
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 0xcfb4c
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 0xcfb4c
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 0xcfb4c
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), %r15d
xorl %esi, %r15d
cmpl $0x1, %r15d
jne 0xcfb43
orb $-0x80, 0x3(%r11,%r14)
addq $0x18, %r14
cmpq %r14, %r10
jne 0xcfb2f
incq %r9
cmpq %rdi, %r9
jne 0xcfac3
leaq 0x1(%rdx), %rsi
testq %rdx, %rdx
movq %rsi, %rdx
je 0xcfa92
incl %eax
cmpq %rax, 0xc8(%rsp)
ja 0xcfa6f
movq 0x218(%rsp), %rax
testq %rax, %rax
movq 0x8(%rsp), %rcx
je 0xcfbce
movq 0x8(%rsp), %rcx
movl (%rcx,%rbp), %edx
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andq %rcx, %rdx
movq 0x28(%rsp), %rsi
movl 0xc(%rsi), %r8d
andq %rcx, %r8
leaq 0x170(%rsp), %rsi
leaq 0x100(%rsp), %rcx
movq 0x10(%rsp), %r9
pushq %rax
pushq 0x78(%rsp)
callq 0xbd407
movq 0x18(%rsp), %rcx
addq $0x10, %rsp
movq 0x220(%rsp), %rax
testq %rax, %rax
movq %r13, %r14
movq 0x48(%rsp), %r15
movq 0x10(%rsp), %r12
leaq 0x100(%rsp), %r10
je 0xcfc3c
movq 0x8(%rsp), %rcx
movl (%rcx,%rbp), %edx
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andq %rcx, %rdx
movq 0x28(%rsp), %rsi
movl 0xc(%rsi), %r8d
andq %rcx, %r8
subq $0x8, %rsp
leaq 0x15b548(%rip), %rdi    # 0x22b15f
leaq 0x178(%rsp), %rsi
movq %r10, %rcx
movq %r12, %r9
pushq %rax
callq 0x1902f0
movq 0x18(%rsp), %rcx
leaq 0x110(%rsp), %r10
addq $0x10, %rsp
movq 0x38(%rsp), %r13
incl %r13d
movq $0x0, 0x138(%rsp)
movl -0x4(%rcx,%rbp), %edx
movq %rbx, %rdi
movq %r12, %rsi
leaq 0x4(%rsp), %rcx
leaq 0x80(%rsp), %r8
leaq 0x40(%rsp), %r9
pushq %r10
movl 0x218(%rsp), %eax
pushq %rax
leaq 0x68(%rsp), %rax
pushq %rax
leaq 0x90(%rsp), %rax
pushq %rax
callq 0x10109f
addq $0x20, %rsp
movq 0x138(%rsp), %rax
testq %rax, %rax
je 0xcfcc9
movq 0x20(%rbx), %rcx
movq 0x148(%rsp), %rdx
xorl %esi, %esi
movq 0x20(%rsp), %rbp
movq 0x18(%rsp), %r11
movl (%rdx,%rsi,4), %edi
shrl %edi
movb $0x2, 0x4(%rcx,%rdi,8)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rax
ja 0xcfcb3
jmp 0xcfcd3
movq 0x20(%rsp), %rbp
movq 0x18(%rsp), %r11
incq %r11
cmpq %rbp, %r11
jne 0xcf5ae
movq %rbx, %rdi
callq 0xa02fa
movq %rbx, %rdi
callq 0xa0333
movq %rbx, %rdi
callq 0xa03e9
orb $-0x80, 0x17(%rbx)
movq 0xd8(%rsp), %rdi
callq 0x2220
movq 0x148(%rsp), %rdi
callq 0x2220
movq 0x1b8(%rsp), %rdi
callq 0x2220
movl %r13d, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq