// File: /workspace/github_cpp_makefile_star2_O3/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
movl %edx, %ebx
movl $0x0, (%r8)
movq $0x0, 0x8(%rsi)
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 0x215838
movq (%rdi), %rcx
imulq $0x78, %rax, %rax
cmpb $0x0, 0x70(%rcx,%rax)
je 0x21584c
xorl %edi, %edi
movq %rdi, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r8, %r14
movq %rsi, %r15
movq %rdi, 0x18(%rsp)
cmpq $0x0, 0x10(%rsi)
je 0x21586b
movq 0x18(%r15), %rax
movl %ebx, (%rax)
movl $0x1, %ecx
jmp 0x215898
movq $0x2, 0x10(%r15)
movq 0x18(%r15), %rdi
movl $0x8, %esi
callq 0x2370
movq %rax, 0x18(%r15)
movq 0x8(%r15), %rdx
movq %rdx, %rcx
incq %rcx
movq %rcx, 0x8(%r15)
movl %ebx, (%rax,%rdx,4)
je 0x215838
movq %r14, 0x30(%rsp)
xorl %r8d, %r8d
xorl %r9d, %r9d
xorl %edi, %edi
movq 0x18(%rsp), %r14
movq %r12, 0x38(%rsp)
movq %rcx, %rax
movq (%r15), %rdx
movq 0x18(%r15), %rsi
decq %rcx
movq %rcx, 0x8(%r15)
movl -0x4(%rsi,%rax,4), %r13d
movl %r13d, %ebp
shrl %ebp
leaq (,%rbp,8), %rax
addq %rbp, %rax
leaq (%rax,%rax,2), %rax
addq %rbp, %rax
cmpl $0x0, 0x18(%rdx,%rax)
js 0x215b54
movl %r9d, 0x28(%rsp)
movl %r8d, 0x2c(%rsp)
movq %rdi, 0x50(%rsp)
movq $0x0, (%r12)
movq %r12, (%rsp)
movq %r14, %rdi
movl %r13d, %esi
leaq 0x14(%rsp), %rdx
xorl %ecx, %ecx
leaq 0x20(%rsp), %r8
xorl %r9d, %r9d
callq 0x22d1ab
movq 0x20(%rsp), %rbx
cmpq $0x0, (%r12)
je 0x21595b
movl $0x1, %ecx
xorl %edx, %edx
movq (%r15), %rsi
movq 0x10(%r12), %rdi
movq (%rdi,%rdx,8), %rdx
shrq %rdx
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, (%r12)
ja 0x21592f
cmpl $0x7, %eax
je 0x215838
movl 0x14(%rsp), %eax
movq %rax, 0x40(%rsp)
movl %eax, %esi
xorl $0x1, %esi
movq $0x0, (%r12)
movq %r12, (%rsp)
xorl %r12d, %r12d
movq %r14, %rdi
leaq 0x14(%rsp), %rdx
xorl %ecx, %ecx
leaq 0x20(%rsp), %r8
xorl %r9d, %r9d
callq 0x22d1ab
movq 0x20(%rsp), %rax
cmpq %rax, %rbx
cmovaq %rbx, %rax
movq %rax, 0x48(%rsp)
movq (%r14), %rax
notl %r13d
andl $0x1, %r13d
imulq $0x78, %rbp, %rcx
addq %rax, %rcx
leaq (,%r13,2), %rdx
addq %r13, %rdx
movl 0x10(%rcx,%rdx,8), %r13d
movl $0x0, %ebp
testq %r13, %r13
je 0x215a65
movq 0x20(%rcx,%rdx,8), %rbx
shlq $0x5, %r13
xorl %r14d, %r14d
xorl %ebp, %ebp
cmpl $0x0, 0xc(%rbx,%r14)
js 0x215a54
incl %ebp
movq (%r15), %rax
movl 0x8(%rbx,%r14), %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 0x215a54
movq 0x8(%r15), %rdx
movq 0x18(%r15), %rax
cmpq 0x10(%r15), %rdx
jne 0x215a49
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r15)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x18(%r15)
movl 0x8(%rbx,%r14), %ecx
movq 0x8(%r15), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%r15)
movl %ecx, (%rax,%rdx,4)
addq $0x20, %r14
cmpq %r14, %r13
jne 0x2159e6
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq 0x40(%rsp), %rdx
movl %edx, %ecx
shrl %ecx
andl $0x1, %edx
imulq $0x78, %rcx, %rcx
addq %rax, %rcx
leaq (%rdx,%rdx,2), %rax
movl 0x10(%rcx,%rax,8), %ebx
testq %rbx, %rbx
je 0x215b10
movq 0x20(%rcx,%rax,8), %r13
shlq $0x5, %rbx
xorl %r14d, %r14d
xorl %r12d, %r12d
cmpl $0x0, 0xc(%r13,%r14)
js 0x215b07
incl %r12d
movq (%r15), %rax
movl 0x8(%r13,%r14), %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 0x215b07
movq 0x8(%r15), %rdx
movq 0x18(%r15), %rax
cmpq 0x10(%r15), %rdx
jne 0x215afc
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
movl $0x2, %ecx
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
cmpq %r14, %rbx
jne 0x215a98
movq 0x50(%rsp), %rdi
addq 0x48(%rsp), %rdi
testl %ebp, %ebp
setne %al
testl %r12d, %r12d
setne %cl
andb %al, %cl
movzbl %cl, %eax
movl 0x28(%rsp), %r9d
addl %eax, %r9d
cmpl $0x2, %ebp
movl 0x2c(%rsp), %r8d
sbbl $-0x1, %r8d
cmpl $0x2, %r12d
sbbl $-0x1, %r8d
movq 0x8(%r15), %rcx
movq 0x38(%rsp), %r12
movq 0x18(%rsp), %r14
testq %rcx, %rcx
jne 0x2158af
testl %r9d, %r9d
je 0x21583a
cmpl $0x2, %r8d
jb 0x21583a
movq 0x30(%rsp), %rax
movl $0x1, (%rax)
jmp 0x21583a