// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: get_num_edges2existing_nodes_advance_by_broken_bub(ma_ug_t*, asg_t*, ma_hit_t_alloc*, ma_sub_t*, R_to_U*, unsigned char*, int, int, unsigned int, unsigned int*, unsigned char*, unsigned int)
inline uint32_t get_num_edges2existing_nodes_advance_by_broken_bub(ma_ug_t *ug, asg_t *g, 
ma_hit_t_alloc* sources, ma_sub_t *coverage_cut, R_to_U* ruIndex, uint8_t* expect_vis, 
int max_hang, int min_ovlp, uint32_t query, uint32_t* oLen, uint8_t* utg_vis, 
uint32_t ignore_trio_flag)
{
    (*oLen) = 0;
    uint32_t qn = query>>1, is_first = 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, occ = 0, uId, is_Unitig;

    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);
        if(uId == (uint32_t)-1 || is_Unitig == 0 || ug->g->seq[uId].del) continue;
        if(expect_vis[t.v>>1] == 0) continue;

        if(is_first && utg_vis) memset(utg_vis, 0, ug->g->n_seq);
        if(utg_vis == NULL || (utg_vis && utg_vis[uId] == 0)) occ++;
        ////fprintf(stderr, "found-utg%.6ul, occ: %u\n", uId+1, occ);
        if(utg_vis) utg_vis[uId] = 1;

        (*oLen) += t.ol;
        is_first = 0;
    }

    return occ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r9, 0x20(%rsp)
movq %r8, 0x30(%rsp)
movq %rcx, %r15
movq %rsi, %r12
movq %rdi, 0x28(%rsp)
movq 0xa8(%rsp), %rcx
movl 0xa0(%rsp), %eax
movl $0x0, (%rcx)
movl %eax, %esi
shrl %esi
leaq (%rsi,%rsi,2), %rcx
leaq 0x188707(%rip), %rdi    # 0x28b230
movq 0x28(%rdi), %rdi
movb (%rdi,%rsi), %sil
xorl %edi, %edi
cmpb $0x1, %sil
sete %dil
leal (%rdi,%rdi,2), %edi
decl %edi
cmpb $0x2, %sil
movl $0x1, %esi
cmovel %esi, %edi
movl %edi, 0x1c(%rsp)
cmpl $0x0, 0xc(%rdx,%rcx,8)
je 0x102d26
movl $0x1, 0x10(%rsp)
movl 0xb8(%rsp), %r9d
leaq (%rdx,%rcx,8), %r14
movl %eax, %eax
movq %rax, 0x38(%rsp)
xorl %ebx, %ebx
xorl %ebp, %ebp
movl $0x0, 0xc(%rsp)
movq (%r14), %rdi
movl 0xc(%rdi,%rbx), %edx
leaq (%rdx,%rdx,2), %rcx
movl (%r15,%rcx,4), %eax
testl %eax, %eax
js 0x102c5f
movq 0x20(%r12), %rsi
cmpl $0x0, (%rsi,%rdx,8)
js 0x102c5f
movl 0x4(%rdi,%rbx), %esi
testl %r9d, %r9d
jne 0x102bcb
leaq 0x188678(%rip), %r8     # 0x28b230
movq 0x28(%r8), %r8
movzbl (%r8,%rdx), %edx
cmpl %edx, 0x1c(%rsp)
je 0x102c5f
movl %r9d, %r13d
addq %rbx, %rdi
leaq (%rsi,%rsi,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
leaq 0x187b5f(%rip), %rax    # 0x28a758
movss 0x158(%rax), %xmm0
movl 0x90(%rsp), %ecx
movl 0x98(%rsp), %r8d
leaq 0x40(%rsp), %r9
callq 0xa159b
testl %eax, %eax
js 0x102c5c
movq 0x38(%rsp), %rax
cmpl %eax, 0x44(%rsp)
jne 0x102c5c
movl 0x48(%rsp), %eax
shrl %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq 0x30(%rsp), %rdx
cmpq %rax, (%rdx)
movl %r13d, %r9d
jbe 0x102c78
movq 0x8(%rdx), %rdx
movl (%rdx,%rax,4), %edx
cmpl $-0x1, %edx
je 0x102c78
movl %edx, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
testl %edx, %edx
setns %dl
jmp 0x102c7a
movl %r13d, %r9d
incq %rbp
movl 0xc(%r14), %eax
addq $0x28, %rbx
cmpq %rax, %rbp
jb 0x102b82
jmp 0x102d2e
xorl %edx, %edx
cmpl $-0x1, %ecx
sete %sil
orb %dl, %sil
jne 0x102c5f
movq 0x28(%rsp), %rdx
movq 0x18(%rdx), %rdx
movq 0x20(%rdx), %rsi
movl %ecx, %r8d
cmpl $0x0, (%rsi,%r8,8)
js 0x102c5f
movq 0x20(%rsp), %rcx
cmpb $0x0, (%rcx,%rax)
je 0x102c5f
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
sete %al
cmpl $0x0, 0x10(%rsp)
sete %cl
orb %al, %cl
jne 0x102ce7
movl 0x14(%rdx), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq %r8, 0x10(%rsp)
xorl %esi, %esi
callq 0x20e0
movq 0xb0(%rsp), %rdi
movq 0x10(%rsp), %r8
movl %r13d, %r9d
testq %rdi, %rdi
movq %rdi, %rax
je 0x102cf6
cmpb $0x0, (%rax,%r8)
jne 0x102cfa
incl 0xc(%rsp)
testq %rax, %rax
je 0x102d04
movb $0x1, (%rax,%r8)
movl 0x4c(%rsp), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
movq 0xa8(%rsp), %rcx
addl %eax, (%rcx)
movl $0x0, 0x10(%rsp)
jmp 0x102c5f
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq