// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: get_num_edges2existing_nodes_advance(ma_ug_t*, asg_t*, ma_hit_t_alloc*, ma_sub_t*, R_to_U*, int, int, unsigned int, unsigned int*, unsigned int*, unsigned int, unsigned int)
inline uint32_t get_num_edges2existing_nodes_advance(ma_ug_t *ug, asg_t *g, ma_hit_t_alloc* sources, ma_sub_t *coverage_cut, 
R_to_U* ruIndex, int max_hang, int min_ovlp, uint32_t query, uint32_t* oLen, uint32_t* skip_uId, uint32_t skip_uId_n, uint32_t ignore_trio_flag)
{
    (*oLen) = 0;
    uint32_t qn = query>>1;
    int32_t r;
    asg_arc_t t;
    ma_hit_t *h = NULL;
    ma_sub_t *sq = NULL;
    ma_sub_t *st = NULL;
    ma_hit_t_alloc* x = &(sources[qn]);
    uint32_t i, k, occ = 0, uId, is_Unitig, v, w;

    uint32_t trio_flag = R_INF.trio_flag[qn], non_trio_flag = (uint32_t)-1;
    if(ignore_trio_flag == 0)
    {
        if(trio_flag == FATHER) non_trio_flag = MOTHER;
        if(trio_flag == MOTHER) non_trio_flag = FATHER;
    }



    for (i = 0; i < x->length; i++)
    {
        h = &(x->buffer[i]);
        sq = &(coverage_cut[Get_qn(*h)]);
        st = &(coverage_cut[Get_tn(*h)]);
        ///sq has already been removed
        ///st must not be removed
        ///g-seq must not be removed
        if(st->del || g->seq[Get_tn(*h)].del) continue;
        if(R_INF.trio_flag[Get_tn(*h)] == non_trio_flag) continue;

        r = ma_hit2arc(h, sq->e - sq->s, st->e - st->s, max_hang, 
                                asm_opt.max_hang_rate, min_ovlp, &t);
        
        ///if it is a contained read, skip
        if(r < 0) continue;

        if((t.ul>>32) != query) continue;
        get_R_to_U(ruIndex, t.v>>1, &uId, &is_Unitig);
        /****************************may have bugs********************************/
        if(uId == (uint32_t)-1 || is_Unitig == 0) continue;
        /****************************may have bugs********************************/
        for (k = 0; k < skip_uId_n; k++)
        {
            if(uId == skip_uId[k]) break;
        }
        if(k != skip_uId_n) continue;
        // if(uId == skip_uId1) continue;
        // if(uId == skip_uId2) continue;
        /****************************may have bugs********************************/
        if(ug->g->seq[uId].del) continue;
        /****************************may have bugs********************************/
        
        if((t.v != ug->u.a[uId].start) 
            && 
           (t.v != ug->u.a[uId].end))
        {
            continue;
        }
        /**********for debug*************/
        if(t.v == ug->u.a[uId].start)
        {
            ///v = uId<<1;
            v = (uId<<1)^1;
        }

        if(t.v == ug->u.a[uId].end)
        {
            ///v = (uId<<1)^1;
            v = uId<<1;
        }

        if(get_real_length(ug->g, v, NULL)==1)
        {
            get_real_length(ug->g, v, &w);
            if(get_real_length(ug->g, w^1, NULL)==1)
            {
                continue;
            }
        }
        /**********for debug*************/

        occ++;
        (*oLen) += t.ol;
    }

    return occ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r9d, 0x18(%rsp)
movq %r8, 0x30(%rsp)
movq %rcx, %r15
movq %rsi, %r12
movq 0xb0(%rsp), %rcx
movl 0xa8(%rsp), %eax
movl $0x0, (%rcx)
movl %eax, %esi
shrl %esi
leaq (%rsi,%rsi,2), %rcx
leaq 0x188a77(%rip), %r8     # 0x28b230
movq 0x28(%r8), %r8
movq %r8, 0x48(%rsp)
movb (%r8,%rsi), %sil
xorl %r8d, %r8d
cmpb $0x1, %sil
sete %r8b
leal (%r8,%r8,2), %r8d
decl %r8d
cmpb $0x2, %sil
movl $0x1, %esi
cmovnel %r8d, %esi
movl %esi, 0x1c(%rsp)
cmpl $0x0, 0xc(%rdx,%rcx,8)
je 0x102ac7
movq %rdi, 0x28(%rsp)
movl 0xc8(%rsp), %r9d
movl 0xc0(%rsp), %esi
leaq (%rdx,%rcx,8), %r14
movq (%r14), %rbx
leaq 0x187f42(%rip), %rcx    # 0x28a758
movss 0x158(%rcx), %xmm0
movss %xmm0, 0x14(%rsp)
movl %eax, %eax
movq %rax, 0x38(%rsp)
movl %esi, %eax
movq %rax, 0x40(%rsp)
xorl %ebp, %ebp
movq %rax, 0x20(%rsp)
movl $0x0, 0xc(%rsp)
leaq (,%rbp,4), %rdx
addq %rbp, %rdx
movl 0xc(%rbx,%rdx,8), %esi
leaq (%rsi,%rsi,2), %rcx
movl (%r15,%rcx,4), %eax
testl %eax, %eax
js 0x102917
movq 0x20(%r12), %rdi
cmpl $0x0, (%rdi,%rsi,8)
js 0x102917
movl 0x4(%rbx,%rdx,8), %r8d
testl %r9d, %r9d
jne 0x10288c
movq 0x48(%rsp), %rdi
movzbl (%rdi,%rsi), %esi
cmpl %esi, 0x1c(%rsp)
je 0x102917
movl %r9d, %r13d
leaq (%rbx,%rdx,8), %rdi
leaq (%r8,%r8,2), %rdx
leaq (%r15,%rdx,4), %rdx
leaq (%r15,%rcx,4), %rcx
movl 0x4(%rdx), %esi
movl (%rdx), %edx
movl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
andl %r8d, %edx
subl %edx, %esi
movl 0x4(%rcx), %edx
subl %eax, %edx
movl 0x18(%rsp), %ecx
movss 0x14(%rsp), %xmm0
movl 0xa0(%rsp), %r8d
leaq 0x50(%rsp), %r9
callq 0xa159b
testl %eax, %eax
js 0x102914
movq 0x38(%rsp), %rax
cmpl %eax, 0x54(%rsp)
jne 0x102914
movl 0x58(%rsp), %ecx
movl %ecx, %eax
shrl %eax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq 0x30(%rsp), %rsi
cmpq %rax, (%rsi)
movl %r13d, %r9d
jbe 0x10292c
movq 0x8(%rsi), %rsi
movl (%rsi,%rax,4), %eax
cmpl $-0x1, %eax
je 0x10292c
movl %eax, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
testl %eax, %eax
setns %al
jmp 0x10292e
movl %r13d, %r9d
incq %rbp
movl 0xc(%r14), %eax
cmpq %rax, %rbp
jb 0x102841
jmp 0x102acf
xorl %eax, %eax
cmpl $-0x1, %edx
sete %sil
orb %al, %sil
jne 0x102917
movl 0xc0(%rsp), %eax
testl %eax, %eax
movq 0xb8(%rsp), %rsi
je 0x102966
xorl %eax, %eax
cmpl (%rsi,%rax,4), %edx
je 0x102968
incq %rax
cmpl %eax, 0x40(%rsp)
jne 0x10294f
movl 0xc0(%rsp), %eax
jmp 0x102968
xorl %eax, %eax
movl 0xc0(%rsp), %esi
cmpl %esi, %eax
jne 0x102917
movq 0x28(%rsp), %r8
movq 0x18(%r8), %rax
movq 0x20(%rax), %rsi
movl %edx, %edi
cmpl $0x0, (%rsi,%rdi,8)
js 0x102917
movq 0x10(%r8), %rsi
leaq (%rdi,%rdi,4), %rdi
cmpl 0x4(%rsi,%rdi,8), %ecx
je 0x1029a4
leaq (%rsi,%rdi,8), %r8
cmpl 0x8(%r8), %ecx
jne 0x102917
cmpl 0x4(%rsi,%rdi,8), %ecx
leal (%rdx,%rdx), %r8d
leal 0x1(%rdx,%rdx), %edx
movq 0x20(%rsp), %r10
cmovel %edx, %r10d
cmpl 0x8(%rsi,%rdi,8), %ecx
cmovel %r8d, %r10d
movq 0x28(%rax), %rcx
movq %r10, 0x20(%rsp)
movq (%rcx,%r10,8), %rdx
movq %rdx, %rsi
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %rdi, %rsi
je 0x102aa9
movq 0x8(%rax), %r8
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdi
leaq (%r8,%rdi,8), %r8
addq $0xc, %r8
leaq (,%rsi,8), %rdx
leaq (%rdx,%rdx,2), %rdx
xorl %r9d, %r9d
xorl %r10d, %r10d
movl (%r8,%r9), %r11d
notl %r11d
shrl $0x1f, %r11d
addl %r11d, %r10d
addq $0x18, %r9
cmpq %r9, %rdx
jne 0x102a05
cmpl $0x1, %r10d
movl %r13d, %r9d
jne 0x102aa9
testq %rsi, %rsi
je 0x102a55
movq 0x8(%rax), %rsi
leaq (%rsi,%rdi,8), %rsi
addq $0xc, %rsi
xorl %edi, %edi
cmpl $0x0, (%rsi,%rdi)
js 0x102a4c
movl -0x4(%rsi,%rdi), %r8d
movl %r8d, 0x10(%rsp)
addq $0x18, %rdi
cmpq %rdi, %rdx
jne 0x102a3c
movl 0x10(%rsp), %edx
xorl $0x1, %edx
movq (%rcx,%rdx,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0x102aa9
movq 0x8(%rax), %rax
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rax
addq $0xc, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
xorl %esi, %esi
movl (%rax,%rdx), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %esi
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0x102a8d
cmpl $0x1, %esi
je 0x102917
incl 0xc(%rsp)
movl 0x5c(%rsp), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
movq 0xb0(%rsp), %rcx
addl %eax, (%rcx)
jmp 0x102917
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq