// File: chhylp123[P]hifiasm/gfa_ut.cpp
// Function: usg_end(usg_t const*, unsigned int, unsigned long*)
static inline int usg_end(const usg_t *g, uint32_t v, uint64_t *lw)
{
    ///v^1 is the another direction of v
    uint32_t w, nv, nw, nw0, nv0 = usg_arc_n(g, v^1);
    int i, i0 = -1;
    usg_arc_t *aw, *av = usg_arc_a(g, v^1);

    ///if this arc has not been deleted
    for (i = nv = 0; i < (int)nv0; ++i)
        if (!av[i].del) i0 = i, ++nv;

    ///end without any out-degree
    if (nv == 0) return ASG_ET_TIP; // tip
    if (nv > 1) return ASG_ET_MULTI_OUT; // multiple outgoing arcs
    ///until here, nv == 1
    if (lw) *lw = ((uint64_t)(v^1))<<32 | av[i0].v;
    w = av[i0].v^1;
    nw0 = usg_arc_n(g, w); aw = usg_arc_a(g, w);
    for (i = nw = 0; i < (int)nw0; ++i)
        if (!aw[i].del) ++nw;

    if (nw != 1) return ASG_ET_MULTI_NEI;
    return ASG_ET_MERGEABLE;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x14(%rbp), %ecx
xorl $0x1, %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movl -0x14(%rbp), %ecx
xorl $0x1, %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x34(%rbp)
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x14(%rbp), %ecx
xorl $0x1, %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movl -0x14(%rbp), %ecx
xorl $0x1, %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x28(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x34eaec
movq -0x50(%rbp), %rax
movslq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x34eadf
movl -0x38(%rbp), %eax
movl %eax, -0x3c(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x34eae1
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x34eaae
cmpl $0x0, -0x28(%rbp)
jne 0x34eafe
movl $0x1, -0x4(%rbp)
jmp 0x34ec13
cmpl $0x1, -0x28(%rbp)
jbe 0x34eb10
movl $0x2, -0x4(%rbp)
jmp 0x34ec13
cmpq $0x0, -0x20(%rbp)
je 0x34eb41
movl -0x14(%rbp), %eax
xorl $0x1, %eax
movl %eax, %eax
movl %eax, %ecx
shlq $0x20, %rcx
movq -0x50(%rbp), %rax
movslq -0x3c(%rbp), %rdx
shlq $0x5, %rdx
addq %rdx, %rax
movl 0x8(%rax), %eax
orq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, (%rax)
movq -0x50(%rbp), %rax
movslq -0x3c(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
xorl $0x1, %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x24(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movl -0x24(%rbp), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl -0x24(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
addq $0x10, %rax
movl -0x24(%rbp), %ecx
andl $0x1, %ecx
movl %ecx, %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq %rax, -0x48(%rbp)
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x34ebfd
movq -0x48(%rbp), %rax
movslq -0x38(%rbp), %rcx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x34ebf0
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x34ebf2
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x34ebc5
cmpl $0x1, -0x2c(%rbp)
je 0x34ec0c
movl $0x3, -0x4(%rbp)
jmp 0x34ec13
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopl (%rax,%rax)