// File: /workspace/github_cpp_makefile_star2_O2/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 $0x48, %rsp
movq %r9, 0x20(%rsp)
movq %rcx, %r15
movq %rdi, 0x28(%rsp)
movl 0x90(%rsp), %eax
movl 0xa8(%rsp), %r12d
movq 0x98(%rsp), %rcx
andl $0x0, (%rcx)
shrl %eax
imulq $0x18, %rax, %rbx
addq %rdx, %rbx
leaq 0x18fc3b(%rip), %rcx    # 0x254230
movq 0x28(%rcx), %rcx
movb (%rcx,%rax), %al
xorl %ecx, %ecx
cmpb $0x1, %al
sete %cl
leal (%rcx,%rcx,2), %ecx
decl %ecx
cmpb $0x2, %al
pushq $0x1
popq %rax
cmovel %eax, %ecx
movl %ecx, 0x1c(%rsp)
xorl %r14d, %r14d
movl $0x0, 0x8(%rsp)
xorl %ebp, %ebp
movl $0x0, 0xc(%rsp)
movl %eax, 0x10(%rsp)
movq %rsi, (%rsp)
movl 0xc(%rbx), %eax
cmpq %rax, %rbp
jae 0xc47d6
movq (%rbx), %rdi
movl 0xc(%rdi,%r14), %edx
imulq $0xc, %rdx, %rcx
movl (%r15,%rcx), %eax
testl %eax, %eax
js 0xc4784
movq 0x20(%rsi), %r9
cmpl $0x0, (%r9,%rdx,8)
js 0xc4784
movl 0x4(%rdi,%r14), %r11d
testl %r12d, %r12d
jne 0xc4688
leaq 0x18fbbb(%rip), %r9     # 0x254230
movq 0x28(%r9), %r9
movzbl (%r9,%rdx), %edx
cmpl %edx, 0x1c(%rsp)
je 0xc4784
movq %r8, %r13
addq %r14, %rdi
imulq $0xc, %r11, %rdx
addq %r15, %rdx
addq %r15, %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 0x18f0a4(%rip), %rax    # 0x253758
movss 0x158(%rax), %xmm0
movl 0x80(%rsp), %ecx
movl 0x88(%rsp), %r8d
leaq 0x30(%rsp), %r9
callq 0x6a4a7
testl %eax, %eax
js 0xc477d
movl 0x90(%rsp), %eax
cmpl %eax, 0x34(%rsp)
movq %r13, %r8
jne 0xc4780
movl 0x38(%rsp), %eax
shrl %eax
cmpq %rax, (%r8)
jbe 0xc4780
movq 0x8(%r8), %rcx
movl (%rcx,%rax,4), %r9d
cmpl $-0x2, %r9d
jg 0xc4780
andl $0x7fffffff, %r9d       # imm = 0x7FFFFFFF
movq 0x28(%rsp), %rcx
movq 0x18(%rcx), %rcx
movq 0x20(%rcx), %rdx
cmpl $0x0, (%rdx,%r9,8)
js 0xc4780
movq 0x20(%rsp), %rdx
cmpb $0x0, (%rdx,%rax)
je 0xc4780
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
sete %al
cmpl $0x0, 0x10(%rsp)
sete %dl
orb %al, %dl
jne 0xc4790
movl 0x14(%rcx), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %esi, %esi
movq %r9, 0x10(%rsp)
callq 0x20e0
movq 0x10(%rsp), %r9
movq 0xa0(%rsp), %rdi
movq %r13, %r8
movq 0x98(%rsp), %rcx
jmp 0xc47a4
movq %r13, %r8
movq (%rsp), %rsi
incq %rbp
addq $0x28, %r14
jmp 0xc4631
pushq $0x1
popq %rax
testq %rdi, %rdi
movq 0x98(%rsp), %rcx
movl 0x8(%rsp), %esi
je 0xc47b5
xorl %eax, %eax
cmpb $0x0, (%rdi,%r9)
sete %al
movb $0x1, (%rdi,%r9)
movl (%rcx), %esi
addl %eax, 0xc(%rsp)
movl 0x3c(%rsp), %eax
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
andl %edx, %eax
addl %eax, %esi
movl %esi, 0x8(%rsp)
movl %esi, (%rcx)
movl $0x0, 0x10(%rsp)
jmp 0xc4780
movl 0xc(%rsp), %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq