// File: /workspace/github_cpp_makefile_star2_O3/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 0x1f884c
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 0x1f8642
testq %r12, %r12
je 0x1f84a9
movq 0x10(%r12), %rax
cmpb $0x0, (%rax,%r14)
jne 0x1f8642
movq %rbx, %rdi
movl %ebp, %esi
leaq 0x20(%rsp), %rdx
movl $0x1, %ecx
callq 0x1efacc
cmpl $0x1, %eax
jne 0x1f8642
movl %ebp, %r12d
xorl $0x1, %r12d
movq %rbx, %rdi
movl %r12d, %esi
leaq 0x24(%rsp), %rdx
movl $0x1, %ecx
callq 0x1efacc
cmpl $0x1, %eax
jne 0x1f863d
movq 0x8(%rbx), %rax
movl 0x20(%rsp), %ecx
leaq (%rcx,%rcx,2), %rdx
movl 0x4(%rax,%rdx,8), %ecx
cmpq %rbp, %rcx
jne 0x1f8892
movl 0x24(%rsp), %ecx
leaq (%rcx,%rcx,2), %rcx
cmpl %r12d, 0x4(%rax,%rcx,8)
jne 0x1f8892
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 0x1f863d
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 0x1f8543
cmpl $0x2, %r8d
jne 0x1f863d
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 0x1f863d
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 0x1f858e
cmpl $0x2, %esi
jne 0x1f863d
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 0x1ef642
testl %eax, %eax
je 0x1f863d
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), %rdx
movq %rdx, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
testl %edx, %edx
je 0x1f8653
movl %edx, %edi
leaq (%rax,%rcx,8), %r8
addq $0xc, %r8
xorl %esi, %esi
movl 0x8(%rsp), %r9d
cmpl $0x0, (%r8)
js 0x1f8625
cmpl %r12d, -0x4(%r8)
jne 0x1f8634
movl %esi, %r9d
incq %rsi
addq $0x18, %r8
cmpq %rsi, %rdi
jne 0x1f8616
movq %rdx, %rsi
movl %esi, %edx
movq 0x10(%rsp), %r12
jmp 0x1f865f
movq 0x10(%rsp), %r12
incq %rbp
cmpq %r13, %rbp
jne 0x1f847f
jmp 0x1f884c
xorl %edx, %edx
movq 0x10(%rsp), %r12
movl 0x8(%rsp), %r9d
leaq (%rax,%rcx,8), %rax
movl %r9d, 0xc(%rsp)
leaq (%rdx,%rdx,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 0x1efbd9
cmpl $0x1, %eax
sete %al
movl 0xc(%rsp), %edx
cmpl 0x30(%rsp), %edx
seta %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1f8804
movl 0x1c(%rsp), %eax
movq 0x28(%rbx), %rcx
movq (%rcx,%rax,8), %rdx
testl %edx, %edx
je 0x1f880d
movq 0x8(%rbx), %rcx
movq %rdx, %rsi
shrq $0x20, %rsi
movl %edx, %edi
leaq (%rsi,%rsi,2), %rdx
leaq (%rcx,%rdx,8), %rdx
addq $0xc, %rdx
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
cmpl $0x0, (%rdx,%rdi)
js 0x1f86f8
incl %r8d
movl -0x4(%rdx,%rdi), %eax
cmpl $0x1, %r8d
ja 0x1f8822
addq $0x18, %rdi
cmpq %rdi, %rsi
jne 0x1f86e1
movl %r8d, 0xc(%rsp)
movl %eax, 0x1c(%rsp)
cmpl $0x1, %r8d
jne 0x1f8835
movl 0x24(%rsp), %edx
leaq (%rdx,%rdx,2), %rdx
cmpl 0x8(%rcx,%rdx,8), %eax
jne 0x1f883f
movq 0x20(%rbx), %rax
orl $0x80000000, (%rax,%r14,8) # imm = 0x80000000
movl %ebp, %eax
andl $-0x2, %eax
movb $0x1, %cl
xorl %edx, %edx
orq %rax, %rdx
movq 0x28(%rbx), %rsi
movq (%rsi,%rdx,8), %rdi
movq %rdi, %rsi
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
andq %r8, %rsi
je 0x1f87d8
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 0x1f87d0
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 0x1f87c7
orb $-0x80, 0x3(%r10,%r11)
addq $0x18, %r11
cmpq %r11, %r9
jne 0x1f87b3
incq %r8
cmpq %rsi, %r8
jne 0x1f876b
movl $0x1, %edx
testb $0x1, %cl
movl $0x0, %ecx
jne 0x1f873b
movl $0x1, 0x8(%rsp)
movq 0x28(%rsp), %rax
incl %eax
movq %rax, 0x28(%rsp)
jmp 0x1f8642
movl %edx, 0x8(%rsp)
jmp 0x1f8642
movl $0x0, 0xc(%rsp)
movl $0x0, 0x8(%rsp)
jmp 0x1f8642
movl %r8d, 0x8(%rsp)
movl %r8d, 0xc(%rsp)
movl %eax, 0x1c(%rsp)
jmp 0x1f8642
movl %r8d, 0x8(%rsp)
jmp 0x1f8642
movl $0x1, 0x8(%rsp)
jmp 0x1f8642
cmpq $0x0, 0x48(%rsp)
jne 0x1f885e
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 0x1f8880
movq %rbx, %rdi
callq 0xa0a7d
movl %r14d, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x4cd31(%rip), %rdi     # 0x2455ca
leaq 0x4cd69(%rip), %rsi     # 0x245609
leaq 0x4d261(%rip), %rcx     # 0x245b08
movl $0xa20, %edx            # imm = 0xA20
callq 0x2110