// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
movl %edx, %ebp
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 0xe53bc
movq %rdi, %r12
movq 0x20(%rdi), %rcx
cmpl $0x0, (%rcx,%rax,8)
js 0xe53bc
movq %rsi, %r14
movq $0x0, 0x8(%rsi)
cmpq $0x0, 0x10(%rsi)
jne 0xe50cd
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 %r13d, %r13d
xorl %r8d, %r8d
xorl %edi, %edi
movq 0x8(%r14), %rax
decq %rax
cmpq $-0x1, %rax
je 0xe53c1
movq %rax, 0x8(%r14)
movq (%r14), %rcx
movq 0x18(%r14), %rdx
movl (%rdx,%rax,4), %ebp
movl %ebp, %edx
shrl %edx
leaq (%rdx,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdx, %rsi
decq %rax
cmpl $0x0, 0x18(%rcx,%rsi)
js 0xe50ef
movl %r8d, 0x18(%rsp)
movl %edi, 0x1c(%rsp)
movq $0x0, 0x38(%r14)
movq %r12, %rdi
xorl %esi, %esi
movl %ebp, %edx
leaq 0x4(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x10(%rsp), %r9
pushq %r14
pushq $0x1
leaq 0x50(%rsp), %rax
pushq %rax
leaq 0x60(%rsp), %rax
pushq %rax
callq 0x10109f
addq $0x20, %rsp
movq 0x10(%rsp), %r15
cmpq $0x0, 0x38(%r14)
je 0xe519c
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 0xe5173
cmpl $0x7, %eax
je 0xe53bc
movq %r13, 0x30(%rsp)
movq %rbx, 0x38(%rsp)
movl 0x4(%rsp), %ecx
movq %rcx, 0x20(%rsp)
movl %ecx, %edx
xorl $0x1, %edx
movq $0x0, 0x38(%r14)
xorl %ebx, %ebx
movq %r12, %rdi
xorl %esi, %esi
leaq 0x4(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x10(%rsp), %r9
pushq %r14
pushq $0x1
leaq 0x50(%rsp), %rax
pushq %rax
leaq 0x60(%rsp), %rax
pushq %rax
callq 0x10109f
addq $0x20, %rsp
movq 0x10(%rsp), %rax
cmpq %rax, %r15
cmovgq %r15, %rax
movq %rax, 0x28(%rsp)
xorq $0x1, %rbp
movq %r12, 0x8(%rsp)
movq 0x28(%r12), %rax
movq (%rax,%rbp,8), %rax
movl $0x0, %ebp
testl %eax, %eax
je 0xe52c3
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r12
addq $0x8, %r12
shlq $0x3, %rax
leaq (%rax,%rax,2), %r13
xorl %r15d, %r15d
xorl %ebp, %ebp
cmpl $0x0, 0x4(%r12,%r15)
js 0xe52ba
incl %ebp
movq (%r14), %rax
movl (%r12,%r15), %ecx
shrl %ecx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
cmpl $0x0, 0x18(%rax,%rdx)
js 0xe52ba
movq 0x10(%r14), %rax
cmpq %rax, 0x8(%r14)
jne 0xe52a3
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
movq %rax, 0x18(%r14)
movl (%r12,%r15), %eax
movq 0x8(%r14), %rcx
movq 0x18(%r14), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%r14)
movl %eax, (%rdx,%rcx,4)
addq $0x18, %r15
cmpq %r15, %r13
jne 0xe524f
movq 0x8(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x20(%rsp), %rcx
movq (%rax,%rcx,8), %rax
testl %eax, %eax
je 0xe537c
movq 0x8(%rsp), %rcx
movq 0x8(%rcx), %rcx
movq %rax, %rdx
shrq $0x20, %rdx
movl %eax, %eax
leaq (%rdx,%rdx,2), %rdx
leaq (%rcx,%rdx,8), %r12
addq $0x8, %r12
shlq $0x3, %rax
leaq (%rax,%rax,2), %r13
xorl %r15d, %r15d
xorl %ebx, %ebx
cmpl $0x0, 0x4(%r12,%r15)
js 0xe5373
incl %ebx
movq (%r14), %rax
movl (%r12,%r15), %ecx
shrl %ecx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
cmpl $0x0, 0x18(%rax,%rdx)
js 0xe5373
movq 0x10(%r14), %rax
cmpq %rax, 0x8(%r14)
jne 0xe535c
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
movq %rax, 0x18(%r14)
movl (%r12,%r15), %eax
movq 0x8(%r14), %rcx
movq 0x18(%r14), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%r14)
movl %eax, (%rdx,%rcx,4)
addq $0x18, %r15
cmpq %r15, %r13
jne 0xe5308
movq 0x30(%rsp), %r13
addq 0x28(%rsp), %r13
testl %ebp, %ebp
setne %al
testl %ebx, %ebx
setne %cl
andb %al, %cl
movzbl %cl, %eax
movl 0x18(%rsp), %r8d
addl %eax, %r8d
cmpl $0x2, %ebp
movl 0x1c(%rsp), %edi
sbbl $-0x1, %edi
cmpl $0x2, %ebx
sbbl $-0x1, %edi
movq 0x38(%rsp), %rbx
movq 0x8(%rsp), %r12
jmp 0xe50e8
xorl %r13d, %r13d
jmp 0xe53d1
testl %r8d, %r8d
je 0xe53d1
cmpl $0x2, %edi
jb 0xe53d1
movl $0x1, (%rbx)
movq %r13, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq