// File: /workspace/github_c_makefile_star2_O1/c-zhou[P]oatk/graph.c
// Function: asmg_uext
static inline int32_t asmg_uext(asmg_t *g, uint64_t v, int32_t max_ext, uint64_t *ne, uint64_t *le, u64_v_t *a, int tip_only)
{
    // the extension of circular unitigs will be bounded by max_ext
    // and the return value will be ASMG_VT_MERGEABLE
    int32_t vt;
    uint64_t nv, nw, l, w, n_ext, l_ext;
    l = n_ext = l_ext = 0;
    if (a) a->n = 0;
    if (a) kv_push(uint64_t, *a, v);
    do {
        nv = asmg_arc_n2(g, v, &w, &l);
        if (nv == 0) {
            vt = ASMG_VT_TIP;
        } else if (nv > 1) {
            vt = ASMG_VT_MULTI_OUT;
        } else {
            nw = asmg_arc_n1(g, w^1);
            vt = nw == 1? ASMG_VT_MERGEABLE : ASMG_VT_MULTI_NEI;
        }
        l_ext += l;
        if (vt != ASMG_VT_MERGEABLE) break;
        ++n_ext;
        if (a) kv_push(uint64_t, *a, w);
        v = w;
    } while (--max_ext > 0);
    if (tip_only && vt == ASMG_VT_MULTI_OUT) {
        // for tip extenstion
        l_ext -= l;
        if (a) (*a).n--;
    }
    if (ne) *ne = n_ext;
    if (le) *le = l_ext;
    return vt;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r9d, 0x4(%rsp)
movq %r8, %r14
movq %rcx, 0x8(%rsp)
movl %edx, %r15d
movq %rsi, %r13
movq %rdi, %r12
testq %r8, %r8
je 0x15b13
movq $0x0, (%r14)
cmpq $0x0, 0x8(%r14)
jne 0x15b01
movq $0x2, 0x8(%r14)
movq 0x10(%r14), %rdi
movl $0x10, %esi
callq 0x2360
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movq %r13, (%rcx,%rax,8)
xorl %ebx, %ebx
movq %rbx, %rdi
movq 0x10(%r12), %rdx
movq %r13, %rax
shrq %rax
leaq (%rax,%rax,4), %rsi
testb $0x40, 0x23(%rdx,%rsi,8)
jne 0x15b8d
movq %rdi, %rbp
movq 0x38(%r12), %rax
movq (%rax,%r13,8), %r8
movq 0x28(%r12), %rcx
movq 0x30(%r12), %rax
movq (%rax,%r13,8), %rax
leaq (%rax,%rax,2), %rdi
shlq $0x4, %rdi
testq %r8, %r8
je 0x15b9a
leaq (%rcx,%rdi), %r11
addq $0x20, %r11
xorl %ebx, %ebx
xorl %r9d, %r9d
xorl %r10d, %r10d
xorl %eax, %eax
testb $0x40, 0x3(%r11)
jne 0x15b7f
incq %rax
movq -0x8(%r11), %r10
cmpq %r9, %r10
cmovaq %r10, %r9
movq %rbx, %r10
incq %rbx
addq $0x30, %r11
cmpq %rbx, %r8
jne 0x15b67
jmp 0x15ba2
xorl %ebx, %ebx
movq $-0x1, %r13
xorl %eax, %eax
jmp 0x15bcc
xorl %eax, %eax
xorl %r10d, %r10d
xorl %r9d, %r9d
movq 0x18(%rdx,%rsi,8), %rbx
subq %r9, %rbx
cmpq $0x1, %rax
jne 0x15bc2
addq %rdi, %rcx
leaq (%r10,%r10,2), %rdx
shlq $0x4, %rdx
movq 0x8(%rcx,%rdx), %r13
jmp 0x15bc9
movq $-0x1, %r13
movq %rbp, %rdi
testq %rax, %rax
je 0x15c35
cmpq $0x1, %rax
jne 0x15c3c
leaq (,%r13,8), %rcx
xorq $0x8, %rcx
movq 0x38(%r12), %rax
movq (%rax,%rcx), %rax
testq %rax, %rax
je 0x15c43
movq 0x28(%r12), %rdx
movq 0x30(%r12), %rsi
movq (%rsi,%rcx), %rcx
leaq (%rcx,%rcx,2), %rcx
shlq $0x4, %rcx
addq %rdx, %rcx
addq $0x20, %rcx
movq %rax, %rdx
movl (%rcx), %esi
addl %esi, %esi
sarl $0x1f, %esi
movslq %esi, %rsi
addq %rsi, %rdx
addq $0x30, %rcx
decq %rax
jne 0x15c11
xorl %eax, %eax
cmpq $0x1, %rdx
setne %al
leal (%rax,%rax,2), %ebp
jmp 0x15c48
movl $0x1, %ebp
jmp 0x15c48
movl $0x2, %ebp
jmp 0x15c48
movl $0x3, %ebp
addq %rdi, %rbx
testl %ebp, %ebp
jne 0x15cbb
testq %r14, %r14
je 0x15caa
movq 0x8(%r14), %rax
cmpq %rax, (%r14)
jne 0x15c98
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%r14)
movq %r15, 0x10(%rsp)
movq %r12, %r15
movq %rdi, %r12
movq 0x10(%r14), %rdi
shlq $0x3, %rsi
callq 0x2360
movq %r12, %rdi
movq %r15, %r12
movq 0x10(%rsp), %r15
movq %rax, 0x10(%r14)
movq (%r14), %rax
movq 0x10(%r14), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%r14)
movq %r13, (%rcx,%rax,8)
leal -0x1(%r15), %eax
cmpl $0x1, %r15d
movl %eax, %r15d
jg 0x15b15
cmpl $0x0, 0x4(%rsp)
sete %cl
cmpl $0x2, %ebp
setne %al
orb %cl, %al
cmoveq %rdi, %rbx
testq %r14, %r14
je 0x15cde
testb %al, %al
jne 0x15cde
decq (%r14)
movq %rdi, %rbx
movq 0x8(%rsp), %rax
testq %rax, %rax
je 0x15ceb
movq %rbx, (%rax)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq