// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rdi, 0x10(%rsp)
andl $0x0, (%rcx)
movq (%rsi), %rax
movl %edx, %ecx
imulq $0x1c, %rcx, %rcx
cmpl $0x0, 0x18(%rax,%rcx)
js 0xa88f2
movl %edx, %ebp
movq %rsi, %r14
andq $0x0, 0x8(%rsi)
cmpq $0x0, 0x10(%rsi)
je 0xa88f9
movq 0x18(%r14), %rax
xorl %edx, %edx
jmp 0xa8915
xorl %eax, %eax
jmp 0xa8b24
movq $0x2, 0x10(%r14)
movq 0x18(%r14), %rdi
pushq $0x8
popq %rsi
callq 0x2370
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rdx
leaq 0x1(%rdx), %rcx
movq %rcx, 0x8(%r14)
movl %ebp, (%rax,%rdx,4)
xorl %eax, %eax
xorl %r10d, %r10d
xorl %r9d, %r9d
decq %rcx
cmpq $-0x1, %rcx
je 0xa8b13
movq %rcx, 0x8(%r14)
movq (%r14), %rdx
movq 0x18(%r14), %rsi
movl (%rsi,%rcx,4), %r8d
imulq $0x1c, %r8, %rdi
movl 0x18(%rdx,%rdi), %esi
decq %rcx
testl %esi, %esi
js 0xa892b
movl %r10d, 0x4(%rsp)
movl %r9d, 0x8(%rsp)
movq %rax, 0x28(%rsp)
movq %rbx, 0x30(%rsp)
leaq (%rdx,%rdi), %rcx
addq $0x18, %rcx
orl $0x80000000, %esi       # imm = 0x80000000
movl %esi, (%rcx)
movq 0x10(%rsp), %rsi
movq 0x8(%rsi), %rcx
movq 0x20(%rsi), %rdx
movl (%rdx,%r8,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x20(%rsp)
leal (%r8,%r8), %edx
movq 0x28(%rsi), %rax
movq %rdx, 0x18(%rsp)
movq (%rax,%rdx,8), %rax
movl %eax, %edx
shrq $0x20, %rax
imulq $0x18, %rdx, %r15
imulq $0x18, %rax, %rax
leaq (%rcx,%rax), %rbp
addq $0xc, %rbp
xorl %r13d, %r13d
xorl %esi, %esi
cmpq %r13, %r15
je 0xa8a2d
cmpl $0x0, (%rbp,%r13)
js 0xa8a27
movl -0x4(%rbp,%r13), %ebx
shrl %ebx
incl %esi
movq (%r14), %rax
imulq $0x1c, %rbx, %rcx
cmpl $0x0, 0x18(%rax,%rcx)
js 0xa8a27
movq 0x8(%r14), %rcx
movq 0x18(%r14), %rax
cmpq 0x10(%r14), %rcx
jne 0xa8a1c
movl %esi, %r12d
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movl %r12d, %esi
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
movl %ebx, (%rax,%rcx,4)
addq $0x18, %r13
jmp 0xa89be
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movl 0x18(%rsp), %edx
movq 0x8(%rcx,%rdx,8), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
imulq $0x18, %rdx, %r15
imulq $0x18, %rcx, %rcx
leaq (%rax,%rcx), %rbp
addq $0xc, %rbp
xorl %r13d, %r13d
xorl %ebx, %ebx
movl %esi, 0xc(%rsp)
cmpq %r13, %r15
je 0xa8ad1
cmpl $0x0, (%rbp,%r13)
js 0xa8acb
movl -0x4(%rbp,%r13), %r12d
shrl %r12d
incl %ebx
movq (%r14), %rax
imulq $0x1c, %r12, %rcx
cmpl $0x0, 0x18(%rax,%rcx)
js 0xa8acb
movq 0x8(%r14), %rcx
movq 0x18(%r14), %rax
cmpq 0x10(%r14), %rcx
jne 0xa8abf
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movl 0xc(%rsp), %esi
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
movl %r12d, (%rax,%rcx,4)
addq $0x18, %r13
jmp 0xa8a62
movq 0x28(%rsp), %rax
addq 0x20(%rsp), %rax
testl %esi, %esi
setne %dl
testl %ebx, %ebx
setne %cl
andb %dl, %cl
movzbl %cl, %ecx
movl 0x4(%rsp), %r10d
addl %ecx, %r10d
cmpl $0x2, %esi
movl 0x8(%rsp), %r9d
sbbl $-0x1, %r9d
cmpl $0x2, %ebx
sbbl $-0x1, %r9d
movq 0x8(%r14), %rcx
movq 0x30(%rsp), %rbx
jmp 0xa8928
testl %r10d, %r10d
je 0xa8b24
cmpl $0x2, %r9d
jb 0xa8b24
movl $0x1, (%rbx)
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq