// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: usg_max_bub(usg_t*, buf_t*, asg64_v*)
uint64_t usg_max_bub(usg_t *g, buf_t *b, asg64_v *nb)
{
    usg_arc_t *av, *aw; uint64_t cLen = 0, mLen = 0;
    uint32_t n_vtx = g->n<<1, k, v, w, kv, nv, kw, nw, p_bub;
    for (v = 0; v < n_vtx; ++v) {
        if(b->a[v>>1].s || g->a[v>>1].del) continue;

        av = usg_arc_a(g, v); nv = usg_arc_n(g, v);
        for (k = kv = 0; k < nv && kv <= 1; k++) {
            if(av[k].del) continue;
            w = av[k].v^1; kv++;
        }

        if(kv == 1) {
            aw = usg_arc_a(g, w); nw = usg_arc_n(g, w);
            for (k = kw = 0; k < nw && kw <= 1; k++) {
                if(aw[k].del) continue;
                kw++;
            }
            if(kw == 1) continue;
        }

        cLen = dfs_max_bub(g, b, v^1, nb, &p_bub);
        if(p_bub == 0) continue;///no bubble
        if(cLen > mLen) mLen = cLen;
    }

    for (k = 0; k < g->n; ++k) b->a[k].s = 0;

    b->S.n = b->b.n = 0;
    return mLen;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movl %eax, -0x3c(%rbp)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jae 0x351c1f
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x44(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x351a30
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x44(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
cmpb $0x0, 0x70(%rax)
je 0x351a35
jmp 0x351c11
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x44(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movl -0x44(%rbp), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x44(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movl -0x44(%rbp), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %ecx
xorl %eax, %eax
cmpl -0x50(%rbp), %ecx
movb %al, -0x5d(%rbp)
jae 0x351ab8
cmpl $0x1, -0x4c(%rbp)
setbe %al
movb %al, -0x5d(%rbp)
movb -0x5d(%rbp), %al
testb $0x1, %al
jne 0x351ac1
jmp 0x351b07
movq -0x20(%rbp), %rax
movl -0x40(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x351adc
jmp 0x351afc
movq -0x20(%rbp), %rax
movl -0x40(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x48(%rbp)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x351aa1
cmpl $0x1, -0x4c(%rbp)
jne 0x351bd6
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x48(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movl -0x48(%rbp), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x48(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movl -0x48(%rbp), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x58(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %ecx
xorl %eax, %eax
cmpl -0x58(%rbp), %ecx
movb %al, -0x5e(%rbp)
jae 0x351b94
cmpl $0x1, -0x54(%rbp)
setbe %al
movb %al, -0x5e(%rbp)
movb -0x5e(%rbp), %al
testb $0x1, %al
jne 0x351b9d
jmp 0x351bcc
movq -0x28(%rbp), %rax
movl -0x40(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x351bb8
jmp 0x351bc1
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x351b7d
cmpl $0x1, -0x54(%rbp)
jne 0x351bd4
jmp 0x351c11
jmp 0x351bd6
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x44(%rbp), %edx
xorl $0x1, %edx
movq -0x18(%rbp), %rcx
leaq -0x5c(%rbp), %r8
callq 0x351390
movq %rax, -0x30(%rbp)
cmpl $0x0, -0x5c(%rbp)
jne 0x351bfd
jmp 0x351c11
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
jbe 0x351c0f
movq -0x30(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x351c11
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x3519e9
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jae 0x351c5e
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x40(%rbp), %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x0, %ecx
movl %ecx, 0x18(%rax)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x351c26
movq -0x10(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x38(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq