// File: /workspace/github_cpp_makefile_star2_O3/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, %r15
movq %r8, 0x88(%rsp)
movq %rcx, 0x80(%rsp)
movq %rdx, 0x68(%rsp)
movq %rsi, %rbp
movq %rdi, %rbx
callq 0x2f3fc
movl 0x14(%rbx), %eax
xorl %r14d, %r14d
xorpd %xmm0, %xmm0
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 %r14, 0x160(%rsp)
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 %r14, 0xf0(%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 %r14, 0x1d0(%rsp)
addl %eax, %eax
je 0xd0f06
movl 0x228(%rsp), %esi
leal -0x3(%rsi), %ecx
movl %ecx, 0x60(%rsp)
movl %eax, %r10d
xorl %r13d, %r13d
xorl %r14d, %r14d
movq %r10, 0x18(%rsp)
movq 0x20(%rbx), %rax
movl %r13d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xd0c44
cmpb $0x1, 0x4(%rax,%rcx,8)
je 0xd0c44
movq 0x28(%rbx), %rax
movq (%rax,%r13,8), %rcx
movq %rcx, %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rdx
je 0xd082e
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 0xd080f
testl %edi, %edi
jne 0xd0c44
movl %r13d, %edx
xorl $0x1, %edx
movq (%rax,%rdx,8), %rax
movq %rax, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0xd0c44
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 0xd0869
cmpl $0x1, %edi
jne 0xd0c44
movq $0x0, 0x138(%rsp)
movq %rbx, %rdi
movq %rbp, %rsi
leaq 0xc(%rsp), %rcx
leaq 0x78(%rsp), %r8
leaq 0x40(%rsp), %r9
leaq 0x100(%rsp), %rax
pushq %rax
pushq $0x1
leaq 0x68(%rsp), %rax
pushq %rax
leaq 0x88(%rsp), %rax
pushq %rax
callq 0x1053a7
addq $0x20, %rsp
cmpl $0x3, %eax
jne 0xd0c3f
cmpl $-0x2, 0x60(%rsp)
movl 0x228(%rsp), %esi
leaq 0x3c(%rsp), %rdx
leaq 0x38(%rsp), %rcx
leaq 0x64(%rsp), %r8
movq %rbp, 0x28(%rsp)
movq %r14, 0x10(%rsp)
jb 0xd0a3e
movq %r13, 0x30(%rsp)
movq %r15, 0x48(%rsp)
movl 0x138(%rsp), %edi
testq %rdi, %rdi
je 0xd099c
movq 0x148(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x10(%rbp), %rax
xorl %r15d, %r15d
xorl %ebp, %ebp
xorl %r12d, %r12d
xorl %r14d, %r14d
movq %rdi, 0x20(%rsp)
movq 0x50(%rsp), %r13
movl (%r13,%r15,4), %edi
shrl %edi
leaq (%rdi,%rdi,4), %rdi
leaq (%rax,%rdi,8), %rdi
callq 0xd0648
leaq 0x64(%rsp), %r8
leaq 0x38(%rsp), %rcx
leaq 0x3c(%rsp), %rdx
movl 0x228(%rsp), %esi
addl 0x3c(%rsp), %r14d
addl 0x38(%rsp), %r12d
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
movl (%r13,%r15,4), %edi
shrl %edi
leaq (%rdi,%rdi,4), %rdi
addl 0x10(%rax,%rdi,8), %ebp
movq 0x20(%rsp), %rdi
incq %r15
cmpq %r15, %rdi
jne 0xd093c
jmp 0xd09a4
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %ebp, %ebp
movq 0x28(%rsp), %rdx
movl %r12d, %eax
addl %r14d, %eax
movq 0x48(%rsp), %r15
movq 0x30(%rsp), %r13
je 0xd0a36
movl %r14d, %ecx
cvtsi2sd %rcx, %xmm0
movl %eax, %eax
cvtsi2sd %rax, %xmm1
mulsd 0x160c5e(%rip), %xmm1   # 0x231630
ucomisd %xmm0, %xmm1
jae 0xd0a36
testl %r12d, %r12d
sete %al
cmpl $0x14, %r14d
setae %cl
testb %al, %cl
jne 0xd0c37
cmpl $0x64, %ebp
jb 0xd0a06
movl %ebp, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x16020c(%rip), %xmm1   # 0x230c10
jmp 0xd0a2c
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
mulsd 0x1601fb(%rip), %xmm1   # 0x230c10
cmpl $0x32, %ebp
jb 0xd0a24
mulsd 0x160bce(%rip), %xmm1   # 0x2315f0
jmp 0xd0a2c
mulsd 0x160ba4(%rip), %xmm1   # 0x2315d0
ucomisd %xmm0, %xmm1
jbe 0xd0c37
movq %rdx, %rbp
movq 0x10(%rsp), %r14
movl 0xc(%rsp), %eax
movq 0x8(%rbx), %rcx
movq 0x28(%rbx), %rdx
movq (%rdx,%rax,8), %r9
movq %r9, %rdi
movl %eax, %r10d
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rdi
je 0xd0a96
shrq $0x20, %r9
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdi
leaq (%r9,%r9,2), %rsi
leaq (%rcx,%rsi,8), %rsi
addq $0xc, %rsi
xorl %r9d, %r9d
movl %eax, %r10d
cmpl $0x0, (%rsi,%r9)
js 0xd0a8d
movl -0x4(%rsi,%r9), %r10d
movl %r10d, 0xc(%rsp)
addq $0x18, %r9
cmpq %r9, %rdi
jne 0xd0a7c
xorl $0x1, %r10d
movl %r10d, 0xc(%rsp)
movq (%rdx,%r10,8), %r9
testl %r9d, %r9d
je 0xd0c3f
movl 0x40(%rsp), %edx
movq %rdx, 0x50(%rsp)
movq %r9, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdi
leaq (%rcx,%rdi,8), %rdx
movq %rdx, 0x30(%rsp)
movl %r9d, %edx
leaq (%rcx,%rdi,8), %r8
addq $0xc, %r8
movq %r8, %rdi
xorl %ecx, %ecx
movq 0x18(%rsp), %r10
cmpl $0x0, (%rdi)
js 0xd0aed
movl -0x4(%rdi), %esi
xorl %eax, %esi
cmpl $0x1, %esi
je 0xd0afc
incq %rcx
addq $0x18, %rdi
cmpq %rcx, %rdx
jne 0xd0ade
movq %r9, %rcx
testl %r9d, %r9d
je 0xd0c2b
movl %ecx, %eax
shlq $0x3, %rax
leaq (%rax,%rax,2), %r14
addq %r14, 0x30(%rsp)
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %r12
xorl %ebp, %ebp
movq %r8, 0x20(%rsp)
cmpq %rbp, %r14
je 0xd0c1e
cmpl $0x0, (%r8,%rbp)
js 0xd0c1e
movl -0x4(%r8,%rbp), %edx
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
leaq 0xc(%rsp), %rcx
leaq 0x78(%rsp), %r8
leaq 0x40(%rsp), %r9
pushq $0x0
movl 0x218(%rsp), %eax
pushq %rax
leaq 0x68(%rsp), %rax
pushq %rax
leaq 0x88(%rsp), %rax
pushq %rax
callq 0x1053a7
movq 0x40(%rsp), %r8
movq 0x38(%rsp), %r10
addq $0x20, %rsp
movq 0x40(%rsp), %rax
cmpq 0x50(%rsp), %rax
jle 0xd0c1e
xorps %xmm0, %xmm0
cvtsi2sdq 0x58(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x1609df(%rip), %xmm1   # 0x231588
ucomisd %xmm1, %xmm0
jb 0xd0c1e
movq 0x30(%rsp), %rax
movl 0x8(%rax), %ecx
movq 0x20(%rsp), %rax
movl -0x4(%rax,%rbp), %r8d
movq %rbx, %rdi
movq 0x28(%rsp), %rsi
movq 0x68(%rsp), %rdx
movq 0x80(%rsp), %r9
movl 0x210(%rsp), %eax
pushq %rax
pushq 0x90(%rsp)
movq 0x228(%rsp), %rax
pushq 0xa0(%rax)
pushq %r15
leaq 0x190(%rsp), %rax
pushq %rax
leaq 0xb8(%rsp), %rax
pushq %rax
callq 0x105913
movq 0x50(%rsp), %r8
movq 0x48(%rsp), %r10
addq $0x30, %rsp
testl %eax, %eax
je 0xd0c55
addq $0x18, %rbp
cmpq %rbp, %r12
jne 0xd0b23
movq 0x28(%rsp), %rbp
movq 0x10(%rsp), %r14
jmp 0xd0c44
movq %rdx, %rbp
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %r10
incq %r13
cmpq %r10, %r13
jne 0xd07bc
jmp 0xd0f06
movq 0x138(%rsp), %rdx
testq %rdx, %rdx
movq 0x220(%rsp), %r14
leaq 0x90(%rsp), %r10
je 0xd0dd4
movq 0x20(%rbx), %rax
movq 0x148(%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 0xd0c84
xorl %eax, %eax
movq %r15, 0x48(%rsp)
movq 0x148(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, %esi
shrl %esi
movq 0x20(%rbx), %rdi
cmpb $0x1, 0x4(%rdi,%rsi,8)
jne 0xd0dbe
andl $-0x2, %ecx
movb $0x1, %dl
xorl %esi, %esi
orq %rcx, %rsi
movq 0x28(%rbx), %rdi
movq (%rdi,%rsi,8), %r8
movq %r8, %rdi
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
andq %r9, %rdi
je 0xd0d89
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 0xd0d7d
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 0xd0d7d
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 0xd0d7d
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 0xd0d74
orb $-0x80, 0x3(%r11,%r14)
addq $0x18, %r14
cmpq %r14, %r10
jne 0xd0d60
incq %r9
cmpq %rdi, %r9
jne 0xd0cf4
movl $0x1, %esi
testb $0x1, %dl
movl $0x0, %edx
jne 0xd0cc4
movq 0x138(%rsp), %rdx
movq 0x48(%rsp), %r15
movq 0x220(%rsp), %r14
leaq 0x90(%rsp), %r10
movq 0x20(%rsp), %r8
incl %eax
cmpq %rax, %rdx
ja 0xd0c9f
cmpq $0x0, 0x218(%rsp)
je 0xd0e1d
movl (%r8,%rbp), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rdx
movq 0x30(%rsp), %rcx
movl 0xc(%rcx), %r8d
andq %rax, %r8
leaq 0x170(%rsp), %rsi
movq %r10, %rcx
movq 0x28(%rsp), %r9
pushq 0x218(%rsp)
pushq 0x70(%rsp)
callq 0xbe511
movq 0x30(%rsp), %r8
leaq 0xa0(%rsp), %r10
addq $0x10, %rsp
testq %r14, %r14
movq %r14, %rax
movq 0x28(%rsp), %r14
je 0xd0e72
movl (%r8,%rbp), %edx
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andq %rcx, %rdx
movq 0x30(%rsp), %rsi
movl 0xc(%rsi), %r8d
andq %rcx, %r8
subq $0x8, %rsp
leaq 0x166502(%rip), %rdi    # 0x23734f
leaq 0x178(%rsp), %rsi
movq %r10, %rcx
movq %r14, %r9
pushq %rax
callq 0x1990ae
movq 0x30(%rsp), %r8
leaq 0xa0(%rsp), %r10
addq $0x10, %rsp
movq 0x10(%rsp), %rax
incl %eax
movq %rax, 0x10(%rsp)
movq $0x0, 0xc8(%rsp)
movl -0x4(%r8,%rbp), %edx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0xc(%rsp), %rcx
leaq 0x78(%rsp), %r8
leaq 0x40(%rsp), %r9
pushq %r10
movl 0x218(%rsp), %eax
pushq %rax
leaq 0x68(%rsp), %rax
pushq %rax
leaq 0x88(%rsp), %rax
pushq %rax
callq 0x1053a7
addq $0x20, %rsp
movq 0xc8(%rsp), %rax
testq %rax, %rax
movq %r14, %rbp
je 0xd0c3a
movq 0x20(%rbx), %rcx
movq 0xd8(%rsp), %rdx
xorl %esi, %esi
movq 0x18(%rsp), %r10
movl (%rdx,%rsi,4), %edi
shrl %edi
movb $0x2, 0x4(%rcx,%rdi,8)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rax
ja 0xd0eed
jmp 0xd0c30
movq %rbx, %rdi
callq 0xa0a7d
movq %rbx, %rdi
callq 0xa0ab6
movq %rbx, %rdi
callq 0xa0b79
orb $-0x80, 0x17(%rbx)
movq 0x148(%rsp), %rdi
callq 0x2220
movq 0xd8(%rsp), %rdi
callq 0x2220
movq 0x1b8(%rsp), %rdi
callq 0x2220
movl %r14d, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq