// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: asg_arc_cut_trio_long_tip_primary_complex(asg_t*, ma_ug_t*, asg_t*, ma_hit_t_alloc*, R_to_U*, unsigned int, float, unsigned int, hap_cov_t*, utg_trans_t*, unsigned int)
int asg_arc_cut_trio_long_tip_primary_complex(asg_t *g, ma_ug_t *ug, asg_t *read_sg, ma_hit_t_alloc* reverse_sources,
R_to_U* ruIndex, uint32_t min_edge_length, float drop_ratio, 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, operation;
    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, &ll, &tmp, &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, "ERROR\n");


        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, &ll, &tmp, &max_stop_nodeLen, 
            &max_stop_baseLen, stops_threshold, NULL);
            
            if(convexLen < ll*drop_ratio && max_stop_nodeLen >= ll*MAX_STOP_RATE)
            {
                n_reduced++;
                operation = TRIM;
                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, min_edge_length, stops_threshold);
                // #define UNAVAILABLE (uint32_t)-1
                // #define PLOID 0
                // #define NON_PLOID 1
                if(flag == NON_PLOID) operation = CUT;

                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(operation == CUT)
                {
                    for (k = 0; k < b.b.n; k++)
                    {
                        g->seq[b.b.a[k]>>1].c = CUT;
                    }
                }

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

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


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

    asg_cleanup(g);
    asg_symm(g);
    free(b.b.a);
    free(b_0.b.a);
    free(b_1.b.a);

    return n_reduced;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movss %xmm0, 0x58(%rsp)
movl %r9d, %r15d
movq %r8, 0x78(%rsp)
movq %rcx, 0x70(%rsp)
movq %rdx, 0x60(%rsp)
movq %rsi, 0x20(%rsp)
movq %rdi, %rbx
callq 0x300fc
movl 0x14(%rbx), %eax
xorl %r14d, %r14d
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 %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)
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)
addl %eax, %eax
je 0xce175
movl 0x228(%rsp), %ecx
addl $-0x3, %ecx
movl %ecx, 0x54(%rsp)
movl %eax, %r12d
xorl %r13d, %r13d
leaq 0x90(%rsp), %rbp
xorl %r14d, %r14d
movq 0x20(%rbx), %rax
movl %r13d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xcdea3
cmpb $0x1, 0x4(%rax,%rcx,8)
je 0xcdea3
movq 0x28(%rbx), %rax
movq (%rax,%r13,8), %rcx
movq %rcx, %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rdx
je 0xcdb08
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 0xcdae9
testl %edi, %edi
jne 0xcdea3
movl %r13d, %edx
xorl $0x1, %edx
movq (%rax,%rdx,8), %rax
movq %rax, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0xcdea3
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 0xcdb43
cmpl $0x1, %edi
jne 0xcdea3
movq $0x0, 0xc8(%rsp)
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
leaq 0x4(%rsp), %rcx
leaq 0x48(%rsp), %r8
leaq 0x88(%rsp), %r9
pushq %rbp
pushq $0x1
leaq 0x90(%rsp), %rax
pushq %rax
leaq 0x80(%rsp), %rax
pushq %rax
callq 0x10109f
addq $0x20, %rsp
cmpl $0x3, %eax
jne 0xcdea3
cmpl $-0x2, 0x54(%rsp)
leaq 0x34(%rsp), %rdx
leaq 0x30(%rsp), %rcx
leaq 0x5c(%rsp), %r8
movq %r14, 0x8(%rsp)
movq %r12, 0x10(%rsp)
movq %r13, 0x18(%rsp)
jb 0xcdcfa
movq %r15, 0x40(%rsp)
movl 0xc8(%rsp), %ebp
testq %rbp, %rbp
je 0xcdc65
movq 0xd8(%rsp), %rax
movq %rax, 0x38(%rsp)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x28(%rsp)
xorl %r15d, %r15d
xorl %edi, %edi
xorl %r14d, %r14d
xorl %r13d, %r13d
movl %edi, (%rsp)
movq 0x38(%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 (%rsp), %edi
leaq 0x5c(%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 0xcdc10
jmp 0xcdc6d
xorl %r13d, %r13d
xorl %r14d, %r14d
xorl %edi, %edi
movl %r14d, %eax
addl %r13d, %eax
movq 0x40(%rsp), %r15
je 0xcdcf5
movl %r13d, %ecx
cvtsi2sd %rcx, %xmm0
movl %eax, %eax
cvtsi2sd %rax, %xmm1
mulsd 0x15789f(%rip), %xmm1   # 0x225530
ucomisd %xmm0, %xmm1
jae 0xcdcf5
testl %r14d, %r14d
sete %al
cmpl $0x14, %r13d
setae %cl
testb %al, %cl
jne 0xcde80
cmpl $0x64, %edi
jb 0xcdcc5
movl %edi, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x156f0d(%rip), %xmm1   # 0x224bd0
jmp 0xcdceb
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
mulsd 0x156efc(%rip), %xmm1   # 0x224bd0
cmpl $0x32, %edi
jb 0xcdce3
mulsd 0x15780f(%rip), %xmm1   # 0x2254f0
jmp 0xcdceb
mulsd 0x1577e5(%rip), %xmm1   # 0x2254d0
ucomisd %xmm0, %xmm1
jbe 0xcde80
movq 0x18(%rsp), %r13
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 0xcdd4a
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 0xcdd41
movl -0x4(%rsi,%rdi), %r8d
movl %r8d, 0x4(%rsp)
addq $0x18, %rdi
cmpq %rdi, %rdx
jne 0xcdd31
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 0xcdda0
movl %ecx, %r8d
leaq (%rdx,%rsi,8), %r9
addq $0xc, %r9
xorl %edi, %edi
cmpl $0x0, (%r9)
js 0xcdd8d
movl -0x4(%r9), %r10d
xorl %eax, %r10d
cmpl $0x1, %r10d
je 0xcdd9c
incq %rdi
addq $0x18, %r9
cmpq %rdi, %r8
jne 0xcdd7a
movq %rcx, %rdi
movl %edi, %edi
jmp 0xcdda2
xorl %edi, %edi
testl %ecx, %ecx
je 0xcde91
movl 0x48(%rsp), %eax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
movss %xmm0, (%rsp)
leaq (%rdx,%rsi,8), %rax
movq %rax, 0x38(%rsp)
movl %ecx, %eax
leaq 0xc(%rdx,%rsi,8), %r12
movq %rdi, 0x28(%rsp)
leaq (,%rdi,8), %rcx
leaq (%rcx,%rcx,2), %r14
shlq $0x3, %rax
leaq (%rax,%rax,2), %r13
xorl %ebp, %ebp
cmpq %rbp, %r14
je 0xcde73
cmpl $0x0, (%r12,%rbp)
js 0xcde73
movl -0x4(%r12,%rbp), %edx
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
leaq 0x4(%rsp), %rcx
leaq 0x48(%rsp), %r8
leaq 0x88(%rsp), %r9
pushq $0x0
movl 0x218(%rsp), %eax
pushq %rax
leaq 0x90(%rsp), %rax
pushq %rax
leaq 0x80(%rsp), %rax
pushq %rax
callq 0x10109f
addq $0x20, %rsp
movq 0x48(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
mulss 0x58(%rsp), %xmm0
ucomiss (%rsp), %xmm0
jbe 0xcde73
xorps %xmm0, %xmm0
cvtsi2sdq 0x68(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x15761b(%rip), %xmm1   # 0x225488
ucomisd %xmm1, %xmm0
jae 0xcdeb4
addq $0x18, %rbp
cmpq %rbp, %r13
jne 0xcdde6
movq 0x8(%rsp), %r14
movq 0x10(%rsp), %r12
movq 0x18(%rsp), %r13
jmp 0xcde9b
movq 0x8(%rsp), %r14
movq 0x10(%rsp), %r12
leaq 0x90(%rsp), %rbp
incq %r13
cmpq %r12, %r13
jne 0xcda96
jmp 0xce175
movq 0x28(%rsp), %rax
leaq (%rax,%rax,2), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x28(%rsp)
movl 0x8(%rax,%rcx,8), %ecx
movl 0x8(%rbp,%rax), %r8d
movq %rbx, %rdi
movq 0x20(%rsp), %rsi
movq 0x60(%rsp), %rdx
movq 0x70(%rsp), %r9
movl 0x210(%rsp), %eax
pushq %rax
movq %r15, 0x48(%rsp)
pushq %r15
movq 0x228(%rsp), %rax
pushq 0xa0(%rax)
pushq 0x90(%rsp)
leaq 0x120(%rsp), %rax
pushq %rax
leaq 0x198(%rsp), %rax
pushq %rax
callq 0x1015d1
addq $0x30, %rsp
movl %eax, (%rsp)
movq 0xc8(%rsp), %rax
testq %rax, %rax
je 0xcdf53
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 0xcdf3f
movq 0xc8(%rsp), %rcx
testq %rcx, %rcx
je 0xce072
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 0xce05f
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 0xce04f
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 0xce043
leaq (%r8,%r11,8), %r14
movq 0x20(%rbx), %r15
movl 0x8(%r14), %r11d
movl %r11d, %r13d
shrl %r13d
cmpb $0x1, 0x4(%r15,%r13,8)
je 0xce043
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 0xce043
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 0xce03a
orb $-0x80, 0x3(%r11,%r14)
addq $0x18, %r14
cmpq %r14, %r10
jne 0xce026
incq %r9
cmpq %rdi, %r9
jne 0xcdfba
leaq 0x1(%rdx), %rsi
testq %rdx, %rdx
movq %rsi, %rdx
je 0xcdf89
incl %eax
movq 0xc8(%rsp), %rcx
cmpq %rax, %rcx
ja 0xcdf66
testq %rcx, %rcx
movl (%rsp), %r8d
je 0xce0a3
cmpl $0x1, %r8d
jne 0xce0a3
movq 0x20(%rbx), %rax
movq 0xd8(%rsp), %rdx
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
shrl %edi
movb $0xb, 0x4(%rax,%rdi,8)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rcx
ja 0xce08f
movq 0x38(%rsp), %rax
movq 0x28(%rsp), %rcx
leaq (%rax,%rcx,8), %r14
cmpq $0x0, 0x218(%rsp)
movq 0x40(%rsp), %r15
je 0xce108
cmpl $0x1, %r8d
je 0xce108
movl (%r12,%rbp), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rdx
movl 0xc(%r14), %r8d
andq %rax, %r8
leaq 0x100(%rsp), %rsi
leaq 0x170(%rsp), %rcx
movq 0x20(%rsp), %r9
pushq 0x218(%rsp)
pushq 0x68(%rsp)
callq 0xbd407
movl 0x10(%rsp), %r8d
addq $0x10, %rsp
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x220(%rsp)
je 0xcde80
cmpl $0x1, %r8d
je 0xcde80
movl (%r12,%rbp), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rdx
movl 0xc(%r14), %r8d
andq %rax, %r8
subq $0x8, %rsp
leaq 0x15cfc0(%rip), %rdi    # 0x22b10b
leaq 0x108(%rsp), %rsi
leaq 0x178(%rsp), %rcx
movq 0x28(%rsp), %r9
pushq 0x228(%rsp)
callq 0x1902f0
addq $0x10, %rsp
jmp 0xcde80
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 0x1b8(%rsp), %rdi
callq 0x2220
movq 0x148(%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