// File: chhylp123[P]hifiasm/Overlaps.cpp
// Function: dfs_subgraph_advance(asg_t*, buf_t*, unsigned int, unsigned int*)
uint64_t dfs_subgraph_advance(asg_t *g, buf_t *b, uint32_t x, uint32_t *p_bub)
{
    uint64_t len = 0;
    uint32_t c_v, e_v, nv, convex, v, i, kv_0, kv_1, flag_0 = 0, flag_1 = 0, op;
    asg_arc_t *av = NULL;
    long long nodeLen, baseLen, max_stop_nodeLen, max_stop_baseLen, uLen;
    (*p_bub) = 0;
    if(b->a[x>>1].s || g->seq[x>>1].del) return 0;
    b->S.n = 0;
    kv_push(uint32_t, b->S, x);

    while (b->S.n > 0)
    {
        b->S.n--;
        c_v = b->S.a[b->S.n];
        if(b->a[c_v>>1].s) continue;

        b->b.n = 0;
        op = get_unitig(g, NULL, c_v, &convex, &nodeLen, &baseLen, &max_stop_nodeLen, 
                                                                    &max_stop_baseLen, 1, b);
        uLen = baseLen;
        for(i = 0; i < b->b.n; i++)
        {
            ///if(b->a[b->b.a[i]>>1].s == 1) fprintf(stderr, "ERROR 3\n");
            b->a[b->b.a[i]>>1].s = 1;
        } 
        
        if(op == LOOP) return 0;


        e_v = convex^1;
        b->b.n = 0;
        op = get_unitig(g, NULL, e_v, &convex, &nodeLen, &baseLen, &max_stop_nodeLen, 
                                                                    &max_stop_baseLen, 1, b);
        uLen = MAX(uLen, baseLen);

        len += uLen;

        
        v = c_v^1;
        nv = asg_arc_n(g, v);
        av = asg_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 = asg_arc_n(g, v);
        av = asg_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
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movl $0x0, -0x54(%rbp)
movl $0x0, -0x58(%rbp)
movq $0x0, -0x68(%rbp)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl -0x1c(%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 0x13bedc
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x1c(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
movl (%rax,%rcx,8), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x13bee9
movq $0x0, -0x8(%rbp)
jmp 0x13c464
movq -0x18(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x13bf67
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x13bf26
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x98(%rbp)
jmp 0x13bf34
movl $0x2, %eax
movq %rax, -0x98(%rbp)
jmp 0x13bf34
movq -0x98(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x1c(%rbp), %edx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rsi
movq 0x8(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x8(%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x13bf8a
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jbe 0x13c446
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
addq $-0x1, %rcx
movq %rcx, 0x8(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x8(%rcx), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movl -0x34(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x13bfe1
jmp 0x13bf8a
movq -0x18(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x10(%rbp), %rdi
movl -0x34(%rbp), %edx
movq -0x18(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %esi
leaq -0x40(%rbp), %rcx
leaq -0x70(%rbp), %r8
leaq -0x78(%rbp), %r9
leaq -0x80(%rbp), %r11
leaq -0x88(%rbp), %r10
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x166c30
movl %eax, -0x5c(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x90(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpq 0x38(%rcx), %rax
jae 0x13c08d
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x48(%rcx), %rcx
movl -0x48(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, 0x18(%rax)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x13c043
cmpl $0x7, -0x5c(%rbp)
jne 0x13c0a0
movq $0x0, -0x8(%rbp)
jmp 0x13c464
movl -0x40(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, 0x38(%rax)
movq -0x10(%rbp), %rdi
movl -0x38(%rbp), %edx
movq -0x18(%rbp), %rax
xorl %ecx, %ecx
movl %ecx, %esi
leaq -0x40(%rbp), %rcx
leaq -0x70(%rbp), %r8
leaq -0x78(%rbp), %r9
leaq -0x80(%rbp), %r11
leaq -0x88(%rbp), %r10
movq %r11, (%rsp)
movq %r10, 0x8(%rsp)
movl $0x1, 0x10(%rsp)
movq %rax, 0x18(%rsp)
callq 0x166c30
movl %eax, -0x5c(%rbp)
movq -0x90(%rbp), %rax
cmpq -0x78(%rbp), %rax
jl 0x13c116
movq -0x90(%rbp), %rax
movq %rax, -0xa0(%rbp)
jmp 0x13c121
movq -0x78(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x90(%rbp), %rax
addq -0x30(%rbp), %rax
movq %rax, -0x30(%rbp)
movl -0x34(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x44(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x44(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x4c(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jae 0x13c2a6
movq -0x68(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x13c1b7
jmp 0x13c298
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x68(%rbp), %rcx
movl -0x48(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x13c1f3
jmp 0x13c298
jmp 0x13c1f5
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x13c267
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x13c226
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0xa8(%rbp)
jmp 0x13c234
movl $0x2, %eax
movq %rax, -0xa8(%rbp)
jmp 0x13c234
movq -0xa8(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x68(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rsi
movq 0x8(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x8(%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x13c298
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x13c18d
movl -0x38(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x44(%rbp)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x44(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x3c(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x28(%rcx), %rcx
movl -0x44(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x68(%rbp)
movl $0x0, -0x50(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jae 0x13c40e
movq -0x68(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x13c31f
jmp 0x13c400
movl -0x50(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x50(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x68(%rbp), %rcx
movl -0x48(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movl 0x8(%rcx), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movl 0x18(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x13c35b
jmp 0x13c400
jmp 0x13c35d
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x13c3cf
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x13c38e
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0xb0(%rbp)
jmp 0x13c39c
movl $0x2, %eax
movq %rax, -0xb0(%rbp)
jmp 0x13c39c
movq -0xb0(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rsi
shlq $0x2, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x68(%rbp), %rax
movl -0x48(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %edx
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rsi
movq 0x8(%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, 0x8(%rsi)
movl %edx, (%rax,%rcx,4)
jmp 0x13c400
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x13c2f5
cmpl $0x0, -0x4c(%rbp)
jbe 0x13c423
cmpl $0x0, -0x50(%rbp)
jbe 0x13c423
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
cmpl $0x1, -0x4c(%rbp)
jbe 0x13c432
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
cmpl $0x1, -0x50(%rbp)
jbe 0x13c441
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x13bf8a
cmpl $0x0, -0x54(%rbp)
jbe 0x13c45c
cmpl $0x1, -0x58(%rbp)
jbe 0x13c45c
movq -0x28(%rbp), %rax
movl $0x1, (%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)