// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: dfs_max_bub(usg_t*, buf_t*, unsigned int, asg64_v*, unsigned int*)
uint64_t dfs_max_bub(usg_t *g, buf_t *b, uint32_t x, asg64_v *nb, uint32_t *p_bub)
{
    uint64_t len = 0, baseLen, uLen; uint32_t c_v, e_v, nv, convex, v, i, kv_0, kv_1, flag_0 = 0, flag_1 = 0, op;
    usg_arc_t *av = NULL; (*p_bub) = 0; b->S.n = 0;
    if(b->a[x>>1].s || g->a[x>>1].del) return 0;
    kv_push(uint32_t, b->S, x);
    // fprintf(stderr, "\n[M::%s::] g->n::%u, x::%u\n", __func__, (uint32_t)g->n, x);
    while (b->S.n > 0) {
        c_v = b->S.a[--b->S.n];
        // fprintf(stderr, "[M::%s::] b->S.n::%u, c_v::%u\n", __func__, (uint32_t)b->S.n, c_v);
        // if(c_v >= g->n) {
        //     fprintf(stderr, "+++++[M::%s::] g->n::%u, c_v::%u\n", __func__, (uint32_t)g->n, c_v);
        // }
        if(b->a[c_v>>1].s) continue;

        nb->n = 0; op = get_usg_unitig(g, c_v, &convex, NULL, &baseLen, NULL, nb);
        uLen = baseLen;
        for(i = 0; i < nb->n; i++) b->a[nb->a[i]>>1].s = 1;
        if(op == LOOP) return 0;

        e_v = convex^1;
        nb->n = 0; op = get_usg_unitig(g, e_v, &convex, NULL, &baseLen, NULL, nb);

        uLen = MAX(uLen, baseLen); len += uLen;


        v = c_v^1; nv = usg_arc_n(g, v); av = usg_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 = usg_arc_n(g, v); av = usg_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
andl $0x0, (%r8)
andq $0x0, 0x8(%rsi)
movl %edx, %ebp
movq (%rsi), %rcx
movl %edx, %eax
shrl %eax
imulq $0x1c, %rax, %rdx
cmpl $0x0, 0x18(%rcx,%rdx)
js 0x1c79c0
movq %rdi, %r14
movq (%rdi), %rcx
imulq $0x78, %rax, %rax
cmpb $0x0, 0x70(%rcx,%rax)
je 0x1c79d4
xorl %esi, %esi
movq %rsi, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r8, %rbx
movq %rsi, %r15
cmpq $0x0, 0x10(%rsi)
je 0x1c79e9
movq 0x18(%r15), %rax
xorl %edx, %edx
jmp 0x1c7a05
movq $0x2, 0x10(%r15)
movq 0x18(%r15), %rdi
pushq $0x8
popq %rsi
callq 0x2370
movq %rax, 0x18(%r15)
movq 0x8(%r15), %rdx
movq %rbx, 0x30(%rsp)
leaq 0x1(%rdx), %rcx
movq %rcx, 0x8(%r15)
movl %ebp, (%rax,%rdx,4)
xorl %esi, %esi
xorl %r8d, %r8d
xorl %edi, %edi
decq %rcx
cmpq $-0x1, %rcx
je 0x1c7c78
movq (%r15), %rax
movq 0x18(%r15), %rdx
movq %rcx, 0x8(%r15)
movl (%rdx,%rcx,4), %r13d
movl %r13d, %ebp
shrl %ebp
imulq $0x1c, %rbp, %rdx
decq %rcx
cmpl $0x0, 0x18(%rax,%rdx)
js 0x1c7a1f
movl %r8d, 0x20(%rsp)
movl %edi, 0x24(%rsp)
movq %rsi, 0x50(%rsp)
andq $0x0, (%r12)
movq %r12, (%rsp)
movq %r14, %rdi
xorl %r14d, %r14d
movq %rdi, 0x28(%rsp)
movl %r13d, %esi
leaq 0x14(%rsp), %rdx
xorl %ecx, %ecx
leaq 0x18(%rsp), %r8
xorl %r9d, %r9d
callq 0x1dee72
movq 0x18(%rsp), %rbx
movl %r14d, %ecx
cmpq %rcx, (%r12)
jbe 0x1c7ab3
movq (%r15), %rdx
movq 0x10(%r12), %rsi
movq (%rsi,%rcx,8), %rsi
shrq %rsi
imulq $0x1c, %rsi, %rsi
orl $0x80000000, 0x18(%rdx,%rsi) # imm = 0x80000000
leal 0x1(%rcx), %r14d
jmp 0x1c7a89
cmpl $0x7, %eax
je 0x1c79c0
movl 0x14(%rsp), %eax
movq %rax, 0x38(%rsp)
movl %eax, %esi
xorl $0x1, %esi
andq $0x0, (%r12)
movq %r12, 0x48(%rsp)
movq %r12, (%rsp)
xorl %r12d, %r12d
movq 0x28(%rsp), %r14
movq %r14, %rdi
leaq 0x14(%rsp), %rdx
xorl %ecx, %ecx
leaq 0x18(%rsp), %r8
xorl %r9d, %r9d
callq 0x1dee72
movq 0x18(%rsp), %rax
cmpq %rax, %rbx
cmovaq %rbx, %rax
movq %rax, 0x40(%rsp)
notl %r13d
andl $0x1, %r13d
imulq $0x78, %rbp, %rax
addq (%r14), %rax
imulq $0x18, %r13, %rcx
movl 0x10(%rcx,%rax), %r13d
movq 0x20(%rcx,%rax), %rbx
shlq $0x5, %r13
xorl %ebp, %ebp
cmpq %r12, %r13
je 0x1c7b9a
cmpl $0x0, 0xc(%rbx,%r12)
js 0x1c7b94
incl %ebp
movq (%r15), %rax
movl 0x8(%rbx,%r12), %ecx
movl %ecx, %edx
shrl %edx
imulq $0x1c, %rdx, %rdx
cmpl $0x0, 0x18(%rax,%rdx)
js 0x1c7b94
movq 0x8(%r15), %rdx
movq 0x18(%r15), %rax
cmpq 0x10(%r15), %rdx
jne 0x1c7b89
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x18(%r15)
movl 0x8(%rbx,%r12), %ecx
movq 0x8(%r15), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%r15)
movl %ecx, (%rax,%rdx,4)
addq $0x20, %r12
jmp 0x1c7b2a
movq 0x38(%rsp), %rcx
movl %ecx, %eax
shrl %eax
andl $0x1, %ecx
imulq $0x78, %rax, %rax
addq (%r14), %rax
imulq $0x18, %rcx, %rcx
movl 0x10(%rcx,%rax), %r12d
movq 0x20(%rcx,%rax), %r13
shlq $0x5, %r12
xorl %r14d, %r14d
xorl %ebx, %ebx
cmpq %r14, %r12
je 0x1c7c34
cmpl $0x0, 0xc(%r13,%r14)
js 0x1c7c2e
incl %ebx
movq (%r15), %rax
movl 0x8(%r13,%r14), %ecx
movl %ecx, %edx
shrl %edx
imulq $0x1c, %rdx, %rdx
cmpl $0x0, 0x18(%rax,%rdx)
js 0x1c7c2e
movq 0x8(%r15), %rdx
movq 0x18(%r15), %rax
cmpq 0x10(%r15), %rdx
jne 0x1c7c23
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x18(%r15)
movl 0x8(%r13,%r14), %ecx
movq 0x8(%r15), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%r15)
movl %ecx, (%rax,%rdx,4)
addq $0x20, %r14
jmp 0x1c7bc4
movq 0x50(%rsp), %rsi
addq 0x40(%rsp), %rsi
testl %ebp, %ebp
setne %al
testl %ebx, %ebx
setne %cl
andb %al, %cl
movzbl %cl, %eax
movl 0x20(%rsp), %r8d
addl %eax, %r8d
cmpl $0x2, %ebp
movl 0x24(%rsp), %edi
sbbl $-0x1, %edi
cmpl $0x2, %ebx
sbbl $-0x1, %edi
movq 0x8(%r15), %rcx
movq 0x48(%rsp), %r12
movq 0x28(%rsp), %r14
jmp 0x1c7a1c
testl %r8d, %r8d
je 0x1c79c2
cmpl $0x2, %edi
jb 0x1c79c2
movq 0x30(%rsp), %rax
movl $0x1, (%rax)
jmp 0x1c79c2