// File: /workspace/github_cpp_makefile_star2_O2/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, %r12
movl %edx, %ebp
andl $0x0, (%rcx)
movq (%rsi), %rcx
movl %edx, %eax
shrl %eax
imulq $0x1c, %rax, %rdx
cmpl $0x0, 0x18(%rcx,%rdx)
js 0xa8ebe
movq %rdi, %r13
movq 0x20(%rdi), %rcx
cmpl $0x0, (%rcx,%rax,8)
js 0xa8ebe
movq %rsi, %r14
andq $0x0, 0x8(%rsi)
cmpq $0x0, 0x10(%rsi)
je 0xa8c19
movq 0x18(%r14), %rax
xorl %edx, %edx
jmp 0xa8c35
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 %r8d, %r8d
xorl %edi, %edi
decq %rcx
cmpq $-0x1, %rcx
je 0xa8ec2
movq %rcx, 0x8(%r14)
movq (%r14), %rsi
movq 0x18(%r14), %rdx
movl (%rdx,%rcx,4), %ebp
movl %ebp, %edx
shrl %edx
imulq $0x1c, %rdx, %rdx
decq %rcx
cmpl $0x0, 0x18(%rsi,%rdx)
js 0xa8c4a
movl %r8d, 0x10(%rsp)
movl %edi, 0x14(%rsp)
movq %rax, 0x38(%rsp)
andq $0x0, 0x38(%r14)
xorl %ebx, %ebx
movq %r13, %rdi
xorl %esi, %esi
movl %ebp, %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 0xc2ebf
addq $0x20, %rsp
movq 0x8(%rsp), %r15
movl %ebx, %ecx
cmpq %rcx, 0x38(%r14)
jbe 0xa8ce2
movq (%r14), %rdx
movq 0x48(%r14), %rsi
movl (%rsi,%rcx,4), %esi
shrl %esi
imulq $0x1c, %rsi, %rsi
orl $0x80000000, 0x18(%rdx,%rsi) # imm = 0x80000000
leal 0x1(%rcx), %ebx
jmp 0xa8cbd
cmpl $0x7, %eax
je 0xa8ebe
movq %r12, 0x30(%rsp)
movl 0x4(%rsp), %ecx
movq %rcx, 0x18(%rsp)
movl %ecx, %edx
xorl $0x1, %edx
andq $0x0, 0x38(%r14)
xorl %ebx, %ebx
movq %r13, %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 0xc2ebf
addq $0x20, %rsp
movq 0x8(%rsp), %rax
cmpq %rax, %r15
cmovgq %r15, %rax
movq %rax, 0x20(%rsp)
xorq $0x1, %rbp
movq 0x8(%r13), %rax
movq 0x28(%r13), %rcx
movq (%rcx,%rbp,8), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
imulq $0x18, %rdx, %r12
imulq $0x18, %rcx, %rcx
leaq (%rax,%rcx), %r15
addq $0x8, %r15
xorl %ebp, %ebp
cmpq %rbx, %r12
je 0xa8dd9
cmpl $0x0, 0x4(%r15,%rbx)
js 0xa8dd3
incl %ebp
movq (%r14), %rax
movl (%r15,%rbx), %ecx
movl %ecx, %edx
shrl %edx
imulq $0x1c, %rdx, %rdx
cmpl $0x0, 0x18(%rax,%rdx)
js 0xa8dd3
movq 0x8(%r14), %rdx
movq 0x18(%r14), %rax
cmpq 0x10(%r14), %rdx
jne 0xa8dc8
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
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
jmp 0xa8d6b
movq 0x8(%r13), %rax
movq %r13, 0x28(%rsp)
movq 0x28(%r13), %rcx
movq 0x18(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movl %ecx, %edx
shrq $0x20, %rcx
imulq $0x18, %rdx, %r12
imulq $0x18, %rcx, %rcx
leaq (%rax,%rcx), %r13
addq $0x8, %r13
xorl %r15d, %r15d
xorl %ebx, %ebx
cmpq %r15, %r12
je 0xa8e7a
cmpl $0x0, 0x4(%r13,%r15)
js 0xa8e74
incl %ebx
movq (%r14), %rax
movl (%r13,%r15), %ecx
movl %ecx, %edx
shrl %edx
imulq $0x1c, %rdx, %rdx
cmpl $0x0, 0x18(%rax,%rdx)
js 0xa8e74
movq 0x8(%r14), %rdx
movq 0x18(%r14), %rax
cmpq 0x10(%r14), %rdx
jne 0xa8e69
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x18(%r14)
movl (%r13,%r15), %ecx
movq 0x8(%r14), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%r14)
movl %ecx, (%rax,%rdx,4)
addq $0x18, %r15
jmp 0xa8e0a
movq 0x38(%rsp), %rax
addq 0x20(%rsp), %rax
testl %ebp, %ebp
setne %dl
testl %ebx, %ebx
setne %cl
andb %dl, %cl
movzbl %cl, %ecx
movl 0x10(%rsp), %r8d
addl %ecx, %r8d
cmpl $0x2, %ebp
movl 0x14(%rsp), %edi
sbbl $-0x1, %edi
cmpl $0x2, %ebx
sbbl $-0x1, %edi
movq 0x8(%r14), %rcx
movq 0x30(%rsp), %r12
movq 0x28(%rsp), %r13
jmp 0xa8c47
xorl %eax, %eax
jmp 0xa8ed4
testl %r8d, %r8d
je 0xa8ed4
cmpl $0x2, %edi
jb 0xa8ed4
movl $0x1, (%r12)
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq