// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Overlaps.cpp
// Function: get_s_bub_pop_max_dist_advance(asg_t*, buf_s_t*)
uint64_t get_s_bub_pop_max_dist_advance(asg_t *g, buf_s_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_s_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
addl %eax, %eax
je 0xa6f91
movl %eax, %r13d
xorl %ebp, %ebp
xorl %r15d, %r15d
movq (%rbx), %rcx
movl %ebp, %eax
shrl %eax
leaq (%rax,%rax,2), %rdx
cmpl $0x0, 0x8(%rcx,%rdx,4)
js 0xa6f83
movq 0x20(%r14), %rcx
cmpl $0x0, (%rcx,%rax,8)
js 0xa6f83
movq 0x8(%r14), %rax
movq 0x28(%r14), %rcx
movq (%rcx,%rbp,8), %rsi
xorl %edx, %edx
testl %esi, %esi
je 0xa6f12
movq %rsi, %rdi
shrq $0x20, %rdi
movl %esi, %r8d
leaq (%rdi,%rdi,2), %rsi
leaq (%rax,%rsi,8), %rsi
addq $0xc, %rsi
shlq $0x3, %r8
leaq (%r8,%r8,2), %rdi
xorl %r8d, %r8d
cmpl $0x0, (%rsi,%r8)
js 0xa6f03
movl -0x4(%rsi,%r8), %r12d
xorl $0x1, %r12d
incl %edx
addq $0x18, %r8
cmpq %r8, %rdi
jne 0xa6ef1
cmpl $0x1, %edx
sete %dl
testb %dl, %dl
je 0xa6f5e
movl %r12d, %edx
movq (%rcx,%rdx,8), %rdx
movq %rdx, %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rsi, %rcx
je 0xa6f5e
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 0xa6f46
cmpl $0x1, %esi
je 0xa6f83
movl %ebp, %edx
xorl $0x1, %edx
movq %r14, %rdi
movq %rbx, %rsi
leaq 0x4(%rsp), %rcx
callq 0xe53e3
cmpq %r15, %rax
cmovbeq %r15, %rax
cmpl $0x0, 0x4(%rsp)
cmovneq %rax, %r15
incq %rbp
cmpq %r13, %rbp
jne 0xa6e9a
jmp 0xa6f94
xorl %r15d, %r15d
testl $0x7fffffff, 0x14(%r14) # imm = 0x7FFFFFFF
je 0xa6fc5
movl $0x8, %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 $0xc, %rax
cmpq %rdx, %rcx
jb 0xa6fa5
xorl %eax, %eax
movq %rax, 0x20(%rbx)
movq %rax, 0x8(%rbx)
movq %r15, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq