// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: dfs_subgraph(asg_t*, buf_t*, unsigned int, unsigned int*)
uint64_t dfs_subgraph(asg_t *g, buf_t *b, uint32_t id, uint32_t *p_bub)
{
    uint64_t len = 0;
    uint32_t cur, nv, v, w, i, kv_0, kv_1, flag_0 = 0, flag_1 = 0;
    asg_arc_t *av = NULL;
    (*p_bub) = 0;
    if(b->a[id].s) return 0;
    b->S.n = 0;
    kv_push(uint32_t, b->S, id);

    while (b->S.n > 0)
    {
        b->S.n--;
        cur = b->S.a[b->S.n];
        if(b->a[cur].s) continue;
        b->a[cur].s = 1;
        len += g->seq[cur].len;
        
        v = cur<<1;
        nv = asg_arc_n(g, v);
        av = asg_arc_a(g, v);
        for (i = kv_0 = 0; i < nv; i++)
        {
            w = av[i].v>>1;
            if(av[i].del) continue;
            kv_0++;
            if(b->a[w].s) continue;
            kv_push(uint32_t, b->S, w);
        }

        v = (cur<<1)+1;
        nv = asg_arc_n(g, v);
        av = asg_arc_a(g, v);
        for (i = kv_1 = 0; i < nv; i++)
        {
            w = av[i].v>>1;
            if(av[i].del) continue;
            kv_1++;
            if(b->a[w].s) continue;
            kv_push(uint32_t, b->S, w);
        }

        if(kv_0 > 0 && kv_1 > 0) flag_0++;
        if(kv_0 > 1) flag_1++;
        if(kv_1 > 1) flag_1++;
    }

    if(flag_0 > 0 && flag_1 > 1) (*p_bub) = 1;
    return len;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rcx, %rbx
movl %edx, %ebp
movq %rdi, (%rsp)
movl $0x0, (%rcx)
movq (%rsi), %rax
movl %edx, %ecx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
cmpl $0x0, 0x18(%rax,%rdx)
js 0xe4fa2
movq %rsi, %r14
movq $0x0, 0x8(%rsi)
cmpq $0x0, 0x10(%rsi)
jne 0xe4d2e
movq $0x2, 0x10(%r14)
movq 0x18(%r14), %rdi
movl $0x8, %esi
callq 0x2370
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rax
movq 0x18(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%r14)
movl %ebp, (%rcx,%rax,4)
xorl %eax, %eax
xorl %r10d, %r10d
xorl %r9d, %r9d
movq 0x8(%r14), %r8
decq %r8
cmpq $-0x1, %r8
je 0xe4f8f
movq %r8, 0x8(%r14)
movq (%r14), %rdx
movq 0x18(%r14), %rcx
movl (%rcx,%r8,4), %ecx
leaq (%rcx,%rcx,8), %rsi
leaq (%rsi,%rsi,2), %rdi
addq %rcx, %rdi
movl 0x18(%rdx,%rdi), %esi
decq %r8
testl %esi, %esi
js 0xe4d50
movl %r10d, 0xc(%rsp)
movl %r9d, 0x10(%rsp)
movq %rax, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
leaq (%rdx,%rdi), %rax
addq $0x18, %rax
orl $0x80000000, %esi       # imm = 0x80000000
movl %esi, (%rax)
movq (%rsp), %rdx
movq 0x20(%rdx), %rax
movl (%rax,%rcx,8), %eax
movq %rax, 0x20(%rsp)
addl %ecx, %ecx
movq 0x28(%rdx), %rax
movq %rcx, 0x18(%rsp)
movq (%rax,%rcx,8), %rax
xorl %esi, %esi
movl $0x0, %r12d
testl %eax, %eax
je 0xe4e78
movq (%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r15
addq $0xc, %r15
shlq $0x3, %rax
leaq (%rax,%rax,2), %rbp
xorl %ebx, %ebx
xorl %r12d, %r12d
cmpl $0x0, (%r15,%rbx)
js 0xe4e6f
movl -0x4(%r15,%rbx), %r13d
shrl %r13d
incl %r12d
movq (%r14), %rax
leaq (,%r13,8), %rcx
addq %r13, %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r13, %rcx
cmpl $0x0, 0x18(%rax,%rcx)
js 0xe4e6f
movq 0x10(%r14), %rax
cmpq %rax, 0x8(%r14)
jne 0xe4e5b
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x10(%r14)
movq 0x18(%r14), %rdi
shlq $0x2, %rsi
callq 0x2370
xorl %esi, %esi
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rax
movq 0x18(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%r14)
movl %r13d, (%rcx,%rax,4)
addq $0x18, %rbx
cmpq %rbx, %rbp
jne 0xe4dfc
movq (%rsp), %rax
movq 0x28(%rax), %rax
movl 0x18(%rsp), %ecx
movq 0x8(%rax,%rcx,8), %rax
testl %eax, %eax
je 0xe4f46
movq (%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %rbx
addq $0xc, %rbx
shlq $0x3, %rax
leaq (%rax,%rax,2), %r15
xorl %ebp, %ebp
xorl %esi, %esi
movl %r12d, 0x14(%rsp)
cmpl $0x0, (%rbx,%rbp)
js 0xe4f39
movl -0x4(%rbx,%rbp), %r13d
shrl %r13d
incl %esi
movq (%r14), %rax
leaq (,%r13,8), %rcx
addq %r13, %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r13, %rcx
cmpl $0x0, 0x18(%rax,%rcx)
js 0xe4f39
movq 0x10(%r14), %rax
cmpq %rax, 0x8(%r14)
jne 0xe4f25
movl %esi, %r12d
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x10(%r14)
movq 0x18(%r14), %rdi
shlq $0x2, %rsi
callq 0x2370
movl %r12d, %esi
movl 0x14(%rsp), %r12d
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rax
movq 0x18(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%r14)
movl %r13d, (%rcx,%rax,4)
addq $0x18, %rbp
cmpq %rbp, %r15
jne 0xe4ebf
movq 0x20(%rsp), %rcx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq 0x28(%rsp), %rax
addq %rcx, %rax
testl %r12d, %r12d
setne %dl
testl %esi, %esi
setne %cl
andb %dl, %cl
movzbl %cl, %ecx
movl 0xc(%rsp), %r10d
addl %ecx, %r10d
cmpl $0x2, %r12d
movl 0x10(%rsp), %r9d
sbbl $-0x1, %r9d
cmpl $0x2, %esi
sbbl $-0x1, %r9d
movq 0x30(%rsp), %rbx
jmp 0xe4d49
testl %r10d, %r10d
je 0xe4fa4
cmpl $0x2, %r9d
jb 0xe4fa4
movl $0x1, (%rbx)
jmp 0xe4fa4
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq