// File: /workspace/github_cpp_makefile_star2_O3/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
movl %r9d, %r12d
movq %rsi, %rbx
movq 0x48(%rsp), %rsi
movl 0x40(%rsp), %eax
movl $0x0, (%rsi)
movl %eax, %esi
shrl %esi
leaq (%rsi,%rsi,2), %r9
leaq 0x18f7d4(%rip), %r10    # 0x296230
movq 0x28(%r10), %r10
movq %r10, -0x8(%rsp)
movb (%r10,%rsi), %sil
xorl %r10d, %r10d
cmpb $0x1, %sil
sete %r10b
leal (%r10,%r10,2), %r10d
decl %r10d
cmpb $0x2, %sil
movl $0x1, %esi
cmovnel %r10d, %esi
movl %esi, -0x3c(%rsp)
movl 0xc(%rdx,%r9,8), %r13d
testl %r13d, %r13d
je 0x106e93
movq %rdi, -0x20(%rsp)
movq %r8, -0x18(%rsp)
movl 0x60(%rsp), %ebp
leaq (%rdx,%r9,8), %rdx
movq %rdx, -0x28(%rsp)
movq (%rdx), %r14
leaq 0x18ec9d(%rip), %rdx    # 0x295758
movss 0x158(%rdx), %xmm0
movl %eax, %eax
movq %rax, -0x10(%rsp)
movq $0x0, -0x38(%rsp)
xorl %r15d, %r15d
movq %rax, -0x30(%rsp)
movl $0x0, -0x54(%rsp)
movq %rcx, -0x50(%rsp)
movq %rbx, -0x60(%rsp)
movq %r14, -0x68(%rsp)
leaq (%r15,%r15,4), %r9
movl 0xc(%r14,%r9,8), %edi
leaq (%rdi,%rdi,2), %rdx
movl (%rcx,%rdx,4), %eax
testl %eax, %eax
js 0x106c10
movq 0x20(%rbx), %rsi
cmpl $0x0, (%rsi,%rdi,8)
js 0x106c10
movq (%r14,%r9,8), %r8
testl %ebp, %ebp
jne 0x106b33
movq -0x8(%rsp), %rsi
movzbl (%rsi,%rdi), %esi
cmpl %esi, -0x3c(%rsp)
je 0x106c10
movl %r13d, -0x58(%rsp)
leaq (%r14,%r9,8), %r11
leaq (%rcx,%rdx,4), %rdx
movl 0x4(%rdx), %edx
subl %eax, %edx
movq 0x18(%r11), %r14
testl %r14d, %r14d
js 0x106b5f
movl 0x10(%r11), %r13d
movl 0x14(%r11), %ebp
subl %ebp, %edx
movl %edx, %eax
movl %r13d, %edx
jmp 0x106b6c
movl 0x10(%r11), %r13d
movl 0x14(%r11), %ebp
subl %ebp, %edx
movl %r13d, %eax
movq %r8, %rsi
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rcx,%rsi,4), %rsi
movl 0x4(%rsi), %r9d
movl (%rsi), %esi
movl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
andl %r10d, %esi
subl %esi, %r9d
cmpl %r8d, %edx
movl %r8d, %esi
cmovll %edx, %esi
movl 0x8(%r11), %r11d
movl %r9d, %r10d
subl %r11d, %r10d
cmpl %eax, %r10d
movl %eax, %ebx
cmovll %r10d, %ebx
cmpl %r12d, %esi
jg 0x106bfd
cmpl %r12d, %ebx
jg 0x106bfd
movl %r12d, %ecx
movl %r11d, %r12d
subl %r8d, %r12d
cvtsi2ss %r12, %xmm1
addl %esi, %r12d
addl %ebx, %r12d
cvtsi2ss %r12, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm1, %xmm2
ja 0x106bf5
subl %r13d, %ebp
xorps %xmm1, %xmm1
cvtsi2ss %rbp, %xmm1
addl %esi, %ebx
addl %ebp, %ebx
xorps %xmm2, %xmm2
cvtsi2ss %rbx, %xmm2
mulss %xmm0, %xmm2
ucomiss %xmm1, %xmm2
jbe 0x106c24
movl %ecx, %r12d
movq -0x50(%rsp), %rcx
movq -0x60(%rsp), %rbx
movl 0x60(%rsp), %ebp
movq -0x68(%rsp), %r14
movl -0x58(%rsp), %r13d
incq %r15
movl %r13d, %eax
cmpq %rax, %r15
jb 0x106af2
jmp 0x106e9b
cmpl %eax, %r10d
setl %sil
setg %r10b
cmpl %edx, %r8d
setg %bpl
setl %r13b
orb %r10b, %bpl
cmpb $0x1, %bpl
jne 0x106bf5
orb %sil, %r13b
je 0x106bf5
movl 0x38(%rsp), %esi
cmpl %esi, %r12d
movl -0x58(%rsp), %r13d
jl 0x106cf8
cmpl %esi, %ebx
movl %ecx, %r12d
movq -0x50(%rsp), %rcx
jl 0x106d00
testl %r14d, %r14d
setns %r14b
addl %r11d, %eax
movl %r9d, %r10d
subl %eax, %r10d
xorl %eax, %eax
movl %r8d, %ebx
subl %edx, %ebx
setle %sil
setg %dl
cmovlel %r10d, %ebx
testl %ebx, %ebx
js 0x106d00
movb %sil, %al
shrq $0x1f, %r8
andl $-0x2, %r8d
orq %rax, %r8
cmpl -0x10(%rsp), %r8d
jne 0x106d00
movl %edi, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq -0x18(%rsp), %rsi
cmpq %rax, (%rsi)
jbe 0x106d00
movq 0x8(%rsi), %rsi
movl (%rsi,%rax,4), %eax
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
cmpq %rsi, %rax
je 0x106d00
testl %eax, %eax
jns 0x106d00
movl %eax, %r10d
andl $0x7fffffff, %r10d      # imm = 0x7FFFFFFF
xorl %esi, %esi
cmpl $0x0, 0x58(%rsp)
je 0x106d13
movq 0x50(%rsp), %r8
movl 0x58(%rsp), %r11d
cmpl (%r8,%rsi,4), %r10d
je 0x106d13
incq %rsi
cmpq %rsi, %r11
jne 0x106ce8
jmp 0x106d19
movl %ecx, %r12d
movq -0x50(%rsp), %rcx
movq -0x60(%rsp), %rbx
movl 0x60(%rsp), %ebp
movq -0x68(%rsp), %r14
jmp 0x106c10
cmpl 0x58(%rsp), %esi
jne 0x106d00
movq -0x20(%rsp), %r11
movq 0x18(%r11), %r8
movq 0x20(%r8), %rsi
cmpl $0x0, (%rsi,%r10,8)
js 0x106d00
movl %ebx, -0x44(%rsp)
xorb %dl, %r14b
movzbl %r14b, %edx
leal (%rdx,%rdi,2), %edx
movq 0x10(%r11), %rdi
leaq (%r10,%r10,4), %r10
movl 0x4(%rdi,%r10,8), %esi
cmpl %esi, %edx
jne 0x106d61
movl 0x8(%rdi,%r10,8), %edi
movq -0x60(%rsp), %rbx
movl 0x60(%rsp), %ebp
movq -0x68(%rsp), %r14
jmp 0x106d7f
leaq (%rdi,%r10,8), %r10
movl %edx, %edi
cmpl 0x8(%r10), %edx
movq -0x60(%rsp), %rbx
movl 0x60(%rsp), %ebp
movq -0x68(%rsp), %r14
jne 0x106c10
cmpl %esi, %edx
leal 0x1(%rax,%rax), %esi
movq -0x30(%rsp), %r10
cmovel %esi, %r10d
addl %eax, %eax
cmpl %edi, %edx
cmovel %eax, %r10d
movq 0x28(%r8), %rdx
movq %r10, -0x30(%rsp)
movq (%rdx,%r10,8), %rdi
movq %rdi, %rsi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %rsi
je 0x106e61
movq 0x8(%r8), %rax
shrq $0x20, %rdi
leaq (%rdi,%rdi,2), %rdi
leaq (%rax,%rdi,8), %rdi
addq $0xc, %rdi
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %r8
xorl %esi, %esi
xorl %r11d, %r11d
movl (%rdi,%rsi), %r10d
notl %r10d
shrl $0x1f, %r10d
addl %r10d, %r11d
addq $0x18, %rsi
cmpq %rsi, %r8
jne 0x106dd5
cmpl $0x1, %r11d
jne 0x106e61
xorl %esi, %esi
cmpl $0x0, (%rdi,%rsi)
js 0x106e04
movl -0x4(%rdi,%rsi), %r10d
movl %r10d, -0x40(%rsp)
addq $0x18, %rsi
cmpq %rsi, %r8
jne 0x106df4
movl -0x40(%rsp), %esi
xorl $0x1, %esi
movq (%rdx,%rsi,8), %rsi
movq %rsi, %rdx
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %rdi, %rdx
je 0x106e61
shrq $0x20, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rax,%rsi,8), %rax
addq $0xc, %rax
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdx
xorl %esi, %esi
xorl %edi, %edi
movl (%rax,%rsi), %r8d
notl %r8d
shrl $0x1f, %r8d
addl %r8d, %edi
addq $0x18, %rsi
cmpq %rsi, %rdx
jne 0x106e41
cmpl $0x1, %edi
je 0x106c10
subl -0x44(%rsp), %r9d
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
incl -0x54(%rsp)
movq -0x38(%rsp), %rdx
addl %r9d, %edx
movq 0x48(%rsp), %rax
movq %rdx, -0x38(%rsp)
movl %edx, (%rax)
movq -0x28(%rsp), %rax
movl 0xc(%rax), %r13d
jmp 0x106c10
movl $0x0, -0x54(%rsp)
movl -0x54(%rsp), %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq