// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movl 0x38(%rbp), %eax
movq 0x30(%rbp), %rax
movq 0x28(%rbp), %rax
movl 0x20(%rbp), %eax
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq 0x28(%rbp), %rax
movl $0x0, (%rax)
movl 0x20(%rbp), %eax
shrl %eax
movl %eax, -0x34(%rbp)
movl $0x1, -0x38(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x68(%rbp)
movq $0x0, -0x70(%rbp)
movq -0x18(%rbp), %rax
movl -0x34(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movl $0x0, -0x80(%rbp)
leaq 0x25bc08(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movl -0x34(%rbp), %ecx
movzbl (%rax,%rcx), %eax
movl %eax, -0x8c(%rbp)
movl $0xffffffff, -0x90(%rbp) # imm = 0xFFFFFFFF
cmpl $0x0, 0x38(%rbp)
jne 0x169711
cmpl $0x1, -0x8c(%rbp)
jne 0x1696fc
movl $0x2, -0x90(%rbp)
cmpl $0x2, -0x8c(%rbp)
jne 0x16970f
movl $0x1, -0x90(%rbp)
jmp 0x169711
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movq -0x78(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jae 0x169927
movq -0x78(%rbp), %rax
movq (%rax), %rax
movl -0x7c(%rbp), %ecx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x60(%rbp)
movq -0x20(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rcx), %rcx
shrq $0x20, %rcx
movl %ecx, %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movq -0x20(%rbp), %rax
movq -0x60(%rbp), %rcx
movl 0xc(%rcx), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movl (%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x169797
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x60(%rbp), %rcx
movl 0xc(%rcx), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x16979c
jmp 0x169919
leaq 0x25bb2d(%rip), %rax    # 0x3c52d0
movq 0x28(%rax), %rax
movq -0x60(%rbp), %rcx
movl 0xc(%rcx), %ecx
movzbl (%rax,%rcx), %eax
cmpl -0x90(%rbp), %eax
jne 0x1697bf
jmp 0x169919
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rax
movl 0x4(%rax), %esi
movq -0x68(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subl %eax, %esi
movq -0x70(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x70(%rbp), %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subl %eax, %edx
movl 0x10(%rbp), %ecx
leaq 0x25b003(%rip), %rax    # 0x3c47f8
movss 0x158(%rax), %xmm0
movl 0x18(%rbp), %r8d
leaq -0x58(%rbp), %r9
callq 0xd0300
movl %eax, -0x3c(%rbp)
cmpl $0x0, -0x3c(%rbp)
jge 0x169818
jmp 0x169919
movq -0x58(%rbp), %rax
shrq $0x20, %rax
movl 0x20(%rbp), %ecx
cmpq %rcx, %rax
je 0x16982d
jmp 0x169919
movq -0x28(%rbp), %rdi
movl -0x50(%rbp), %esi
shrl %esi
leaq -0x84(%rbp), %rdx
leaq -0x88(%rbp), %rcx
callq 0xd3d50
cmpl $-0x1, -0x84(%rbp)
je 0x169878
cmpl $0x0, -0x88(%rbp)
je 0x169878
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rax), %rax
movl -0x84(%rbp), %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x16987d
jmp 0x169919
movq -0x30(%rbp), %rax
movl -0x50(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x169896
jmp 0x169919
cmpl $0x0, -0x38(%rbp)
je 0x1698c2
cmpq $0x0, 0x30(%rbp)
je 0x1698c2
movq 0x30(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x18(%rax), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %edx
xorl %esi, %esi
callq 0x2100
cmpq $0x0, 0x30(%rbp)
je 0x1698e3
cmpq $0x0, 0x30(%rbp)
je 0x1698ec
movq 0x30(%rbp), %rax
movl -0x84(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x1698ec
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
cmpq $0x0, 0x30(%rbp)
je 0x169901
movq 0x30(%rbp), %rax
movl -0x84(%rbp), %ecx
movb $0x1, (%rax,%rcx)
movl -0x4c(%rbp), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq 0x28(%rbp), %rax
addl (%rax), %ecx
movl %ecx, (%rax)
movl $0x0, -0x38(%rbp)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x169718
movl -0x80(%rbp), %eax
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)
nopl (%rax)