// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movl %r8d, 0x34(%rsp)
movl %ecx, 0x30(%rsp)
movq %rsi, 0x40(%rsp)
movq %rdi, %rbx
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %rsi
movaps %xmm0, (%rsi)
xorl %ecx, %ecx
movq %rcx, 0x10(%rsi)
movl 0x14(%rdi), %eax
addl %eax, %eax
movq %rcx, 0x20(%rsp)
testq %rdx, %rdx
movq %rdx, 0x48(%rsp)
cmovneq %rdx, %rsi
movq $0x0, 0x28(%rsp)
movq %rsi, 0x38(%rsp)
movq %rcx, (%rsi)
testl %eax, %eax
je 0x1eda3e
movq %r9, %r12
movl %eax, %r13d
xorl %ebp, %ebp
movq $0x0, 0x28(%rsp)
movq %r9, 0x10(%rsp)
movq 0x20(%rbx), %r15
movl %ebp, %r14d
shrl %r14d
cmpl $0x0, (%r15,%r14,8)
js 0x1ed895
testq %r12, %r12
je 0x1ed702
movq 0x10(%r12), %rax
cmpb $0x0, (%rax,%r14)
jne 0x1ed895
movq %rbx, %rdi
movl %ebp, %esi
leaq 0x20(%rsp), %rdx
movl $0x1, %ecx
callq 0x1e50d4
cmpl $0x1, %eax
jne 0x1ed895
movl %ebp, %r12d
xorl $0x1, %r12d
movq %rbx, %rdi
movl %r12d, %esi
leaq 0x24(%rsp), %rdx
movl $0x1, %ecx
callq 0x1e50d4
cmpl $0x1, %eax
jne 0x1ed890
movq 0x8(%rbx), %rax
movl 0x20(%rsp), %ecx
leaq (%rcx,%rcx,2), %rdx
movl 0x4(%rax,%rdx,8), %ecx
cmpq %rbp, %rcx
jne 0x1eda84
movl 0x24(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
cmpl %r12d, 0x4(%rax,%rcx,8)
jne 0x1eda84
leaq (%rax,%rdx,8), %rdx
movl 0x8(%rdx), %esi
xorq $0x1, %rsi
movq 0x28(%rbx), %rdx
movq (%rdx,%rsi,8), %rsi
movq %rsi, %rdi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rdi
je 0x1ed890
shrq $0x20, %rsi
xorl %r8d, %r8d
movl %esi, %r9d
leaq (%r9,%r9,2), %r9
movl 0xc(%rax,%r9,8), %r9d
notl %r9d
shrl $0x1f, %r9d
addl %r9d, %r8d
incq %rsi
decq %rdi
jne 0x1ed79c
cmpl $0x2, %r8d
jne 0x1ed890
movl 0x8(%rax,%rcx,8), %ecx
xorq $0x1, %rcx
movq (%rdx,%rcx,8), %rcx
movq %rcx, %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rdx
je 0x1ed890
shrq $0x20, %rcx
xorl %esi, %esi
movl %ecx, %edi
leaq (%rdi,%rdi,2), %rdi
movl 0xc(%rax,%rdi,8), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %esi
incq %rcx
decq %rdx
jne 0x1ed7e7
cmpl $0x2, %esi
jne 0x1ed890
leaq (%r14,%r14,2), %rax
movq 0x40(%rsp), %rcx
leaq (%rcx,%rax,8), %rdi
movl (%r15,%r14,8), %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
movq 0x38(%rsp), %rdx
movl $0x1, %ecx
callq 0x1e4c39
testl %eax, %eax
je 0x1ed890
movq 0x8(%rbx), %rax
movq 0x28(%rbx), %rcx
movl 0x20(%rsp), %edx
leaq (%rdx,%rdx,2), %rdx
movl 0x8(%rax,%rdx,8), %edx
xorq $0x1, %rdx
movq (%rcx,%rdx,8), %rsi
movq %rsi, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
movl 0xc(%rsp), %edx
testl %esi, %esi
je 0x1ed8a6
movl %esi, %r8d
leaq (%rax,%rcx,8), %r9
addq $0xc, %r9
xorl %edi, %edi
cmpl $0x0, (%r9)
js 0x1ed87d
cmpl %r12d, -0x4(%r9)
jne 0x1ed88c
movl %edi, %edx
incq %rdi
addq $0x18, %r9
cmpq %rdi, %r8
jne 0x1ed86f
movq %rsi, %rdi
movl %edi, %esi
jmp 0x1ed8a8
movq 0x10(%rsp), %r12
incq %rbp
cmpq %r13, %rbp
jne 0x1ed6d8
jmp 0x1eda3e
xorl %esi, %esi
movq 0x10(%rsp), %r12
leaq (%rax,%rcx,8), %rax
movl %edx, 0xc(%rsp)
leaq (%rsi,%rsi,2), %rcx
movl 0x8(%rax,%rcx,8), %esi
movq %rbx, %rdi
leaq 0x1c(%rsp), %rdx
leaq 0xc(%rsp), %rcx
xorl %r8d, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0x1e51e1
cmpl $0x1, %eax
jne 0x1ed895
movl 0x30(%rsp), %eax
cmpl %eax, 0xc(%rsp)
jbe 0x1ed895
movl 0x1c(%rsp), %ecx
movq 0x8(%rbx), %rax
movq 0x28(%rbx), %rdx
movq (%rdx,%rcx,8), %rdx
movl $0x0, 0xc(%rsp)
testl %edx, %edx
je 0x1ed943
movq %rdx, %rsi
shrq $0x20, %rsi
movl %edx, %edx
leaq (%rsi,%rsi,2), %rsi
leaq (%rax,%rsi,8), %rsi
addq $0xc, %rsi
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rdi
xorl %r8d, %r8d
xorl %edx, %edx
cmpl $0x0, (%rsi,%r8)
js 0x1ed938
incl %edx
movl -0x4(%rsi,%r8), %ecx
cmpl $0x1, %edx
ja 0x1ed945
addq $0x18, %r8
cmpq %r8, %rdi
jne 0x1ed925
jmp 0x1ed945
xorl %edx, %edx
movl %edx, 0xc(%rsp)
movl %ecx, 0x1c(%rsp)
cmpl $0x1, %edx
jne 0x1ed895
movl 0x1c(%rsp), %ecx
movl 0x24(%rsp), %edx
leaq (%rdx,%rdx,2), %rdx
cmpl 0x8(%rax,%rdx,8), %ecx
jne 0x1ed895
movq 0x20(%rbx), %rax
orl $0x80000000, (%rax,%r14,8) # imm = 0x80000000
movl %ebp, %eax
andl $-0x2, %eax
xorl %ecx, %ecx
leaq (%rcx,%rax), %rdx
movq 0x28(%rbx), %rsi
movq (%rsi,%rdx,8), %rdi
movq %rdi, %rsi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rsi
je 0x1eda1d
shrq $0x20, %rdi
leaq (%rdi,%rdi,2), %rdi
shlq $0x3, %rdi
addq 0x8(%rbx), %rdi
xorl %r8d, %r8d
leaq (%r8,%r8,2), %r9
orb $-0x80, 0xf(%rdi,%r9,8)
movl 0x8(%rdi,%r9,8), %r9d
xorq $0x1, %r9
movq 0x28(%rbx), %r10
movq (%r10,%r9,8), %r10
movq %r10, %r9
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
andq %r11, %r9
je 0x1eda15
movq 0x8(%rbx), %r11
shrq $0x20, %r10
shlq $0x3, %r9
leaq (%r9,%r9,2), %r9
leaq (%r10,%r10,2), %r10
leaq (%r11,%r10,8), %r10
addq $0xc, %r10
xorl %r11d, %r11d
movl -0x4(%r10,%r11), %r14d
xorl %edx, %r14d
cmpl $0x1, %r14d
jne 0x1eda0c
orb $-0x80, 0x3(%r10,%r11)
addq $0x18, %r11
cmpq %r11, %r9
jne 0x1ed9f8
incq %r8
cmpq %rsi, %r8
jne 0x1ed9b0
leaq 0x1(%rcx), %rdx
testq %rcx, %rcx
movq %rdx, %rcx
je 0x1ed97f
movq 0x28(%rsp), %rax
incl %eax
movq %rax, 0x28(%rsp)
jmp 0x1ed895
cmpq $0x0, 0x48(%rsp)
jne 0x1eda50
movq 0x60(%rsp), %rdi
callq 0x2220
cmpl $0x0, 0x34(%rsp)
setne %al
movq 0x28(%rsp), %r14
testl %r14d, %r14d
setne %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1eda72
movq %rbx, %rdi
callq 0xa02fa
movl %r14d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4b85b(%rip), %rdi     # 0x2392e6
leaq 0x4b893(%rip), %rsi     # 0x239325
leaq 0x4bd8b(%rip), %rcx     # 0x239824
movl $0xa20, %edx            # imm = 0xA20
callq 0x2110