// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: dfs_subgraph_advance(asg_t*, buf_t*, unsigned int, unsigned int*)
uint64_t dfs_subgraph_advance(asg_t *g, buf_t *b, uint32_t x, uint32_t *p_bub)
{
    uint64_t len = 0;
    uint32_t c_v, e_v, nv, convex, v, i, kv_0, kv_1, flag_0 = 0, flag_1 = 0, op;
    asg_arc_t *av = NULL;
    long long nodeLen, baseLen, max_stop_nodeLen, max_stop_baseLen, uLen;
    (*p_bub) = 0;
    if(b->a[x>>1].s || g->seq[x>>1].del) return 0;
    b->S.n = 0;
    kv_push(uint32_t, b->S, x);

    while (b->S.n > 0)
    {
        b->S.n--;
        c_v = b->S.a[b->S.n];
        if(b->a[c_v>>1].s) continue;

        b->b.n = 0;
        op = get_unitig(g, NULL, c_v, &convex, &nodeLen, &baseLen, &max_stop_nodeLen, 
                                                                    &max_stop_baseLen, 1, b);
        uLen = baseLen;
        for(i = 0; i < b->b.n; i++)
        {
            ///if(b->a[b->b.a[i]>>1].s == 1) fprintf(stderr, "ERROR 3\n");
            b->a[b->b.a[i]>>1].s = 1;
        } 
        
        if(op == LOOP) return 0;


        e_v = convex^1;
        b->b.n = 0;
        op = get_unitig(g, NULL, e_v, &convex, &nodeLen, &baseLen, &max_stop_nodeLen, 
                                                                    &max_stop_baseLen, 1, b);
        uLen = MAX(uLen, baseLen);

        len += uLen;

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

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

        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 $0x58, %rsp
movq %rcx, %r15
movl %edx, %ebx
movl $0x0, (%rcx)
movq (%rsi), %rcx
movl %edx, %eax
shrl %eax
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rax, %rdx
cmpl $0x0, 0x18(%rcx,%rdx)
js 0xe6804
movq %rdi, %rbp
movq 0x20(%rdi), %rcx
cmpl $0x0, (%rcx,%rax,8)
js 0xe6804
movq %rsi, %r14
movq $0x0, 0x8(%rsi)
cmpq $0x0, 0x10(%rsi)
je 0xe67d7
movq 0x18(%r14), %rax
movl %ebx, (%rax)
movl $0x1, %ecx
jmp 0xe6819
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 %ebx, (%rax,%rdx,4)
jne 0xe6819
xorl %r15d, %r15d
movq %r15, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, 0x20(%rsp)
xorl %edi, %edi
xorl %r8d, %r8d
xorl %r15d, %r15d
movq %rbp, 0x18(%rsp)
movq %rcx, %rax
decq %rcx
movq %rcx, 0x8(%r14)
movq (%r14), %rdx
movq 0x18(%r14), %rsi
movl -0x4(%rsi,%rax,4), %r13d
movl %r13d, %eax
shrl %eax
leaq (%rax,%rax,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rax, %rsi
cmpl $0x0, 0x18(%rdx,%rsi)
js 0xe6ae8
movl %r8d, 0x10(%rsp)
movl %edi, 0x14(%rsp)
movq $0x0, 0x38(%r14)
movq %rbp, %rdi
xorl %esi, %esi
movl %r13d, %edx
leaq 0x4(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x8(%rsp), %r9
pushq %r14
pushq $0x1
leaq 0x50(%rsp), %rax
pushq %rax
leaq 0x60(%rsp), %rax
pushq %rax
callq 0x1053a7
addq $0x20, %rsp
movq 0x8(%rsp), %rbx
cmpq $0x0, 0x38(%r14)
je 0xe68d9
movl $0x1, %ecx
xorl %edx, %edx
movq (%r14), %rsi
movq 0x48(%r14), %rdi
movl (%rdi,%rdx,4), %edx
shrl %edx
leaq (%rdx,%rdx,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %rdx, %rdi
orl $0x80000000, 0x18(%rsi,%rdi) # imm = 0x80000000
movl %ecx, %edx
incl %ecx
cmpq %rdx, 0x38(%r14)
ja 0xe68b0
cmpl $0x7, %eax
je 0xe6804
movq %r15, 0x38(%rsp)
movl 0x4(%rsp), %r15d
movl %r15d, %edx
xorl $0x1, %edx
movq $0x0, 0x38(%r14)
xorl %r12d, %r12d
movq %rbp, %rdi
xorl %esi, %esi
leaq 0x4(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x8(%rsp), %r9
pushq %r14
pushq $0x1
leaq 0x50(%rsp), %rax
pushq %rax
leaq 0x60(%rsp), %rax
pushq %rax
callq 0x1053a7
addq $0x20, %rsp
movq 0x8(%rsp), %rax
cmpq %rax, %rbx
cmovgq %rbx, %rax
movq %rax, 0x30(%rsp)
xorq $0x1, %r13
movq 0x8(%rbp), %rax
movq 0x28(%rbp), %rcx
movq (%rcx,%r13,8), %rdx
testl %edx, %edx
je 0xe6a04
movq %r15, 0x28(%rsp)
movq %rdx, %rcx
shrq $0x20, %rcx
movl %edx, %edx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %r15
addq $0x8, %r15
shlq $0x3, %rdx
leaq (%rdx,%rdx,2), %rbp
xorl %ebx, %ebx
xorl %r13d, %r13d
cmpl $0x0, 0x4(%r15,%rbx)
js 0xe69e7
incl %r13d
movq (%r14), %rax
movl (%r15,%rbx), %ecx
movl %ecx, %edx
shrl %edx
leaq (%rdx,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdx, %rsi
cmpl $0x0, 0x18(%rax,%rsi)
js 0xe69e7
movq 0x8(%r14), %rdx
movq 0x18(%r14), %rax
cmpq 0x10(%r14), %rdx
jne 0xe69dc
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x18(%r14)
movl (%r15,%rbx), %ecx
movq 0x8(%r14), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%r14)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %rbx
cmpq %rbx, %rbp
jne 0xe697a
movq 0x18(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq 0x28(%rsp), %r15
jmp 0xe6a07
xorl %r13d, %r13d
movq (%rcx,%r15,8), %rcx
testl %ecx, %ecx
je 0xe6aaa
movq %rcx, %rdx
shrq $0x20, %rdx
movl %ecx, %ecx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rbp
addq $0x8, %rbp
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %r15
xorl %ebx, %ebx
xorl %r12d, %r12d
cmpl $0x0, 0x4(%rbp,%rbx)
js 0xe6aa1
incl %r12d
movq (%r14), %rax
movl (%rbp,%rbx), %ecx
movl %ecx, %edx
shrl %edx
leaq (%rdx,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdx, %rsi
cmpl $0x0, 0x18(%rax,%rsi)
js 0xe6aa1
movq 0x8(%r14), %rdx
movq 0x18(%r14), %rax
cmpq 0x10(%r14), %rdx
jne 0xe6a96
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x18(%r14)
movl (%rbp,%rbx), %ecx
movq 0x8(%r14), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%r14)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %rbx
cmpq %rbx, %r15
jne 0xe6a35
movq 0x38(%rsp), %r15
addq 0x30(%rsp), %r15
testl %r13d, %r13d
setne %al
testl %r12d, %r12d
setne %cl
andb %al, %cl
movzbl %cl, %eax
movl 0x10(%rsp), %r8d
addl %eax, %r8d
cmpl $0x2, %r13d
movl 0x14(%rsp), %edi
sbbl $-0x1, %edi
cmpl $0x2, %r12d
sbbl $-0x1, %edi
movq 0x8(%r14), %rcx
movq 0x18(%rsp), %rbp
testq %rcx, %rcx
jne 0xe682b
testl %r8d, %r8d
je 0xe6807
cmpl $0x2, %edi
jb 0xe6807
movq 0x20(%rsp), %rax
movl $0x1, (%rax)
jmp 0xe6807