// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: iter_contain_g(R_to_U*, flex_asg_t*, unsigned int, asg64_v*, asg64_v*, float, unsigned int)
uint32_t iter_contain_g(R_to_U* rI, flex_asg_t *fg, uint32_t v0, asg64_v *b, asg64_v *st, float ou_rat, uint32_t only_trans_nn)
{
    uint32_t v, w = (uint32_t)-1, x, i, kv, kw, ulen, cnt = 0, st_n, m, is_purge; 
    asg_arc_t *s; flex_asg_e_retrive_t rr;
    b->n = st->n = ulen = 0; kv_push(uint64_t, *st, v0);
    while (st->n) {
        v = kv_pop(*st); kv = kw = (uint32_t)-1; ulen = 0;
        if(fg->g->seq_vis[v>>1]) continue;
        while ((!(fg->g->seq_vis[v>>1])) && (is_contain_r((*rI), (v>>1)))) {///push a unitig
            kv = get_flex_arcs(fg, v, &w, 1); ulen++;
            kv_push(uint64_t, *b, v); 
            if(kv == 1) {
                flex_arcs0(s, (*fg), w);
                w = s->v;
                kw = get_flex_arcs(fg, w^1, NULL, 0);
                if(kw == 1) v = w;
                else break;
            } else {
                break;
            }
        }
        // if((v0>>1) == 12321 || (v0>>1) == 12334) {
        //     fprintf(stderr, "0[M::%s] v0>>1::%u(%c), b->n::%u, ulen::%u\n", 
        //     __func__, (v0>>1), "+-"[v0&1], (uint32_t)b->n, ulen);
        // }   
        if((!ulen) || (fg->g->seq_vis[v>>1]) || (!(is_contain_r((*rI), (v>>1))))) {
            for (i = b->n - ulen; i < b->n; i++) {
                fg->g->seq_vis[b->a[i]>>1] = 1; b->a[i] |= ((uint64_t)0x100000000);
            }
            continue;
        }
        // fprintf(stderr, "1[M::%s] v0>>1::%u(%c), b->n::%u, ulen::%u\n", 
        //     __func__, (v0>>1), "+-"[v0&1], (uint32_t)b->n, ulen);
        
        for (i = 0; i < b->n; i++) {
            if(b->a[i]&(0x100000000)) continue;
            fg->g->seq_vis[b->a[i]>>1] = 2;
        }
        // fprintf(stderr, "2[M::%s] v0>>1::%u(%c), b->n::%u, ulen::%u\n", 
        //     __func__, (v0>>1), "+-"[v0&1], (uint32_t)b->n, ulen);
        for (i = 0, st_n = st->n; i < b->n; i++) {
            if(b->a[i]&(0x100000000)) continue;
            if(detect_tip2(fg, b->a[i]>>1, st, ou_rat)) break;
        }
        if(i >= b->n) is_purge = 1;
        else is_purge = 0;
        // fprintf(stderr, "3[M::%s] v0>>1::%u(%c), b->n::%u, ulen::%u\n", 
        //     __func__, (v0>>1), "+-"[v0&1], (uint32_t)b->n, ulen);
        for (i = m = st_n; i < st->n; i++) {
            if(fg->g->seq_vis[st->a[i]]&128) fg->g->seq_vis[st->a[i]] -= 128;
            ///append edges to all nodes, instead of non-contained only
            // if(is_contain_r((*rI), (st->a[i]>>1))) continue;
            st->a[m++] = st->a[i];
        }
        st->n = m;
        // if((v0>>1) == 12321 || (v0>>1) == 12334) {
        //     fprintf(stderr, "4[M::%s] v0>>1::%u(%c), b->n::%u, i::%u\n", 
        //         __func__, (v0>>1), "+-"[v0&1], (uint32_t)b->n, i);
        // }
        if(is_purge && only_trans_nn) {
            is_purge = append_trans_check(fg, st->a + st_n, st->n-st_n);
        }
        
        if(is_purge) {
            for (i = 0; i < b->n; i++) {
                x = ((uint32_t)b->a[i])>>1;
                // if((v0>>1) == 12321 || (v0>>1) == 12334) {
                //     fprintf(stderr, "del::[M::%s] x::%u, seq_vis::%u\n", __func__, x, fg->g->seq_vis[x]);
                // }
                if(fg->g->seq_vis[x]&2) {
                    asg_seq_del(fg->g, x); cnt++;
                }
                fg->g->seq_vis[x] = 0;
            }
            append_notrans_e(fg, st->a + st_n, st->n-st_n, b);
            st->n = st_n;
            return cnt;
        }
        for (i = 0; i < b->n; i++) {
            if(b->a[i]&(0x100000000)) continue;
            fg->g->seq_vis[b->a[i]>>1] = 1;
        }
        st->n = st_n;

        rr.i[0] = 0; rr.i[1] = (uint32_t)-1;
        while(1) {
            s = iter_flex_asg(fg, &rr, v);
            if(!s) break;
            if(s->del) continue;
            if(fg->g->seq_vis[s->v>>1]) continue;
            if(!is_contain_r((*rI), (s->v>>1))) continue;
            kv_push(uint64_t, *st, s->v); 
        }
    }
    for (i = 0; i < b->n; i++) fg->g->seq_vis[((uint32_t)b->a[i])>>1] = 0;
    return cnt;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %r9d, 0x2c(%rsp)
movss %xmm0, 0x18(%rsp)
movq %r8, %r12
movq %rcx, %rbx
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, 0x8(%rsp)
movl $0xffffffff, 0x14(%rsp) # imm = 0xFFFFFFFF
xorl %eax, %eax
movq %rax, (%r8)
movq %rax, (%rcx)
movq (%r8), %rcx
cmpq 0x8(%r8), %rcx
jne 0x1f64cc
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %esi
cmovneq %rax, %rsi
movq %rsi, 0x8(%r12)
movq 0x10(%r12), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r12)
movq (%r12), %rcx
jmp 0x1f64d1
movq 0x10(%r12), %rax
movl %ebp, %edx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r12)
movq %rdx, (%rax,%rcx,8)
movq (%r12), %r15
testq %r15, %r15
je 0x1f690d
leaq 0x58(%r14), %rax
movq %rax, 0x20(%rsp)
movq %r12, (%rsp)
movq 0x10(%r12), %rax
leaq -0x1(%r15), %rcx
movq %rcx, (%r12)
movq -0x8(%rax,%r15,8), %r13
movq 0x30(%r14), %rax
movq 0x30(%rax), %rax
movl %r13d, %ecx
shrl %ecx
cmpb $0x0, (%rax,%rcx)
jne 0x1f6738
xorl %r15d, %r15d
movl %r13d, %ebp
movq 0x30(%r14), %rax
movq 0x30(%rax), %rax
movl %r13d, %r12d
shrl %r12d
cmpb $0x0, (%rax,%r12)
jne 0x1f660e
movq 0x8(%rsp), %rax
cmpq %r12, (%rax)
jbe 0x1f660e
movq 0x8(%rax), %rax
cmpl $0x0, (%rax,%r12,4)
js 0x1f660e
movq %r14, %rdi
movl %ebp, %esi
leaq 0x14(%rsp), %rdx
movl $0x1, %ecx
callq 0x1efb23
movl %eax, %r13d
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x1f65a9
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
movl %ebp, %edx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
movq %rdx, (%rax,%rcx,8)
cmpl $0x1, %r13d
jne 0x1f660b
movl 0x14(%rsp), %eax
testl %eax, %eax
js 0x1f65ce
movq 0x30(%r14), %rcx
addq $0x8, %rcx
jmp 0x1f65d8
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x20(%rsp), %rcx
movq (%rcx), %rcx
movl %eax, %eax
leaq (%rax,%rax,2), %rax
movl 0x8(%rcx,%rax,8), %r13d
movl %r13d, 0x14(%rsp)
movl %r13d, %esi
xorl $0x1, %esi
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1efb23
incl %r15d
cmpl $0x1, %eax
je 0x1f6525
jmp 0x1f660e
incl %r15d
testl %r15d, %r15d
je 0x1f66f1
movq 0x30(%r14), %rax
movq 0x30(%rax), %rax
cmpb $0x0, (%rax,%r12)
jne 0x1f66f1
movq 0x8(%rsp), %rax
cmpq %r12, (%rax)
jbe 0x1f66f1
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
cmpl $0x0, (%rax,%r12,4)
js 0x1f66f1
movq (%rbx), %rcx
testq %rcx, %rcx
je 0x1f674a
movl $0x1, %eax
xorl %edx, %edx
movq (%rsp), %rdi
movabsq $0x100000000, %r8       # imm = 0x100000000
movq 0x10(%rbx), %rsi
movq (%rsi,%rdx,8), %rdx
testq %r8, %rdx
jne 0x1f668c
movq 0x30(%r14), %rcx
movq 0x30(%rcx), %rcx
shrq %rdx
movb $0x2, (%rcx,%rdx)
movq (%rbx), %rcx
movl %eax, %edx
incl %eax
cmpq %rdx, %rcx
ja 0x1f666d
movq (%rdi), %r13
testq %rcx, %rcx
je 0x1f6751
movl $0x1, %r15d
xorl %r12d, %r12d
movq 0x10(%rbx), %rax
movq (%rax,%r12,8), %rsi
movabsq $0x100000000, %rax      # imm = 0x100000000
testq %rax, %rsi
jne 0x1f66dd
shrq %rsi
movq %r14, %rdi
movq (%rsp), %rdx
movss 0x18(%rsp), %xmm0
callq 0x1f53b4
movq (%rbx), %rcx
testl %eax, %eax
jne 0x1f66e8
movl %r15d, %r12d
incl %r15d
cmpq %r12, %rcx
ja 0x1f66aa
movq (%rsp), %rax
movq (%rax), %rsi
jmp 0x1f6759
movq (%rbx), %rcx
movl %ecx, %eax
subl %r15d, %eax
cmpq %rax, %rcx
movq (%rsp), %r12
movabsq $0x100000000, %rdi      # imm = 0x100000000
jbe 0x1f6738
movq 0x10(%rbx), %rdx
movl %eax, %ecx
incl %ecx
movq 0x30(%r14), %rsi
movq 0x30(%rsi), %rsi
movq (%rdx,%rax,8), %rdx
shrq %rdx
movb $0x1, (%rsi,%rdx)
movq 0x10(%rbx), %rdx
orq %rdi, (%rdx,%rax,8)
movl %ecx, %eax
incl %ecx
cmpq %rax, (%rbx)
ja 0x1f6714
movq (%r12), %r15
testq %r15, %r15
jne 0x1f64f9
jmp 0x1f690d
movq (%rsp), %rax
movq (%rax), %r13
movq %r13, %rsi
xorl %ecx, %ecx
xorl %r12d, %r12d
xorl %eax, %eax
cmpq %r12, %rcx
setbe %dl
movl %r13d, %r15d
cmpq %r15, %rsi
jbe 0x1f67b7
movq (%rsp), %rsi
movq 0x10(%rsi), %rsi
movq %r15, %rdi
movq 0x30(%r14), %r8
movq 0x30(%r8), %r9
movq (%rsi,%rdi,8), %r8
movb (%r9,%r8), %r10b
testb %r10b, %r10b
js 0x1f678f
movq (%rsp), %r9
jmp 0x1f67a3
andb $0x7f, %r10b
movb %r10b, (%r9,%r8)
movq (%rsp), %r9
movq 0x10(%r9), %rsi
movq (%rsi,%rdi,8), %r8
movl %r13d, %edi
incl %r13d
movq %r8, (%rsi,%rdi,8)
movq %r13, %rdi
cmpq %r13, (%r9)
ja 0x1f6774
jmp 0x1f67ba
movl %r13d, %r13d
movb %dl, %al
movq (%rsp), %rdx
movq %r13, (%rdx)
cmpl $0x0, 0x2c(%rsp)
je 0x1f67f0
cmpq %r12, %rcx
movq (%rsp), %r12
ja 0x1f67f4
leaq (,%r15,8), %rsi
addq 0x10(%r12), %rsi
subq %r15, %r13
movq %r14, %rdi
movq %r13, %rdx
callq 0x1f6053
jmp 0x1f67f4
movq (%rsp), %r12
movq (%rbx), %rcx
testl %eax, %eax
jne 0x1f6952
testq %rcx, %rcx
je 0x1f683d
movl $0x1, %eax
xorl %edx, %edx
movq 0x10(%rbx), %rsi
movq (%rsi,%rdx,8), %rdx
movabsq $0x100000000, %rsi      # imm = 0x100000000
testq %rsi, %rdx
jne 0x1f6834
movq 0x30(%r14), %rcx
movq 0x30(%rcx), %rcx
shrq %rdx
movb $0x1, (%rcx,%rdx)
movq (%rbx), %rcx
movl %eax, %edx
incl %eax
cmpq %rdx, %rcx
ja 0x1f680b
movq %r15, (%r12)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x30(%rsp)
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
movl %ebp, %edx
callq 0x1f5346
testq %rax, %rax
je 0x1f673c
movq %rax, %r13
cmpl $0x0, 0xc(%r13)
js 0x1f68ed
movq 0x30(%r14), %rax
movq 0x30(%rax), %rdx
movl 0x8(%r13), %ecx
movl %ecx, %eax
shrl %eax
cmpb $0x0, (%rdx,%rax)
jne 0x1f68ed
movq 0x8(%rsp), %rdx
cmpq %rax, (%rdx)
jbe 0x1f68ed
movq 0x8(%rsp), %rdx
movq 0x8(%rdx), %rdx
cmpl $0x0, (%rdx,%rax,4)
js 0x1f68ed
movq (%r12), %rdx
movq 0x10(%r12), %rax
cmpq 0x8(%r12), %rdx
jne 0x1f68df
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r12)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r12)
movl 0x8(%r13), %ecx
movq (%r12), %rdx
movl %ecx, %ecx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r12)
movq %rcx, (%rax,%rdx,8)
movq %r14, %rdi
leaq 0x30(%rsp), %rsi
movl %ebp, %edx
callq 0x1f5346
movq %rax, %r13
testq %rax, %rax
jne 0x1f686b
jmp 0x1f6738
cmpq $0x0, (%rbx)
je 0x1f693d
movl $0x1, %eax
xorl %r13d, %r13d
xorl %ecx, %ecx
movq 0x30(%r14), %rdx
movq 0x30(%rdx), %rdx
movq 0x10(%rbx), %rsi
movl (%rsi,%rcx,8), %ecx
shrl %ecx
movb $0x0, (%rdx,%rcx)
movl %eax, %ecx
incl %eax
cmpq %rcx, (%rbx)
ja 0x1f691d
jmp 0x1f6940
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rcx, %rcx
je 0x1f6a82
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r13d, %r13d
movq 0x10(%rbx), %rdx
movq (%rdx,%rax,8), %rsi
movl %esi, %r8d
shrl %r8d
movq 0x30(%r14), %rdi
movq 0x30(%rdi), %rdx
testb $0x2, (%rdx,%r8)
je 0x1f6a70
movq %rax, 0x20(%rsp)
movq %r13, 0x8(%rsp)
movq 0x20(%rdi), %rdx
movq %r8, 0x18(%rsp)
orl $0x80000000, (%rdx,%r8,8) # imm = 0x80000000
andl $-0x2, %esi
movb $0x1, %r8b
xorl %r9d, %r9d
orq %rsi, %r9
movq 0x28(%rdi), %rdx
movq (%rdx,%r9,8), %rdx
movq %rdx, %r10
andq %rcx, %r10
je 0x1f6a3c
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %r11
shlq $0x3, %r11
addq 0x8(%rdi), %r11
xorl %r13d, %r13d
leaq (,%r13,2), %rdx
addq %r13, %rdx
orb $-0x80, 0xf(%r11,%rdx,8)
movl 0x8(%r11,%rdx,8), %edx
xorq $0x1, %rdx
movq 0x28(%rdi), %r12
movq (%r12,%rdx,8), %rdx
movq %rdx, %r12
andq %rcx, %r12
je 0x1f6a34
movq 0x8(%rdi), %rax
shrq $0x20, %rdx
shlq $0x3, %r12
leaq (%r12,%r12,2), %rbp
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %r12
addq $0xc, %r12
xorl %edx, %edx
movl -0x4(%r12,%rdx), %eax
xorl %r9d, %eax
cmpl $0x1, %eax
jne 0x1f6a2b
orb $-0x80, 0x3(%r12,%rdx)
addq $0x18, %rdx
cmpq %rdx, %rbp
jne 0x1f6a18
incq %r13
cmpq %r10, %r13
jne 0x1f69d0
movl $0x1, %r9d
testb $0x1, %r8b
movl $0x0, %r8d
jne 0x1f69aa
movq 0x8(%rsp), %r13
incl %r13d
movq 0x30(%r14), %rax
movq 0x30(%rax), %rdx
movq (%rsp), %r12
movq 0x20(%rsp), %rax
movq 0x18(%rsp), %r8
movb $0x0, (%rdx,%r8)
incl %eax
cmpq %rax, (%rbx)
ja 0x1f6965
jmp 0x1f6a85
xorl %r13d, %r13d
leaq (,%r15,8), %rsi
addq 0x10(%r12), %rsi
movq (%r12), %rdx
subq %r15, %rdx
movq %r14, %rdi
movq %rbx, %rcx
callq 0x1f5a8d
movq %r15, (%r12)
jmp 0x1f6940