// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/Overlaps.cpp
// Function: get_bub_pop_max_dist_advance(asg_t*, buf_t*)
uint64_t get_bub_pop_max_dist_advance(asg_t *g, buf_t *b)
{
    asg_arc_t *av = NULL;
    uint32_t n_vtx = g->n_seq<<1, k, v, w, kv, nv, p_bub;
    uint64_t cLen = 0, mLen = 0;
    
    
    for (v = 0; v < n_vtx; ++v) 
    {
        if(b->a[v>>1].s) continue;
        if(g->seq[v>>1].del) continue;


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

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

    for (k = 0; k < g->n_seq; ++k) 
    {
        // if(b->a[k].s == 0 && !g->seq[k].del)
        // {   
        //     uint32_t convex;
        //     long long nodeLen, baseLen, max_stop_nodeLen, max_stop_baseLen;
        //     if(get_unitig(g, NULL, k<<1, &convex, &nodeLen, &baseLen, &max_stop_nodeLen, 
        //                                                             &max_stop_baseLen, 1, NULL) != LOOP)
        //     {
        //         fprintf(stderr, "ERROR 1\n");
        //     }
        // } 
        b->a[k].s = 0;
    }

    // for (; k < n_vtx; ++k)
    // {
    //     if(b->a[k].s == 1) fprintf(stderr, "ERROR 2\n");
    // }
    
    ///fprintf(stderr, "mLen: %lu, tLen: %lu\n", mLen, tLen);
    b->S.n = b->b.n = 0;
    return mLen;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %r14
movl 0x14(%rdi), %eax
movl %eax, %ecx
addl %eax, %ecx
je 0xc0289
movl %ecx, %r13d
xorl %ebp, %ebp
xorl %r15d, %r15d
movq (%rbx), %rcx
movl %ebp, %eax
shrl %eax
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rax, %rdx
cmpl $0x0, 0x18(%rcx,%rdx)
js 0xc0277
movq 0x20(%r14), %rcx
cmpl $0x0, (%rcx,%rax,8)
js 0xc0277
movq 0x28(%r14), %rcx
movq (%rcx,%rbp,8), %rdx
testl %edx, %edx
je 0xc0252
movq 0x8(%r14), %rax
movq %rdx, %rsi
shrq $0x20, %rsi
movl %edx, %edi
leaq (%rsi,%rsi,2), %rdx
leaq (%rax,%rdx,8), %rdx
addq $0xc, %rdx
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rsi
xorl %edi, %edi
xorl %r8d, %r8d
cmpl $0x0, (%rdx,%rdi)
js 0xc01fb
movl -0x4(%rdx,%rdi), %r12d
xorl $0x1, %r12d
incl %r8d
addq $0x18, %rdi
cmpq %rdi, %rsi
jne 0xc01e9
cmpl $0x1, %r8d
jne 0xc0252
movl %r12d, %edx
movq (%rcx,%rdx,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0xc0252
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rax
addq $0xc, %rax
shlq $0x3, %rcx
leaq (%rcx,%rcx,2), %rcx
xorl %edx, %edx
xorl %esi, %esi
movl (%rax,%rdx), %edi
notl %edi
shrl $0x1f, %edi
addl %edi, %esi
addq $0x18, %rdx
cmpq %rdx, %rcx
jne 0xc023a
cmpl $0x1, %esi
je 0xc0277
movl %ebp, %edx
xorl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x4(%rsp), %rcx
callq 0xe6779
cmpq %r15, %rax
cmovbeq %r15, %rax
cmpl $0x0, 0x4(%rsp)
cmovneq %rax, %r15
incq %rbp
cmpq %r13, %rbp
jne 0xc0188
movl 0x14(%r14), %eax
jmp 0xc028c
xorl %r15d, %r15d
testl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
je 0xc02ba
movl $0x18, %eax
xorl %ecx, %ecx
movq (%rbx), %rdx
andl $0x7fffffff, (%rdx,%rax) # imm = 0x7FFFFFFF
incq %rcx
movl 0x14(%r14), %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
addq $0x1c, %rax
cmpq %rdx, %rcx
jb 0xc029a
xorl %eax, %eax
movq %rax, 0x38(%rbx)
movq %rax, 0x8(%rbx)
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq