// File: /workspace/github_cpp_makefile_star2_O1/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 $0x48, %rsp
movl %edx, %ebp
movq %rsi, %r14
movl $0x0, (%rcx)
movq (%rsi), %rsi
movl %edx, %eax
shrl %eax
leaq (%rax,%rax,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rax, %rdx
cmpl $0x0, 0x18(%rsi,%rdx)
js 0x219d7f
movq %rdi, %r15
movq (%rdi), %rdx
imulq $0x78, %rax, %rax
cmpb $0x0, 0x70(%rdx,%rax)
je 0x219d94
xorl %r12d, %r12d
movq %r12, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rcx, 0x28(%rsp)
movq $0x0, 0x8(%r14)
cmpq $0x0, 0x10(%r14)
jne 0x219dc2
movq $0x2, 0x10(%r14)
movq 0x18(%r14), %rdi
movl $0x8, %esi
callq 0x2370
movq %rax, 0x18(%r14)
movq 0x8(%r14), %rax
movq 0x18(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, 0x8(%r14)
movl %ebp, (%rcx,%rax,4)
xorl %r12d, %r12d
xorl %edi, %edi
xorl %esi, %esi
movq 0x8(%r14), %rax
decq %rax
cmpq $-0x1, %rax
je 0x21a06c
movq %rax, 0x8(%r14)
movq (%r14), %rcx
movq 0x18(%r14), %rdx
movl (%rdx,%rax,4), %r13d
movl %r13d, %ebp
shrl %ebp
leaq (,%rbp,8), %rdx
addq %rbp, %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rbp, %rdx
decq %rax
cmpl $0x0, 0x18(%rcx,%rdx)
js 0x219de3
movl %edi, 0x18(%rsp)
movl %esi, 0x1c(%rsp)
movq $0x0, 0x38(%r14)
movq %r15, %rdi
movl %r13d, %esi
leaq 0xc(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r14, %r8
callq 0x221d64
movq 0x10(%rsp), %rbx
cmpq $0x0, 0x38(%r14)
je 0x219e81
movl $0x1, %ecx
xorl %edx, %edx
movq (%r14), %rsi
movq 0x48(%r14), %rdi
movl (%rdi,%rdx,4), %edx
shrl %edx
leaq (%rdx,%rdx,8), %rdi
leaq (%rdi,%rdi,2), %rdi
addq %rdx, %rdi
orl $0x80000000, 0x18(%rsi,%rdi) # imm = 0x80000000
movl %ecx, %edx
incl %ecx
cmpq %rdx, 0x38(%r14)
ja 0x219e58
cmpl $0x7, %eax
je 0x219d7f
movq %r12, 0x40(%rsp)
movl 0xc(%rsp), %eax
movq %rax, 0x30(%rsp)
movl %eax, %esi
xorl $0x1, %esi
movq $0x0, 0x38(%r14)
movq %r15, %rdi
leaq 0xc(%rsp), %rdx
leaq 0x10(%rsp), %rcx
movq %r14, %r8
callq 0x221d64
movq 0x10(%rsp), %rax
cmpq %rax, %rbx
cmovgq %rbx, %rax
movq %rax, 0x38(%rsp)
notl %r13d
andl $0x1, %r13d
imulq $0x78, %rbp, %rax
movq %r15, 0x20(%rsp)
addq (%r15), %rax
leaq (,%r13,2), %rcx
addq %r13, %rcx
movl 0x10(%rax,%rcx,8), %r15d
xorl %r13d, %r13d
movl $0x0, %ebp
testq %r15, %r15
je 0x219f82
movq 0x20(%rax,%rcx,8), %r12
shlq $0x5, %r15
xorl %ebx, %ebx
xorl %ebp, %ebp
cmpl $0x0, 0xc(%r12,%rbx)
js 0x219f79
incl %ebp
movq (%r14), %rax
movl 0x8(%r12,%rbx), %ecx
shrl %ecx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
cmpl $0x0, 0x18(%rax,%rdx)
js 0x219f79
movq 0x10(%r14), %rax
cmpq %rax, 0x8(%r14)
jne 0x219f61
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x10(%r14)
movq 0x18(%r14), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x18(%r14)
movl 0x8(%r12,%rbx), %eax
movq 0x8(%r14), %rcx
movq 0x18(%r14), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%r14)
movl %eax, (%rdx,%rcx,4)
addq $0x20, %rbx
cmpq %rbx, %r15
jne 0x219f0c
movq 0x30(%rsp), %rdx
movl %edx, %eax
shrl %eax
imulq $0x78, %rax, %rax
movq 0x20(%rsp), %rcx
addq (%rcx), %rax
andl $0x1, %edx
leaq (%rdx,%rdx,2), %rcx
movl 0x10(%rax,%rcx,8), %ebx
testq %rbx, %rbx
je 0x21a031
movq 0x20(%rax,%rcx,8), %r15
shlq $0x5, %rbx
xorl %r12d, %r12d
xorl %r13d, %r13d
cmpl $0x0, 0xc(%r15,%r12)
js 0x21a028
incl %r13d
movq (%r14), %rax
movl 0x8(%r15,%r12), %ecx
shrl %ecx
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
cmpl $0x0, 0x18(%rax,%rdx)
js 0x21a028
movq 0x10(%r14), %rax
cmpq %rax, 0x8(%r14)
jne 0x21a010
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x10(%r14)
movq 0x18(%r14), %rdi
shlq $0x2, %rsi
callq 0x2370
movq %rax, 0x18(%r14)
movl 0x8(%r15,%r12), %eax
movq 0x8(%r14), %rcx
movq 0x18(%r14), %rdx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%r14)
movl %eax, (%rdx,%rcx,4)
addq $0x20, %r12
cmpq %r12, %rbx
jne 0x219fba
movq 0x40(%rsp), %r12
addq 0x38(%rsp), %r12
testl %ebp, %ebp
setne %al
testl %r13d, %r13d
setne %cl
andb %al, %cl
movzbl %cl, %eax
movl 0x18(%rsp), %edi
addl %eax, %edi
cmpl $0x2, %ebp
movl 0x1c(%rsp), %esi
sbbl $-0x1, %esi
cmpl $0x2, %r13d
sbbl $-0x1, %esi
movq 0x20(%rsp), %r15
jmp 0x219ddc
testl %edi, %edi
je 0x219d82
cmpl $0x2, %esi
jb 0x219d82
movq 0x28(%rsp), %rax
movl $0x1, (%rax)
jmp 0x219d82