// File: /workspace/github_cpp_makefile_star2_O3/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 $0x1e8, %rsp            # imm = 0x1E8
movss %xmm0, 0x60(%rsp)
movq %r9, 0x88(%rsp)
movq %r8, 0x80(%rsp)
movq %rcx, 0x78(%rsp)
movq %rdx, 0x68(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
callq 0x2f3fc
movl 0x14(%rbx), %eax
xorl %r15d, %r15d
xorpd %xmm0, %xmm0
movapd %xmm0, 0xa0(%rsp)
movapd %xmm0, 0xb0(%rsp)
movapd %xmm0, 0xc0(%rsp)
movapd %xmm0, 0xd0(%rsp)
movapd %xmm0, 0xe0(%rsp)
movapd %xmm0, 0xf0(%rsp)
movq %r15, 0x100(%rsp)
movapd %xmm0, 0x180(%rsp)
movapd %xmm0, 0x190(%rsp)
movapd %xmm0, 0x1a0(%rsp)
movapd %xmm0, 0x1b0(%rsp)
movapd %xmm0, 0x1c0(%rsp)
movapd %xmm0, 0x1d0(%rsp)
movq %r15, 0x1e0(%rsp)
movapd %xmm0, 0x110(%rsp)
movapd %xmm0, 0x120(%rsp)
movapd %xmm0, 0x130(%rsp)
movapd %xmm0, 0x140(%rsp)
movapd %xmm0, 0x150(%rsp)
movapd %xmm0, 0x160(%rsp)
movq %r15, 0x170(%rsp)
addl %eax, %eax
je 0xcf43d
movl 0x238(%rsp), %ecx
addl $-0x3, %ecx
movl %ecx, 0x5c(%rsp)
movl %eax, %r12d
xorl %r13d, %r13d
leaq 0xa0(%rsp), %rbp
xorl %r15d, %r15d
movq 0x20(%rbx), %rax
movl %r13d, %ecx
shrl %ecx
cmpl $0x0, (%rax,%rcx,8)
js 0xcf431
cmpb $0x1, 0x4(%rax,%rcx,8)
je 0xcf431
movq 0x28(%rbx), %rax
movq (%rax,%r13,8), %rcx
movq %rcx, %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rdx
je 0xcedc3
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 0xceda4
testl %edi, %edi
jne 0xcf431
movl %r13d, %edx
xorl $0x1, %edx
movq (%rax,%rdx,8), %rax
movq %rax, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0xcf431
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 0xcedfe
cmpl $0x1, %edi
jne 0xcf431
movq $0x0, 0xd8(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x14(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x98(%rsp), %r9
pushq %rbp
pushq $0x1
leaq 0xa0(%rsp), %rax
pushq %rax
leaq 0x88(%rsp), %rax
pushq %rax
callq 0x1053a7
addq $0x20, %rsp
cmpl $0x3, %eax
jne 0xcf431
cmpl $-0x2, 0x5c(%rsp)
leaq 0x34(%rsp), %rdx
leaq 0x30(%rsp), %r8
leaq 0x64(%rsp), %r9
movq %r15, 0x8(%rsp)
movq %r12, 0x18(%rsp)
jb 0xcefd7
movq %r13, 0x38(%rsp)
movl 0xd8(%rsp), %r13d
testq %r13, %r13
movq %r14, 0x40(%rsp)
je 0xcef2d
movq 0xe8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x10(%r14), %rax
xorl %r15d, %r15d
xorl %edi, %edi
xorl %r12d, %r12d
xorl %r14d, %r14d
movl %edi, 0x28(%rsp)
movq 0x20(%rsp), %rbp
movl (%rbp,%r15,4), %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rdi
movl 0x238(%rsp), %esi
movq %r8, %rcx
movq %r9, %r8
callq 0xd0648
movl 0x28(%rsp), %edi
leaq 0x64(%rsp), %r9
leaq 0x30(%rsp), %r8
leaq 0x34(%rsp), %rdx
addl 0x34(%rsp), %r14d
addl 0x30(%rsp), %r12d
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movl (%rbp,%r15,4), %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
addl 0x10(%rax,%rcx,8), %edi
incq %r15
cmpq %r15, %r13
jne 0xceec4
jmp 0xcef35
xorl %r14d, %r14d
xorl %r12d, %r12d
xorl %edi, %edi
movq 0x40(%rsp), %rdx
movl %r12d, %eax
addl %r14d, %eax
movq 0x38(%rsp), %r13
je 0xcefc2
movl %r14d, %ecx
cvtsi2sd %rcx, %xmm0
movl %eax, %eax
cvtsi2sd %rax, %xmm1
mulsd 0x1626d2(%rip), %xmm1   # 0x231630
ucomisd %xmm0, %xmm1
jae 0xcefc2
testl %r12d, %r12d
sete %al
cmpl $0x14, %r14d
setae %cl
testb %al, %cl
jne 0xcf16a
cmpl $0x64, %edi
jb 0xcef92
movl %edi, %eax
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x161c80(%rip), %xmm1   # 0x230c10
jmp 0xcefb8
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
mulsd 0x161c6f(%rip), %xmm1   # 0x230c10
cmpl $0x32, %edi
jb 0xcefb0
mulsd 0x162642(%rip), %xmm1   # 0x2315f0
jmp 0xcefb8
mulsd 0x162618(%rip), %xmm1   # 0x2315d0
ucomisd %xmm0, %xmm1
jbe 0xcf16a
movq %rdx, %r14
movq 0x8(%rsp), %r15
movq 0x18(%rsp), %r12
leaq 0xa0(%rsp), %rbp
movl 0x14(%rsp), %eax
movq 0x8(%rbx), %rcx
movq 0x28(%rbx), %rdx
movq (%rdx,%rax,8), %r8
movq %r8, %rdi
movl %eax, %esi
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
andq %r9, %rdi
je 0xcf02d
shrq $0x20, %r8
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdi
leaq (%r8,%r8,2), %rsi
leaq (%rcx,%rsi,8), %r8
addq $0xc, %r8
xorl %r9d, %r9d
movl %eax, %esi
cmpl $0x0, (%r8,%r9)
js 0xcf024
movl -0x4(%r8,%r9), %esi
movl %esi, 0x14(%rsp)
addq $0x18, %r9
cmpq %r9, %rdi
jne 0xcf014
xorl $0x1, %esi
movl %esi, 0x14(%rsp)
movq (%rdx,%rsi,8), %rdi
testl %edi, %edi
je 0xcf431
movl 0x50(%rsp), %esi
movq %rdi, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %r8
leaq (%rcx,%r8,8), %r11
movl %edi, %edx
leaq (%rcx,%r8,8), %r10
addq $0xc, %r10
movq %r10, %r8
xorl %ecx, %ecx
cmpl $0x0, (%r8)
js 0xcf075
movl -0x4(%r8), %r9d
xorl %eax, %r9d
cmpl $0x1, %r9d
je 0xcf084
incq %rcx
addq $0x18, %r8
cmpq %rcx, %rdx
jne 0xcf062
movq %rdi, %rcx
testl %edi, %edi
je 0xcf41f
movq %r11, 0x38(%rsp)
movl %ecx, %ecx
movl %esi, %eax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
movss %xmm0, 0x20(%rsp)
movq %rcx, 0x48(%rsp)
leaq (,%rcx,8), %rax
leaq (%rax,%rax,2), %r15
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %r12
xorl %ebp, %ebp
movq %r10, 0x28(%rsp)
cmpq %rbp, %r15
je 0xcf158
cmpl $0x0, (%r10,%rbp)
js 0xcf158
movl -0x4(%r10,%rbp), %edx
movq %rbx, %rdi
movq %r14, %rsi
leaq 0x14(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x98(%rsp), %r9
pushq $0x0
movl 0x228(%rsp), %eax
pushq %rax
leaq 0xa0(%rsp), %rax
pushq %rax
leaq 0x88(%rsp), %rax
pushq %rax
callq 0x1053a7
movq 0x48(%rsp), %r10
addq $0x20, %rsp
movq 0x50(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2ss %rax, %xmm0
mulss 0x60(%rsp), %xmm0
ucomiss 0x20(%rsp), %xmm0
jbe 0xcf158
xorps %xmm0, %xmm0
cvtsi2sdq 0x70(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %rax, %xmm1
mulsd 0x162436(%rip), %xmm1   # 0x231588
ucomisd %xmm1, %xmm0
jae 0xcf172
addq $0x18, %rbp
cmpq %rbp, %r12
jne 0xcf0c3
jmp 0xcf41f
movq %rdx, %r14
jmp 0xcf41f
movq 0x48(%rsp), %rax
leaq (%rax,%rax,2), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x48(%rsp)
movl 0x8(%rax,%rcx,8), %ecx
movl -0x4(%r10,%rbp), %r8d
movq %rbx, %rdi
movq %r14, %rsi
movq 0x68(%rsp), %rdx
movq 0x78(%rsp), %r9
movl 0x220(%rsp), %eax
pushq %rax
pushq 0x90(%rsp)
movq 0x238(%rsp), %rax
pushq 0xa0(%rax)
pushq 0x98(%rsp)
leaq 0x130(%rsp), %rax
pushq %rax
leaq 0x1a8(%rsp), %rax
pushq %rax
callq 0x105913
addq $0x30, %rsp
movl %eax, 0x20(%rsp)
movq 0xd8(%rsp), %rdx
testq %rdx, %rdx
je 0xcf35e
movq 0x20(%rbx), %rax
movq 0xe8(%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 0xcf200
xorl %eax, %eax
movq %r14, 0x40(%rsp)
movq 0xe8(%rsp), %rcx
movl (%rcx,%rax,4), %ecx
movl %ecx, %esi
shrl %esi
movq 0x20(%rbx), %rdi
cmpb $0x1, 0x4(%rdi,%rsi,8)
jne 0xcf325
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 0xcf305
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 0xcf2f9
leaq (%r8,%r11,8), %r15
movq 0x20(%rbx), %r12
movl 0x8(%r15), %r14d
movl %r14d, %r11d
shrl %r11d
cmpb $0x1, 0x4(%r12,%r11,8)
je 0xcf2f9
orl $0x80000000, %r10d      # imm = 0x80000000
movl %r10d, 0xc(%r15)
xorq $0x1, %r14
movq 0x28(%rbx), %r10
movq (%r10,%r14,8), %r11
movq %r11, %r10
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
andq %r14, %r10
je 0xcf2f9
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 %r15d, %r15d
movl -0x4(%r11,%r15), %r14d
xorl %esi, %r14d
cmpl $0x1, %r14d
jne 0xcf2f0
orb $-0x80, 0x3(%r11,%r15)
addq $0x18, %r15
cmpq %r15, %r10
jne 0xcf2dc
incq %r9
cmpq %rdi, %r9
jne 0xcf270
movl $0x1, %esi
testb $0x1, %dl
movl $0x0, %edx
jne 0xcf240
movq 0xd8(%rsp), %rdx
movq 0x40(%rsp), %r14
incl %eax
cmpq %rax, %rdx
ja 0xcf21b
testq %rdx, %rdx
je 0xcf35e
cmpl $0x1, 0x20(%rsp)
jne 0xcf35e
movq 0x20(%rbx), %rax
movq 0xe8(%rsp), %rcx
xorl %esi, %esi
movl (%rcx,%rsi,4), %edi
shrl %edi
movb $0xb, 0x4(%rax,%rdi,8)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rdx
ja 0xcf34a
movq 0x38(%rsp), %rax
movq 0x48(%rsp), %rcx
leaq (%rax,%rcx,8), %r15
cmpq $0x0, 0x228(%rsp)
je 0xcf3bc
cmpl $0x1, 0x20(%rsp)
je 0xcf3bc
movq 0x28(%rsp), %rax
movl (%rax,%rbp), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rdx
movl 0xc(%r15), %r8d
andq %rax, %r8
leaq 0x110(%rsp), %rsi
leaq 0x180(%rsp), %rcx
movq %r14, %r9
pushq 0x228(%rsp)
pushq 0x70(%rsp)
callq 0xbe511
addq $0x10, %rsp
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
cmpq $0x0, 0x230(%rsp)
movq 0x28(%rsp), %rax
je 0xcf41f
cmpl $0x1, 0x20(%rsp)
je 0xcf41f
movl (%rax,%rbp), %edx
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %rdx
movl 0xc(%r15), %r8d
andq %rax, %r8
subq $0x8, %rsp
leaq 0x167eff(%rip), %rdi    # 0x2372fb
leaq 0x118(%rsp), %rsi
leaq 0x188(%rsp), %rcx
movq %r14, %r9
pushq 0x238(%rsp)
callq 0x1990ae
addq $0x10, %rsp
movq 0x8(%rsp), %r15
movq 0x18(%rsp), %r12
leaq 0xa0(%rsp), %rbp
incq %r13
cmpq %r12, %r13
jne 0xced51
movq %rbx, %rdi
callq 0xa0a7d
movq %rbx, %rdi
callq 0xa0ab6
movq %rbx, %rdi
callq 0xa0b79
orb $-0x80, 0x17(%rbx)
movq 0xe8(%rsp), %rdi
callq 0x2220
movq 0x1c8(%rsp), %rdi
callq 0x2220
movq 0x158(%rsp), %rdi
callq 0x2220
movl %r15d, %eax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq