// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: dfs_usg_t_dis(usg_t*, buf_t*, unsigned int, unsigned int*)
uint64_t dfs_usg_t_dis(usg_t *g, buf_t *b, uint32_t x, uint32_t *p_bub)
{
    uint64_t len = 0; usg_arc_t *av = NULL; int64_t baseLen, uLen;
    uint32_t c_v, e_v, nv, convex, v, i, kv_0, kv_1, flag_0 = 0, flag_1 = 0, op;
    
    (*p_bub) = 0;
    if(b->a[x>>1].s || g->a[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; //uint32_t gen_usg_tig(usg_t *g, uint32_t sid, uint32_t *eid, int64_t *baseLen, buf_t* b)
        op = gen_usg_tig(g, c_v, &convex, &baseLen, b);
        uLen = baseLen;
        for(i = 0; i < b->b.n; i++) b->a[b->b.a[i]>>1].s = 1;
        if(op == LOOP) return 0;


        e_v = convex^1;
        b->b.n = 0;
        op = gen_usg_tig(g, e_v, &convex, &baseLen, b);
        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 $0x38, %rsp
movq %rcx, %rbx
movl %edx, %ebp
andl $0x0, (%rcx)
movq (%rsi), %rcx
movl %edx, %eax
shrl %eax
imulq $0x1c, %rax, %rdx
cmpl $0x0, 0x18(%rcx,%rdx)
js 0x1d612a
movq %rdi, %r12
movq (%rdi), %rcx
imulq $0x78, %rax, %rax
cmpb $0x0, 0x70(%rcx,%rax)
je 0x1d613e
xorl %esi, %esi
movq %rsi, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %r14
andq $0x0, 0x8(%rsi)
cmpq $0x0, 0x10(%rsi)
je 0x1d6155
movq 0x18(%r14), %rax
xorl %edx, %edx
jmp 0x1d6171
movq $0x2, 0x10(%r14)
movq 0x18(%r14), %rdi
pushq $0x8
popq %rsi
callq 0x2370
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rdx
movq %rbx, 0x20(%rsp)
leaq 0x1(%rdx), %rcx
movq %rcx, 0x8(%r14)
movl %ebp, (%rax,%rdx,4)
xorl %esi, %esi
xorl %r8d, %r8d
xorl %edi, %edi
decq %rcx
cmpq $-0x1, %rcx
je 0x1d63c0
movq %rcx, 0x8(%r14)
movq (%r14), %rax
movq 0x18(%r14), %rdx
movl (%rdx,%rcx,4), %r13d
movl %r13d, %ebx
shrl %ebx
imulq $0x1c, %rbx, %rdx
decq %rcx
cmpl $0x0, 0x18(%rax,%rdx)
js 0x1d618b
movl %r8d, 0x10(%rsp)
movl %edi, 0x14(%rsp)
movq %rsi, 0x30(%rsp)
andq $0x0, 0x38(%r14)
movq %r12, %rdi
movl %r13d, %esi
leaq 0x4(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r14, %r8
callq 0x1df06d
xorl %ecx, %ecx
movq 0x8(%rsp), %r15
movl %ecx, %ecx
cmpq %rcx, 0x38(%r14)
jbe 0x1d620d
movq (%r14), %rdx
movq 0x48(%r14), %rsi
movl (%rsi,%rcx,4), %esi
shrl %esi
imulq $0x1c, %rsi, %rsi
orl $0x80000000, 0x18(%rdx,%rsi) # imm = 0x80000000
incl %ecx
jmp 0x1d61e9
cmpl $0x7, %eax
je 0x1d612a
movl 0x4(%rsp), %ebp
movl %ebp, %esi
xorl $0x1, %esi
andq $0x0, 0x38(%r14)
movq %r12, %rdi
leaq 0x4(%rsp), %rdx
leaq 0x8(%rsp), %rcx
movq %r14, %r8
callq 0x1df06d
movq 0x8(%rsp), %rax
cmpq %rax, %r15
cmovgq %r15, %rax
movq %rax, 0x28(%rsp)
notl %r13d
andl $0x1, %r13d
imulq $0x78, %rbx, %rax
movq %r12, 0x18(%rsp)
addq (%r12), %rax
imulq $0x18, %r13, %rcx
movl 0x10(%rcx,%rax), %ebx
movq 0x20(%rcx,%rax), %r15
shlq $0x5, %rbx
xorl %r12d, %r12d
xorl %r13d, %r13d
cmpq %r12, %rbx
je 0x1d62e6
cmpl $0x0, 0xc(%r15,%r12)
js 0x1d62e0
incl %r13d
movq (%r14), %rax
movl 0x8(%r15,%r12), %ecx
movl %ecx, %edx
shrl %edx
imulq $0x1c, %rdx, %rdx
cmpl $0x0, 0x18(%rax,%rdx)
js 0x1d62e0
movq 0x8(%r14), %rdx
movq 0x18(%r14), %rax
cmpq 0x10(%r14), %rdx
jne 0x1d62d5
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x18(%r14)
movl 0x8(%r15,%r12), %ecx
movq 0x8(%r14), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%r14)
movl %ecx, (%rax,%rdx,4)
addq $0x20, %r12
jmp 0x1d6275
movl %ebp, %eax
shrl %eax
andl $0x1, %ebp
imulq $0x78, %rax, %rax
movq 0x18(%rsp), %rcx
addq (%rcx), %rax
imulq $0x18, %rbp, %rcx
movl 0x10(%rcx,%rax), %ebx
movq 0x20(%rcx,%rax), %r15
shlq $0x5, %rbx
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpq %r12, %rbx
je 0x1d637f
cmpl $0x0, 0xc(%r15,%r12)
js 0x1d6379
incl %ebp
movq (%r14), %rax
movl 0x8(%r15,%r12), %ecx
movl %ecx, %edx
shrl %edx
imulq $0x1c, %rdx, %rdx
cmpl $0x0, 0x18(%rax,%rdx)
js 0x1d6379
movq 0x8(%r14), %rdx
movq 0x18(%r14), %rax
cmpq 0x10(%r14), %rdx
jne 0x1d636e
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x10(%r14)
shlq $0x2, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x18(%r14)
movl 0x8(%r15,%r12), %ecx
movq 0x8(%r14), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%r14)
movl %ecx, (%rax,%rdx,4)
addq $0x20, %r12
jmp 0x1d630f
movq 0x30(%rsp), %rsi
addq 0x28(%rsp), %rsi
testl %r13d, %r13d
setne %al
testl %ebp, %ebp
setne %cl
andb %al, %cl
movzbl %cl, %eax
movl 0x10(%rsp), %r8d
addl %eax, %r8d
cmpl $0x2, %r13d
movl 0x14(%rsp), %edi
sbbl $-0x1, %edi
cmpl $0x2, %ebp
sbbl $-0x1, %edi
movq 0x8(%r14), %rcx
movq 0x18(%rsp), %r12
jmp 0x1d6188
testl %r8d, %r8d
je 0x1d612c
cmpl $0x2, %edi
jb 0x1d612c
movq 0x20(%rsp), %rax
movl $0x1, (%rax)
jmp 0x1d612c