// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: asg_cut_chimeric_bub(asg_t*, ma_hit_t_alloc*, asg64_v*, unsigned int, unsigned int, telo_end_t*)
uint32_t asg_cut_chimeric_bub(asg_t *g, ma_hit_t_alloc* src, asg64_v *in, uint32_t normal_len, uint32_t is_clean, telo_end_t *te)
{
    asg64_v tx = {0,0,0}, *b = NULL;
    uint32_t v, w, nw, k, n_vtx = g->n_seq<<1, ei[2] = {0}, e, ss, cnt = 0;
    asg_arc_t *aw;
    if(in) b = in;
    else b = &tx;
    b->n = 0;
    // fprintf(stderr, "[M::%s]\n", __func__);
    for (v = 0; v < n_vtx; ++v) {
        if (g->seq[v>>1].del) continue;
        if(te && te->hh[v>>1]) continue;
        ///note: ei[0] and ei[1] are the edge idx
        if((get_arcs(g, v, &(ei[0]), 1)!=1) || (get_arcs(g, v^1, &(ei[1]), 1)!=1)) continue;
        assert((g->arc[ei[0]].ul>>32) == v && (g->arc[ei[1]].ul>>32) == (v^1));
        if((get_arcs(g, g->arc[ei[0]].v^1, NULL, 0)!=2) || (get_arcs(g, g->arc[ei[1]].v^1, NULL, 0)!=2)) continue;
        if(!if_sup_chimeric(&(src[v>>1]), g->seq[v>>1].len, b, 1)) continue;
        w = g->arc[ei[0]].v^1;
        aw = asg_arc_a(g, w); nw = asg_arc_n(g, w);
        for (k = 0; k < nw; k++) {
            if (aw[k].del) continue;
            if (aw[k].v == (v^1)) {
                ss = k; continue;
            }
            break;
        }
        // assert(aw[ss].v == (v^1));//this assert does not work, just ignore
        if(follow_limit_path(g, aw[k].v, &e, &ss, NULL, (uint32_t)-1) != TWO_INPUT) continue;
        if(ss > normal_len) {
            w = e;
            aw = asg_arc_a(g, w); nw = asg_arc_n(g, w);
            for (k = ss = 0; k < nw; k++) {
                if (aw[k].del) continue;
                ss++; e = aw[k].v;
                if(ss > 1) break;
            }
            if(ss == 1 && e == g->arc[ei[1]].v) asg_seq_del(g, v>>1), cnt++;
        }
    }

    if(!in) free(tx.a);
    if (is_clean && cnt > 0) asg_cleanup(g);
    return cnt;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movl %r8d, 0x44(%rsp)
movq %rdi, %r8
xorps %xmm0, %xmm0
leaq 0x60(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movl 0x14(%rdi), %ebp
leaq 0x1c(%rsp), %rdi
andq $0x0, -0x4(%rdi)
addl %ebp, %ebp
testq %rdx, %rdx
movq %rdx, 0x58(%rsp)
cmovneq %rdx, %rax
movl %ecx, 0x40(%rsp)
movq %rax, 0x50(%rsp)
andq $0x0, (%rax)
movq %rsi, 0x48(%rsp)
xorl %r15d, %r15d
pushq $0x1
popq %r13
movl $0x0, 0x28(%rsp)
movq %r9, 0x38(%rsp)
movq %rbp, 0x20(%rsp)
cmpq %rbp, %r15
je 0x1acdcf
movq 0x20(%r8), %r14
movl %r15d, %r12d
shrl %r12d
cmpl $0x0, (%r14,%r12,8)
js 0x1acca7
testq %r9, %r9
je 0x1acb34
movq 0x10(%r9), %rax
cmpb $0x0, (%rax,%r12)
jne 0x1acca7
movq %r9, %rbp
movq %r8, %rdi
movl %r15d, %esi
leaq 0x18(%rsp), %rdx
movl %r13d, %ecx
movq %r15, %rbx
movq %r8, %r15
callq 0x1a5422
cmpl $0x1, %eax
jne 0x1acc86
movl %ebx, %esi
xorl $0x1, %esi
movq %r15, %rdi
movl %esi, 0x2c(%rsp)
leaq 0x1c(%rsp), %rdx
movl %r13d, %ecx
callq 0x1a5422
cmpl $0x1, %eax
jne 0x1acc82
movq 0x8(%r15), %rbp
movl 0x18(%rsp), %eax
imulq $0x18, %rax, %rax
movl 0x4(%rbp,%rax), %ecx
cmpq %rbx, %rcx
jne 0x1ace18
movq %r15, %r13
movq %rbx, %r15
movl 0x1c(%rsp), %ecx
imulq $0x18, %rcx, %rbx
movl 0x2c(%rsp), %ecx
cmpl %ecx, 0x4(%rbp,%rbx)
jne 0x1ace18
addq %rbp, %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
movq %r13, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1a5422
cmpl $0x2, %eax
jne 0x1acc96
movl 0x8(%rbp,%rbx), %esi
xorl $0x1, %esi
movq %r13, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1a5422
cmpl $0x2, %eax
movq %r13, %r8
jne 0x1acc99
movq %r8, 0x30(%rsp)
imulq $0x18, %r12, %rdi
addq 0x48(%rsp), %rdi
movl (%r14,%r12,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq 0x50(%rsp), %rdx
pushq $0x1
popq %rcx
callq 0x1a4f97
testl %eax, %eax
movq 0x38(%rsp), %r9
movq 0x20(%rsp), %rbp
je 0x1accb7
movl 0x18(%rsp), %eax
imulq $0x18, %rax, %rax
movq 0x30(%rsp), %rdi
movq 0x8(%rdi), %rdx
movq 0x28(%rdi), %rcx
movl 0x8(%rdx,%rax), %eax
xorq $0x1, %rax
movq (%rcx,%rax,8), %rcx
movl %ecx, %eax
shrq $0x20, %rcx
imulq $0x18, %rcx, %rsi
leaq (%rdx,%rsi), %rcx
addq %rsi, %rdx
addq $0xc, %rdx
xorl %esi, %esi
movl 0xc(%rsp), %r8d
movl 0x2c(%rsp), %r10d
cmpq %rsi, %rax
je 0x1accaf
cmpl $0x0, (%rdx)
js 0x1acc79
cmpl %r10d, -0x4(%rdx)
jne 0x1accc2
movl %esi, %r8d
incq %rsi
addq $0x18, %rdx
jmp 0x1acc66
pushq $0x1
popq %r13
movq %rbp, %r9
movq 0x20(%rsp), %rbp
movq %r15, %r8
movq %rbx, %r15
jmp 0x1acca7
movq %r13, %r8
movq 0x38(%rsp), %r9
movq 0x20(%rsp), %rbp
pushq $0x1
popq %r13
incq %r15
jmp 0x1acb02
movq %r15, %rbx
movq %r9, %r14
jmp 0x1acccb
pushq $0x1
popq %r13
movq 0x30(%rsp), %r8
jmp 0x1acca7
movq %r15, %rbx
movq %r9, %r14
movq %rsi, %rax
movl %r8d, 0x10(%rsp)
imulq $0x18, %rax, %rax
movl 0x8(%rcx,%rax), %esi
leaq 0x14(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %rdi, %r15
xorl %r8d, %r8d
pushq $-0x1
popq %r9
callq 0x1a5520
cmpl $0x1, %eax
sete %al
movl 0x10(%rsp), %edx
cmpl 0x40(%rsp), %edx
seta %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1acd5d
movl 0x14(%rsp), %eax
movq 0x8(%r15), %rcx
movq 0x28(%r15), %rdx
movq (%rdx,%rax,8), %rdx
movl %edx, %esi
movq %rdx, %rdi
shrq $0x20, %rdi
imulq $0x18, %rsi, %rdx
imulq $0x18, %rdi, %rsi
addq %rcx, %rsi
addq $0xc, %rsi
xorl %edi, %edi
xorl %r10d, %r10d
movq %r14, %r9
movq %r15, %r8
movq %rbx, %r15
cmpq %rdi, %rdx
je 0x1acd6d
cmpl $0x0, (%rsi,%rdi)
js 0x1acd57
incl %r10d
movl -0x4(%rsi,%rdi), %eax
cmpl $0x1, %r10d
ja 0x1acdb2
addq $0x18, %rdi
jmp 0x1acd3f
movl %edx, 0xc(%rsp)
pushq $0x1
popq %r13
movq %r14, %r9
jmp 0x1acc8e
movl %r10d, 0x10(%rsp)
movl %eax, 0x14(%rsp)
cmpl $0x1, %r10d
jne 0x1acdc5
movl 0x1c(%rsp), %edx
imulq $0x18, %rdx, %rdx
cmpl 0x8(%rcx,%rdx), %eax
jne 0x1acda4
movq %r8, %rdi
movl %r12d, %esi
movq %r9, %r14
callq 0x1a606e
movq 0x30(%rsp), %r8
movq %r14, %r9
incl 0x28(%rsp)
pushq $0x1
popq %r13
movl %r13d, 0xc(%rsp)
jmp 0x1acca7
movl %r10d, 0xc(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x14(%rsp)
jmp 0x1acca3
movl %r10d, 0xc(%rsp)
jmp 0x1acca3
cmpq $0x0, 0x58(%rsp)
jne 0x1acde7
movq 0x70(%rsp), %rdi
movq %r8, %rbx
callq 0x2220
movq %rbx, %r8
cmpl $0x0, 0x44(%rsp)
setne %al
movl 0x28(%rsp), %ebp
testl %ebp, %ebp
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1ace07
movq %r8, %rdi
callq 0x694eb
movl %ebp, %eax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4a67b(%rip), %rdi     # 0x1f749a
leaq 0x4a6b3(%rip), %rsi     # 0x1f74d9
leaq 0x4abab(%rip), %rcx     # 0x1f79d8
movl $0xa20, %edx            # imm = 0xA20
callq 0x2110