// File: 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
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movl %r8d, -0x20(%rbp)
movq %r9, -0x28(%rbp)
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2100
movq $0x0, -0x48(%rbp)
movq -0x8(%rbp), %rax
movl 0x14(%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
shll %eax
movl %eax, -0x5c(%rbp)
leaq -0x64(%rbp), %rdi
xorl %esi, %esi
movl $0x8, %edx
callq 0x2100
movl $0x0, -0x70(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x31d453
movq -0x18(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0x31d45b
leaq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x5c(%rbp), %eax
jae 0x31d7f1
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x31d498
jmp 0x31d7e3
cmpq $0x0, -0x28(%rbp)
je 0x31d4b9
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movl -0x4c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
cmpb $0x0, (%rax,%rcx)
je 0x31d4b9
jmp 0x31d7e3
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %esi
leaq -0x64(%rbp), %rdx
movl $0x1, %ecx
callq 0x311ba0
cmpl $0x1, %eax
jne 0x31d4f4
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %esi
xorl $0x1, %esi
leaq -0x64(%rbp), %rdx
addq $0x4, %rdx
movl $0x1, %ecx
callq 0x311ba0
cmpl $0x1, %eax
je 0x31d4f9
jmp 0x31d7e3
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rcx
shrq $0x20, %rcx
movl -0x4c(%rbp), %eax
movl %eax, %edx
xorl %eax, %eax
cmpq %rdx, %rcx
movb %al, -0x79(%rbp)
jne 0x31d54b
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x60(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
shrq $0x20, %rax
movl -0x4c(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
cmpq %rcx, %rax
sete %al
movb %al, -0x79(%rbp)
movb -0x79(%rbp), %al
testb $0x1, %al
jne 0x31d554
jmp 0x31d556
jmp 0x31d575
leaq 0x78c1d(%rip), %rdi     # 0x39617a
leaq 0x78c55(%rip), %rsi     # 0x3961b9
movl $0xa20, %edx            # imm = 0xA20
leaq 0x79148(%rip), %rcx     # 0x3966b8
callq 0x2130
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x311ba0
cmpl $0x2, %eax
jne 0x31d5cd
movq -0x8(%rbp), %rdi
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x60(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
xorl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
xorl %ecx, %ecx
callq 0x311ba0
cmpl $0x2, %eax
je 0x31d5d2
jmp 0x31d7e3
movq -0x10(%rbp), %rdi
movl -0x4c(%rbp), %eax
shrl %eax
movl %eax, %eax
imulq $0x18, %rax, %rax
addq %rax, %rdi
movq -0x8(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x4c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
movl %eax, %esi
movq -0x48(%rbp), %rdx
movl $0x1, %ecx
callq 0x311240
cmpl $0x0, %eax
jne 0x31d617
jmp 0x31d7e3
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x64(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x50(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x50(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x31d6c4
movq -0x78(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x31d694
jmp 0x31d6b9
movq -0x78(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl -0x4c(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x31d6b7
movl -0x58(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x31d6b9
jmp 0x31d6c4
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x31d671
movq -0x8(%rbp), %rdi
movq -0x78(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %esi
leaq -0x68(%rbp), %rdx
leaq -0x6c(%rbp), %rcx
xorl %eax, %eax
movl %eax, %r8d
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
callq 0x311da0
cmpl $0x1, %eax
je 0x31d6fb
jmp 0x31d7e3
movl -0x6c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jbe 0x31d7e1
movl -0x68(%rbp), %eax
movl %eax, -0x50(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x50(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x8(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x50(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x54(%rbp)
movl $0x0, -0x6c(%rbp)
movl $0x0, -0x58(%rbp)
movl -0x58(%rbp), %eax
cmpl -0x54(%rbp), %eax
jae 0x31d7a8
movq -0x78(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x31d776
jmp 0x31d79d
movl -0x6c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
movq -0x78(%rbp), %rax
movl -0x58(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x68(%rbp)
cmpl $0x1, -0x6c(%rbp)
jbe 0x31d79b
jmp 0x31d7a8
jmp 0x31d79d
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x31d753
cmpl $0x1, -0x6c(%rbp)
jne 0x31d7df
movl -0x68(%rbp), %eax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl -0x60(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x8(%rcx), %eax
jne 0x31d7df
movq -0x8(%rbp), %rdi
movl -0x4c(%rbp), %esi
shrl %esi
callq 0x312c50
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x31d7e1
jmp 0x31d7e3
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x31d46d
cmpq $0x0, -0x18(%rbp)
jne 0x31d801
movq -0x30(%rbp), %rdi
callq 0x2210
cmpl $0x0, -0x20(%rbp)
je 0x31d816
cmpl $0x0, -0x70(%rbp)
jbe 0x31d816
movq -0x8(%rbp), %rdi
callq 0xcdd10
movl -0x70(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)