// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/Overlaps.cpp
// Function: get_edge2existing_node_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*, asg_arc_t*, unsigned int)
inline uint32_t get_edge2existing_node_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* index, asg_arc_t* t, 
uint32_t ignore_trio_flag)
{
    uint32_t qn = query>>1, uId, is_Unitig;
    int32_t r;
    ma_hit_t *h = NULL;
    ma_sub_t *sq = NULL;
    ma_sub_t *st = NULL;
    ma_hit_t_alloc* x = &(sources[qn]);

    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 (; (*index) < x->length; (*index)++)
    {
        h = &(x->buffer[(*index)]);
        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;

        (*index)++;
        return 1;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x18(%rsp)
movq %r8, 0x10(%rsp)
movq %rcx, %r15
movq %rsi, %r12
movq %rdi, 0x20(%rsp)
movl 0x70(%rsp), %eax
movl 0x88(%rsp), %ebp
movq 0x80(%rsp), %r14
movq 0x78(%rsp), %rbx
shrl %eax
imulq $0x18, %rax, %r13
addq %rdx, %r13
leaq 0x18f7e2(%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, 0xc(%rsp)
movl (%rbx), %eax
cmpl 0xc(%r13), %eax
jae 0xc4b6a
movq (%r13), %rdi
movl %eax, %eax
imulq $0x28, %rax, %rdx
movl 0xc(%rdi,%rdx), %esi
imulq $0xc, %rsi, %rcx
movl (%r15,%rcx), %eax
testl %eax, %eax
js 0xc4b5f
movq 0x20(%r12), %r8
cmpl $0x0, (%r8,%rsi,8)
js 0xc4b5f
movl 0x4(%rdi,%rdx), %r8d
testl %ebp, %ebp
jne 0xc4aca
leaq 0x18f779(%rip), %r10    # 0x254230
movq 0x28(%r10), %r10
movzbl (%r10,%rsi), %esi
cmpl %esi, 0xc(%rsp)
je 0xc4b5f
addq %rdx, %rdi
imulq $0xc, %r8, %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 0x18ec65(%rip), %rax    # 0x253758
movss 0x158(%rax), %xmm0
movl 0x60(%rsp), %ecx
movl 0x68(%rsp), %r8d
movq %r14, %r9
callq 0x6a4a7
testl %eax, %eax
js 0xc4b5f
movl 0x70(%rsp), %eax
cmpl %eax, 0x4(%r14)
jne 0xc4b5f
movl 0x8(%r14), %eax
shrl %eax
movq 0x10(%rsp), %rcx
cmpq %rax, (%rcx)
jbe 0xc4b5f
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rcx
movl (%rcx,%rax,4), %ecx
cmpl $-0x2, %ecx
jg 0xc4b5f
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq 0x20(%rsp), %rdx
movq 0x18(%rdx), %rdx
movq 0x20(%rdx), %rdx
cmpl $0x0, (%rdx,%rcx,8)
js 0xc4b5f
movq 0x18(%rsp), %rcx
cmpb $0x0, (%rcx,%rax)
jne 0xc4b7b
movl (%rbx), %eax
incl %eax
movl %eax, (%rbx)
jmp 0xc4a6f
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incl (%rbx)
pushq $0x1
popq %rax
jmp 0xc4b6c
nop