// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/tovlp.cpp
// Function: dfs_set(asg_t*, unsigned int, unsigned int, kvec_t_u32_warp*, kvec_t_u32_warp*, unsigned char*, unsigned char)
uint32_t dfs_set(asg_t *g, uint32_t v0, uint32_t fbv, kvec_t_u32_warp *stack, kvec_t_u32_warp *tmp, uint8_t *vis, uint8_t flag)
{
    uint32_t cur, ncur, i, occ = 0;;
    asg_arc_t *acur = NULL;
    stack->a.n = 0;
    kv_push(uint32_t, stack->a, v0);
    // vis[v0] = 0;

    while (stack->a.n > 0)
    {
        stack->a.n--;
        cur = stack->a.a[stack->a.n];
        if(vis[cur] && (!(vis[cur]&flag)))
        {
            vis[cur] |= flag;
            kv_push(uint32_t, tmp->a, cur);
            occ++;
        }
        if(vis[cur]) continue;
        else kv_push(uint32_t, tmp->a, cur);

        vis[cur] |= flag;
        ncur = asg_arc_n(g, cur);
        acur = asg_arc_a(g, cur);
        for (i = 0; i < ncur; i++)
        {
            if(acur[i].del) continue;
            if((acur[i].v>>1) == fbv) continue;
            if(vis[acur[i].v] && (!(vis[acur[i].v]&flag)))
            {
                vis[acur[i].v] |= flag;
                kv_push(uint32_t, tmp->a, acur[i].v);
                occ++;
                continue;
            } 
            
            kv_push(uint32_t, stack->a, acur[i].v);
        }
    }

    return occ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %r9, %rbx
movq %r8, %r14
movq %rcx, %r15
movl %esi, %r12d
movq %rdi, 0x10(%rsp)
movq $0x0, (%rcx)
cmpq $0x0, 0x8(%rcx)
movl %edx, 0x4(%rsp)
jne 0x19044c
movq $0x2, 0x8(%r15)
movq 0x10(%r15), %rdi
movl $0x8, %esi
callq 0x2370
movl 0x4(%rsp), %edx
movq %rax, 0x10(%r15)
movq (%r15), %rcx
movq 0x10(%r15), %rsi
xorl %r8d, %r8d
movq %rcx, %rax
incq %rax
movq %rax, (%r15)
movl %r12d, (%rsi,%rcx,4)
je 0x19068d
movb 0x50(%rsp), %r9b
xorl %r8d, %r8d
movq %rbx, 0x8(%rsp)
leaq -0x1(%rax), %rcx
movq %rcx, (%r15)
movq 0x10(%r15), %rcx
movl -0x4(%rcx,%rax,4), %r12d
movb (%rbx,%r12), %al
testb %al, %al
sete %cl
testb %r9b, %al
setne %sil
orb %cl, %sil
jne 0x1904f4
orb %r9b, %al
movb %al, (%rbx,%r12)
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x1904df
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x2, %rsi
movq %r8, %r13
callq 0x2370
movb 0x50(%rsp), %r9b
movq %r13, %r8
movl 0x4(%rsp), %edx
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rsi
movq %rsi, (%r14)
movl %r12d, (%rcx,%rax,4)
incl %r8d
cmpb $0x0, (%rbx,%r12)
jne 0x190681
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x19053c
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x2, %rsi
movq %r8, %r13
callq 0x2370
movb 0x50(%rsp), %r9b
movq %r13, %r8
movl 0x4(%rsp), %edx
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rsi
movq %rsi, (%r14)
movl %r12d, (%rcx,%rax,4)
orb %r9b, (%rbx,%r12)
movq 0x10(%rsp), %rcx
movq 0x28(%rcx), %rax
movq (%rax,%r12,8), %rax
testl %eax, %eax
je 0x190681
movq 0x8(%rcx), %rcx
movq %rax, %rsi
shrq $0x20, %rsi
movl %eax, %eax
leaq (%rsi,%rsi,2), %rsi
leaq (%rcx,%rsi,8), %r12
addq $0x8, %r12
shlq $0x3, %rax
leaq (%rax,%rax,2), %r13
xorl %ebp, %ebp
cmpl $0x0, 0x4(%r12,%rbp)
js 0x190674
movl (%r12,%rbp), %eax
movl %eax, %ecx
shrl %ecx
cmpl %edx, %ecx
je 0x190674
movb (%rbx,%rax), %cl
testb %cl, %cl
sete %dil
testb %r9b, %cl
setne %sil
orb %dil, %sil
jne 0x19061d
orb %r9b, %cl
movb %cl, (%rbx,%rax)
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x190603
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq 0x10(%r14), %rdi
shlq $0x2, %rsi
movq %r8, %rbx
callq 0x2370
movb 0x50(%rsp), %r9b
movq %rbx, %r8
movq 0x8(%rsp), %rbx
movl 0x4(%rsp), %edx
movq %rax, 0x10(%r14)
movl (%r12,%rbp), %eax
movq (%r14), %rcx
movq 0x10(%r14), %rdi
leaq 0x1(%rcx), %rsi
movq %rsi, (%r14)
movl %eax, (%rdi,%rcx,4)
incl %r8d
jmp 0x190674
movq 0x8(%r15), %rax
cmpq %rax, (%r15)
jne 0x19065f
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r15)
movq 0x10(%r15), %rdi
shlq $0x2, %rsi
movq %r8, %rbx
callq 0x2370
movb 0x50(%rsp), %r9b
movq %rbx, %r8
movq 0x8(%rsp), %rbx
movl 0x4(%rsp), %edx
movq %rax, 0x10(%r15)
movl (%r12,%rbp), %eax
movq (%r15), %rcx
movq 0x10(%r15), %rdi
leaq 0x1(%rcx), %rsi
movq %rsi, (%r15)
movl %eax, (%rdi,%rcx,4)
addq $0x18, %rbp
cmpq %rbp, %r13
jne 0x19058a
movq (%r15), %rax
testq %rax, %rax
jne 0x190476
movl %r8d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq