// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movl %edx, %ebp
movq %rsi, %r15
movl $0x0, (%r8)
movq $0x0, 0x8(%rsi)
movq (%rsi), %rsi
movl %edx, %eax
shrl %eax
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rax, %rdx
cmpl $0x0, 0x18(%rsi,%rdx)
js 0x20a4df
movq %rdi, %r12
movq (%rdi), %rdx
imulq $0x78, %rax, %rax
cmpb $0x0, 0x70(%rdx,%rax)
je 0x20a4f3
xorl %esi, %esi
movq %rsi, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r8, %rbx
movq %rcx, 0x40(%rsp)
cmpq $0x0, 0x10(%r15)
jne 0x20a51c
movq $0x2, 0x10(%r15)
movq 0x18(%r15), %rdi
movl $0x8, %esi
callq 0x2370
movq %rax, 0x18(%r15)
movq %rbx, 0x28(%rsp)
movq 0x8(%r15), %rax
movq 0x18(%r15), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%r15)
movl %ebp, (%rcx,%rax,4)
xorl %esi, %esi
xorl %r8d, %r8d
xorl %edi, %edi
movq 0x8(%r15), %rax
decq %rax
cmpq $-0x1, %rax
je 0x20a7de
movq (%r15), %rcx
movq 0x18(%r15), %rdx
movq %rax, 0x8(%r15)
movl (%rdx,%rax,4), %r13d
movl %r13d, %ebp
shrl %ebp
leaq (,%rbp,8), %rdx
addq %rbp, %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rbp, %rdx
decq %rax
cmpl $0x0, 0x18(%rcx,%rdx)
js 0x20a542
movl %r8d, 0x18(%rsp)
movl %edi, 0x1c(%rsp)
movq %rsi, 0x38(%rsp)
movq 0x40(%rsp), %rbx
movq $0x0, (%rbx)
movq %rbx, (%rsp)
movq %r12, %rdi
movl %r13d, %esi
leaq 0xc(%rsp), %rdx
xorl %ecx, %ecx
leaq 0x10(%rsp), %r8
xorl %r9d, %r9d
callq 0x221b0b
movq %rbx, %r8
movq 0x10(%rsp), %rbx
cmpq $0x0, (%r8)
je 0x20a5f3
movl $0x1, %ecx
xorl %edx, %edx
movq (%r15), %rsi
movq 0x10(%r8), %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, (%r8)
ja 0x20a5c9
cmpl $0x7, %eax
je 0x20a4df
movl 0xc(%rsp), %r14d
movl %r14d, %esi
xorl $0x1, %esi
movq $0x0, (%r8)
movq %r8, (%rsp)
movq %r12, %rdi
leaq 0xc(%rsp), %rdx
xorl %ecx, %ecx
leaq 0x10(%rsp), %r8
xorl %r9d, %r9d
callq 0x221b0b
movq 0x10(%rsp), %rax
cmpq %rax, %rbx
cmovaq %rbx, %rax
movq %rax, 0x30(%rsp)
notl %r13d
andl $0x1, %r13d
imulq $0x78, %rbp, %rax
movq %r12, 0x20(%rsp)
addq (%r12), %rax
leaq (,%r13,2), %rcx
addq %r13, %rcx
movl 0x10(%rax,%rcx,8), %r13d
movl $0x0, %ebp
testq %r13, %r13
je 0x20a6ef
movq 0x20(%rax,%rcx,8), %r12
shlq $0x5, %r13
xorl %ebx, %ebx
xorl %ebp, %ebp
cmpl $0x0, 0xc(%r12,%rbx)
js 0x20a6e6
incl %ebp
movq (%r15), %rax
movl 0x8(%r12,%rbx), %ecx
shrl %ecx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
cmpl $0x0, 0x18(%rax,%rdx)
js 0x20a6e6
movq 0x10(%r15), %rax
cmpq %rax, 0x8(%r15)
jne 0x20a6ce
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x10(%r15)
movq 0x18(%r15), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x18(%r15)
movl 0x8(%r12,%rbx), %eax
movq 0x8(%r15), %rcx
movq 0x18(%r15), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%r15)
movl %eax, (%rdx,%rcx,4)
addq $0x20, %rbx
cmpq %rbx, %r13
jne 0x20a679
movl %r14d, %eax
shrl %eax
imulq $0x78, %rax, %rax
movq 0x20(%rsp), %rcx
addq (%rcx), %rax
andl $0x1, %r14d
leaq (%r14,%r14,2), %rcx
movl 0x10(%rax,%rcx,8), %r12d
testq %r12, %r12
movl $0x0, %r14d
je 0x20a7a1
movq 0x20(%rax,%rcx,8), %r13
shlq $0x5, %r12
xorl %ebx, %ebx
xorl %r14d, %r14d
cmpl $0x0, 0xc(%r13,%rbx)
js 0x20a798
incl %r14d
movq (%r15), %rax
movl 0x8(%r13,%rbx), %ecx
shrl %ecx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
cmpl $0x0, 0x18(%rax,%rdx)
js 0x20a798
movq 0x10(%r15), %rax
cmpq %rax, 0x8(%r15)
jne 0x20a780
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x10(%r15)
movq 0x18(%r15), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x18(%r15)
movl 0x8(%r13,%rbx), %eax
movq 0x8(%r15), %rcx
movq 0x18(%r15), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%r15)
movl %eax, (%rdx,%rcx,4)
addq $0x20, %rbx
cmpq %rbx, %r12
jne 0x20a72a
movq 0x38(%rsp), %rsi
addq 0x30(%rsp), %rsi
testl %ebp, %ebp
setne %al
testl %r14d, %r14d
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, %r14d
sbbl $-0x1, %edi
movq 0x20(%rsp), %r12
jmp 0x20a53b
testl %r8d, %r8d
je 0x20a4e1
cmpl $0x2, %edi
jb 0x20a4e1
movq 0x28(%rsp), %rax
movl $0x1, (%rax)
jmp 0x20a4e1