// File: /workspace/github_cpp_makefile_star2_O3/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
movl %edx, %ebp
movq %rdi, 0x10(%rsp)
movq %rcx, 0x18(%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 0xe647c
movq %rsi, %r14
movq $0x0, 0x8(%rsi)
cmpq $0x0, 0x10(%rsi)
je 0xe644f
movq 0x18(%r14), %rax
movl %ebp, (%rax)
movl $0x1, %ecx
jmp 0xe6484
movq $0x2, 0x10(%r14)
movq 0x18(%r14), %rdi
movl $0x8, %esi
callq 0x2370
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rdx
movq %rdx, %rcx
incq %rcx
movq %rcx, 0x8(%r14)
movl %ebp, (%rax,%rdx,4)
jne 0xe6484
xorl %r8d, %r8d
jmp 0xe66c0
xorl %r9d, %r9d
xorl %r10d, %r10d
xorl %r8d, %r8d
movq %rcx, %rdx
decq %rcx
movq %rcx, 0x8(%r14)
movq (%r14), %rax
movq 0x18(%r14), %rsi
movl -0x4(%rsi,%rdx,4), %edx
leaq (%rdx,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %rdi
addq %rdx, %rdi
movl 0x18(%rax,%rdi), %esi
testl %esi, %esi
js 0xe66a1
movl %r10d, 0xc(%rsp)
movq %r9, 0x28(%rsp)
movq %r8, 0x30(%rsp)
addq %rdi, %rax
addq $0x18, %rax
orl $0x80000000, %esi       # imm = 0x80000000
movl %esi, (%rax)
movq 0x10(%rsp), %rsi
movq 0x8(%rsi), %rax
movq 0x20(%rsi), %rcx
movl (%rcx,%rdx,8), %ecx
movq %rcx, 0x20(%rsp)
leal (%rdx,%rdx), %edi
movq 0x28(%rsi), %rcx
movq (%rcx,%rdi,8), %rdx
xorl %esi, %esi
testl %edx, %edx
je 0xe65ad
movq %rdi, (%rsp)
movq %rdx, %rcx
shrq $0x20, %rcx
movl %edx, %edx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %r13
addq $0xc, %r13
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %r12
xorl %ebp, %ebp
xorl %r15d, %r15d
cmpl $0x0, (%r13,%rbp)
js 0xe6591
movl -0x4(%r13,%rbp), %ebx
shrl %ebx
incl %r15d
movq (%r14), %rax
leaq (%rbx,%rbx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rbx, %rcx
cmpl $0x0, 0x18(%rax,%rcx)
js 0xe6591
movq 0x8(%r14), %rcx
movq 0x18(%r14), %rax
cmpq 0x10(%r14), %rcx
jne 0xe6586
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
xorl %esi, %esi
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
movl %ebx, (%rax,%rcx,4)
addq $0x18, %rbp
cmpq %rbp, %r12
jne 0xe6527
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq (%rsp), %rdi
jmp 0xe65b0
xorl %r15d, %r15d
movl %edi, %edx
movq 0x8(%rcx,%rdx,8), %rcx
testl %ecx, %ecx
je 0xe665f
movq %rcx, %rdx
shrq $0x20, %rdx
movl %ecx, %ecx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rbp
addq $0xc, %rbp
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r13
xorl %r12d, %r12d
xorl %esi, %esi
movl %r15d, (%rsp)
cmpl $0x0, (%rbp,%r12)
js 0xe6656
movl -0x4(%rbp,%r12), %ebx
shrl %ebx
incl %esi
movq (%r14), %rax
leaq (%rbx,%rbx,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %rbx, %rcx
cmpl $0x0, 0x18(%rax,%rcx)
js 0xe6656
movq 0x8(%r14), %rcx
movq 0x18(%r14), %rax
cmpq 0x10(%r14), %rcx
jne 0xe664b
movl %esi, %r15d
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movl %r15d, %esi
movl (%rsp), %r15d
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
movl %ebx, (%rax,%rcx,4)
addq $0x18, %r12
cmpq %r12, %r13
jne 0xe65e5
movq 0x20(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq 0x30(%rsp), %r8
addq %rax, %r8
testl %r15d, %r15d
setne %al
testl %esi, %esi
setne %cl
andb %al, %cl
movzbl %cl, %eax
movl 0xc(%rsp), %r10d
addl %eax, %r10d
cmpl $0x2, %r15d
movq 0x28(%rsp), %r9
sbbl $-0x1, %r9d
cmpl $0x2, %esi
sbbl $-0x1, %r9d
movq 0x8(%r14), %rcx
testq %rcx, %rcx
jne 0xe648d
testl %r10d, %r10d
je 0xe66c0
cmpl $0x2, %r9d
jb 0xe66c0
movq 0x18(%rsp), %rax
movl $0x1, (%rax)
movq %r8, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq