// File: /workspace/github_cpp_makefile_star2_O2/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
andq $0x0, (%rcx)
movl %esi, %r13d
movq %rdi, 0x10(%rsp)
cmpq $0x0, 0x8(%rcx)
movl %edx, 0x4(%rsp)
je 0x151d35
movq 0x10(%r15), %rax
xorl %esi, %esi
jmp 0x151d54
movq $0x2, 0x8(%r15)
movq 0x10(%r15), %rdi
pushq $0x8
popq %rsi
callq 0x2370
movl 0x4(%rsp), %edx
movq %rax, 0x10(%r15)
movq (%r15), %rsi
movb 0x50(%rsp), %r8b
leaq 0x1(%rsi), %rcx
movq %rcx, (%r15)
movl %r13d, (%rax,%rsi,4)
xorl %r13d, %r13d
testq %rcx, %rcx
je 0x151f62
leaq -0x1(%rcx), %rax
movq %rax, (%r15)
movq 0x10(%r15), %rax
movl -0x4(%rax,%rcx,4), %r12d
movb (%rbx,%r12), %al
testb %al, %al
sete %cl
testb %r8b, %al
setne %sil
orb %cl, %sil
jne 0x151de9
orb %r8b, %al
movb %al, (%rbx,%r12)
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x151dd7
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movb 0x50(%rsp), %r8b
movl 0x4(%rsp), %edx
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r14)
movl %r12d, (%rax,%rcx,4)
incl %r13d
movb (%rbx,%r12), %al
testb %al, %al
jne 0x151f5a
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
movq %r13, 0x8(%rsp)
jne 0x151e31
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movb 0x50(%rsp), %r8b
movl 0x4(%rsp), %edx
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rsi
movq %rsi, (%r14)
movl %r12d, (%rax,%rcx,4)
orb %r8b, (%rbx,%r12)
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq (%rcx,%r12,8), %rcx
movl %ecx, %esi
shrq $0x20, %rcx
imulq $0x18, %rsi, %r12
imulq $0x18, %rcx, %rcx
leaq (%rax,%rcx), %r13
addq $0x8, %r13
xorl %ebp, %ebp
cmpq %rbp, %r12
je 0x151f55
cmpl $0x0, 0x4(%r13,%rbp)
js 0x151f4c
movl (%r13,%rbp), %ecx
movl %ecx, %eax
shrl %eax
cmpl %edx, %eax
je 0x151f4c
movb (%rbx,%rcx), %al
testb %al, %al
sete %dil
testb %r8b, %al
setne %sil
orb %dil, %sil
jne 0x151f02
orb %r8b, %al
movb %al, (%rbx,%rcx)
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x151ee5
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movb 0x50(%rsp), %r8b
movl 0x4(%rsp), %edx
movq %rax, 0x10(%r14)
movq (%r14), %rcx
movl (%r13,%rbp), %edi
leaq 0x1(%rcx), %rsi
movq %rsi, (%r14)
movl %edi, (%rax,%rcx,4)
movq 0x8(%rsp), %rax
incl %eax
movq %rax, 0x8(%rsp)
jmp 0x151f4c
movq (%r15), %rdi
movq 0x10(%r15), %rax
cmpq 0x8(%r15), %rdi
jne 0x151f42
leaq (%rdi,%rdi), %rsi
testq %rdi, %rdi
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movb 0x50(%rsp), %r8b
movl 0x4(%rsp), %edx
movq %rax, 0x10(%r15)
movl (%r13,%rbp), %ecx
movq (%r15), %rdi
leaq 0x1(%rdi), %rsi
movq %rsi, (%r15)
movl %ecx, (%rax,%rdi,4)
addq $0x18, %rbp
jmp 0x151e69
movq 0x8(%rsp), %r13
movq (%r15), %rcx
jmp 0x151d67
movl %r13d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq