// File: /workspace/github_cpp_makefile_star2_O1/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, 0x20(%rsp)
movss %xmm0, 0x24(%rsp)
movq %r8, %r15
movq %rcx, %rbx
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, (%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
xorl %eax, %eax
movq %rax, (%r8)
movq %rax, (%rcx)
movq 0x8(%r8), %rax
cmpq %rax, (%r8)
jne 0x1eb68e
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %esi
cmovneq %rcx, %rsi
movq %rsi, 0x8(%r15)
movq 0x10(%r15), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r15)
movl %ebp, %eax
movq (%r15), %rcx
movq 0x10(%r15), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r15)
movq %rax, (%rdx,%rcx,8)
movq (%r15), %rax
testq %rax, %rax
je 0x1ebaa1
leaq 0x58(%r14), %rcx
movq %rcx, 0x18(%rsp)
movq %r15, 0x10(%rsp)
movq 0x10(%r15), %rcx
leaq -0x1(%rax), %rdx
movq %rdx, (%r15)
movq -0x8(%rcx,%rax,8), %r13
movq 0x30(%r14), %rax
movq 0x30(%rax), %rax
movl %r13d, %ecx
shrl %ecx
cmpb $0x0, (%rax,%rcx)
jne 0x1eb8e3
xorl %r15d, %r15d
movl %r13d, %ebp
movq 0x30(%r14), %rax
movq 0x30(%rax), %rax
movl %r13d, %r12d
shrl %r12d
cmpb $0x0, (%rax,%r12)
jne 0x1eb7cf
movq (%rsp), %rax
cmpq %r12, (%rax)
jbe 0x1eb7cf
movq 0x8(%rax), %rax
cmpl $0x0, (%rax,%r12,4)
js 0x1eb7cf
movq %r14, %rdi
movl %ebp, %esi
leaq 0xc(%rsp), %rdx
movl $0x1, %ecx
callq 0x1e512b
movl %eax, %r13d
movq 0x8(%rbx), %rax
cmpq %rax, (%rbx)
jne 0x1eb763
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rbx)
movq 0x10(%rbx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%rbx)
movl %ebp, %eax
movq (%rbx), %rcx
movq 0x10(%rbx), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%rbx)
movq %rax, (%rdx,%rcx,8)
cmpl $0x1, %r13d
jne 0x1eb7cc
movl 0xc(%rsp), %eax
testl %eax, %eax
js 0x1eb78f
movq 0x30(%r14), %rcx
addq $0x8, %rcx
jmp 0x1eb799
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
movl %eax, %eax
leaq (%rax,%rax,2), %rax
movl 0x8(%rcx,%rax,8), %r13d
movl %r13d, 0xc(%rsp)
movl %r13d, %esi
xorl $0x1, %esi
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1e512b
incl %r15d
cmpl $0x1, %eax
je 0x1eb6e6
jmp 0x1eb7cf
incl %r15d
testl %r15d, %r15d
je 0x1eb8a0
movq 0x30(%r14), %rax
movq 0x30(%rax), %rax
cmpb $0x0, (%rax,%r12)
jne 0x1eb8a0
movq (%rsp), %rax
cmpq %r12, (%rax)
jbe 0x1eb8a0
movq (%rsp), %rax
movq 0x8(%rax), %rax
cmpl $0x0, (%rax,%r12,4)
js 0x1eb8a0
cmpq $0x0, (%rbx)
movq 0x10(%rsp), %rsi
movabsq $0x100000000, %rdi      # imm = 0x100000000
je 0x1eb84c
movl $0x1, %eax
xorl %ecx, %ecx
movq 0x10(%rbx), %rdx
movq (%rdx,%rcx,8), %rcx
testq %rdi, %rcx
jne 0x1eb843
movq 0x30(%r14), %rdx
movq 0x30(%rdx), %rdx
shrq %rcx
movb $0x2, (%rdx,%rcx)
movl %eax, %ecx
incl %eax
cmpq %rcx, (%rbx)
ja 0x1eb827
movq (%rsi), %r15
cmpq $0x0, (%rbx)
je 0x1eb8f9
movl $0x1, %r13d
xorl %r12d, %r12d
movq 0x10(%rbx), %rax
movq (%rax,%r12,8), %rsi
movabsq $0x100000000, %rax      # imm = 0x100000000
testq %rax, %rsi
jne 0x1eb893
shrq %rsi
movq %r14, %rdi
movq 0x10(%rsp), %rdx
movss 0x24(%rsp), %xmm0
callq 0x1ea896
testl %eax, %eax
jne 0x1eb8fc
movl %r13d, %r12d
incl %r13d
cmpq %r12, (%rbx)
ja 0x1eb862
jmp 0x1eb8fc
movq (%rbx), %rcx
movl %ecx, %eax
subl %r15d, %eax
cmpq %rax, %rcx
movabsq $0x100000000, %rdi      # imm = 0x100000000
jbe 0x1eb8e3
movl %eax, %ecx
incl %ecx
movq 0x30(%r14), %rdx
movq 0x30(%rdx), %rdx
movq 0x10(%rbx), %rsi
movq (%rsi,%rax,8), %rsi
shrq %rsi
movb $0x1, (%rdx,%rsi)
movq 0x10(%rbx), %rdx
orq %rdi, (%rdx,%rax,8)
movl %ecx, %eax
incl %ecx
cmpq %rax, (%rbx)
ja 0x1eb8bb
movq 0x10(%rsp), %r15
movq (%r15), %rax
testq %rax, %rax
jne 0x1eb6bc
jmp 0x1ebaa1
xorl %r12d, %r12d
movl %r15d, %r10d
movq (%rbx), %rcx
xorl %eax, %eax
cmpq %r12, %rcx
setbe %dl
movq 0x10(%rsp), %r13
cmpq %r10, (%r13)
jbe 0x1eb954
movq %r10, %rsi
movq 0x30(%r14), %rdi
movq 0x30(%rdi), %rdi
movq 0x10(%r13), %r8
movq (%r8,%rsi,8), %r8
movb (%rdi,%r8), %r9b
testb %r9b, %r9b
jns 0x1eb939
andb $0x7f, %r9b
movb %r9b, (%rdi,%r8)
movq 0x10(%r13), %rdi
movq (%rdi,%rsi,8), %rsi
movl %r15d, %r8d
incl %r15d
movq %rsi, (%rdi,%r8,8)
movq %r15, %rsi
cmpq %r15, (%r13)
ja 0x1eb918
movb %dl, %al
movl %r15d, %edx
movq %rdx, (%r13)
cmpl $0x0, 0x20(%rsp)
je 0x1eb992
cmpq %r12, %rcx
movabsq $0x100000000, %r15      # imm = 0x100000000
ja 0x1eb99c
leaq (,%r10,8), %rsi
addq 0x10(%r13), %rsi
subq %r10, %rdx
movq %r14, %rdi
movq %r10, %r12
callq 0x1eb393
movq %r12, %r10
jmp 0x1eb99c
movabsq $0x100000000, %r15      # imm = 0x100000000
movq (%rbx), %rcx
testl %eax, %eax
jne 0x1ebae6
testq %rcx, %rcx
je 0x1eb9d8
movl $0x1, %eax
xorl %ecx, %ecx
movq 0x10(%rbx), %rdx
movq (%rdx,%rcx,8), %rcx
testq %r15, %rcx
jne 0x1eb9cf
movq 0x30(%r14), %rdx
movq 0x30(%rdx), %rdx
shrq %rcx
movb $0x1, (%rdx,%rcx)
movl %eax, %ecx
incl %eax
cmpq %rcx, (%rbx)
ja 0x1eb9b3
movq %r10, (%r13)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, 0x28(%rsp)
movq %r14, %rdi
leaq 0x28(%rsp), %rsi
movl %ebp, %edx
callq 0x1ea827
testq %rax, %rax
je 0x1eb8e3
movq %rax, %r13
cmpl $0x0, 0xc(%r13)
js 0x1eba81
movq 0x30(%r14), %rax
movq 0x30(%rax), %rcx
movl 0x8(%r13), %eax
shrl %eax
cmpb $0x0, (%rcx,%rax)
jne 0x1eba81
movq (%rsp), %rcx
cmpq %rax, (%rcx)
jbe 0x1eba81
movq (%rsp), %rcx
movq 0x8(%rcx), %rcx
cmpl $0x0, (%rcx,%rax,4)
js 0x1eba81
movq 0x10(%rsp), %r15
movq 0x8(%r15), %rax
cmpq %rax, (%r15)
jne 0x1eba6b
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r15)
movq 0x10(%r15), %rdi
shlq $0x3, %rsi
callq 0x2370
movq %rax, 0x10(%r15)
movl 0x8(%r13), %eax
movq (%r15), %rcx
movq 0x10(%r15), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r15)
movq %rax, (%rdx,%rcx,8)
movq %r14, %rdi
leaq 0x28(%rsp), %rsi
movl %ebp, %edx
callq 0x1ea827
movq %rax, %r13
testq %rax, %rax
jne 0x1eba06
jmp 0x1eb8e3
cmpq $0x0, (%rbx)
je 0x1ebad1
movl $0x1, %eax
xorl %r15d, %r15d
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 0x1ebab1
jmp 0x1ebad4
xorl %r15d, %r15d
movl %r15d, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rcx, %rcx
je 0x1ebc13
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
xorl %r15d, %r15d
movq %r10, 0x30(%rsp)
movq 0x10(%rbx), %rdx
movq (%rdx,%rax,8), %rsi
movl %esi, %r9d
shrl %r9d
movq 0x30(%r14), %rdi
movq 0x30(%rdi), %r8
testb $0x2, (%r8,%r9)
je 0x1ebbf9
movq %r15, (%rsp)
movq 0x20(%rdi), %r8
movq %r9, 0x18(%rsp)
orl $0x80000000, (%r8,%r9,8) # imm = 0x80000000
andl $-0x2, %esi
xorl %r8d, %r8d
leaq (%r8,%rsi), %r9
movq 0x28(%rdi), %r10
movq (%r10,%r9,8), %r11
movq %r11, %r10
andq %rcx, %r10
je 0x1ebbd3
shrq $0x20, %r11
leaq (%r11,%r11,2), %r11
shlq $0x3, %r11
addq 0x8(%rdi), %r11
xorl %r15d, %r15d
leaq (%r15,%r15,2), %r12
orb $-0x80, 0xf(%r11,%r12,8)
movl 0x8(%r11,%r12,8), %r12d
xorq $0x1, %r12
movq 0x28(%rdi), %r13
movq (%r13,%r12,8), %r12
movq %r12, %r13
andq %rcx, %r13
je 0x1ebbcb
movq 0x8(%rdi), %rdx
shrq $0x20, %r12
shlq $0x3, %r13
leaq (,%r13,2), %rbp
addq %r13, %rbp
leaq (%r12,%r12,2), %r12
leaq (%rdx,%r12,8), %r13
addq $0xc, %r13
xorl %r12d, %r12d
movl -0x4(%r13,%r12), %edx
xorl %r9d, %edx
cmpl $0x1, %edx
jne 0x1ebbc2
orb $-0x80, 0x3(%r13,%r12)
addq $0x18, %r12
cmpq %r12, %rbp
jne 0x1ebbaf
incq %r15
cmpq %r10, %r15
jne 0x1ebb65
leaq 0x1(%r8), %rdx
testq %r8, %r8
movq %rdx, %r8
je 0x1ebb3a
movq (%rsp), %r15
incl %r15d
movq 0x10(%rsp), %r13
movq 0x30(%rsp), %r10
movq 0x18(%rsp), %r9
movq 0x30(%r14), %rdx
movq 0x30(%rdx), %rdx
movb $0x0, (%rdx,%r9)
incl %eax
cmpq %rax, (%rbx)
ja 0x1ebafe
jmp 0x1ebc16
xorl %r15d, %r15d
leaq (,%r10,8), %rsi
addq 0x10(%r13), %rsi
movq (%r13), %rdx
subq %r10, %rdx
movq %r14, %rdi
movq %rbx, %rcx
movq %r10, %rbx
callq 0x1eaf45
movq %rbx, (%r13)
jmp 0x1ebad4