// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: get_ext_tip(usg_t*, unsigned long*, unsigned long, unsigned long, asg64_v*, asg64_v*, unsigned char*, unsigned long)
uint64_t get_ext_tip(usg_t *g, uint64_t *seq, uint64_t s, uint64_t e, asg64_v *buf, asg64_v *set, uint8_t *f, uint64_t max_ext)
{
    uint64_t bn = buf->n, sn = set->n, v, k, nv, z, n_ext = 0, i, kv; usg_arc_t *av;
    for (k = s + 1; k < e; k++) {///note: here is [s, e]
        v = seq[k]; av = usg_arc_a(g, v); nv = usg_arc_n(g, v);
        for (z = 0; z < nv; z++) {
            if(av[z].del || f[av[z].v^1]) continue;
            kv_push(uint64_t, *buf, av[z].v);
        }

        v = seq[k]^1; av = usg_arc_a(g, v); nv = usg_arc_n(g, v);
        for (z = 0; z < nv; z++) {
            if(av[z].del || f[av[z].v^1]) continue;
            kv_push(uint64_t, *buf, av[z].v);
        }
    }

    v = seq[s]; av = usg_arc_a(g, v); nv = usg_arc_n(g, v);
    for (z = 0; z < nv; z++) {
        if(av[z].del || f[av[z].v^1]) continue;
        kv_push(uint64_t, *buf, av[z].v);
    }

    v = seq[e]^1; av = usg_arc_a(g, v); nv = usg_arc_n(g, v);
    for (z = 0; z < nv; z++) {
        if(av[z].del || f[av[z].v^1]) continue;
        kv_push(uint64_t, *buf, av[z].v);
    }


    while (buf->n > bn && n_ext < max_ext) {
        v = buf->a[--buf->n]; if(f[v]) continue;
        av = usg_arc_a(g, v^1); nv = usg_arc_n(g, v^1);
        for (i = kv = 0; i < nv && kv < 1; i++) {
            if (av[i].del || f[av[i].v^1]) continue;
            kv++; 
        }
        if(kv > 0) continue;
        n_ext += g->a[v>>1].occ; 
        if(!(f[v])) {
            f[v] = 1; kv_push(uint64_t, *set, v);
        }
        if(!(f[v^1])) {
            f[v^1] = 1; kv_push(uint64_t, *set, (v^1));
        }

        av = usg_arc_a(g, v); nv = usg_arc_n(g, v);
        for (i = 0; i < nv; i++) {
            if (av[i].del || f[av[i].v^1]) continue;
            kv_push(uint64_t, *buf, av[i].v);
        }    
    }
    buf->n = bn;
    for (k = sn; k < set->n; k++) f[set->a[k]] = 0;
    return n_ext;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %r14
movq %rcx, 0x8(%rsp)
movq %rdx, %r15
movq %rsi, %r13
movq %rdi, 0x18(%rsp)
movq 0x70(%rsp), %rbp
movq (%r8), %rax
movq %rax, 0x20(%rsp)
movq %r9, 0x30(%rsp)
movq (%r9), %rax
movq %rax, 0x28(%rsp)
movq %rdx, 0x10(%rsp)
incq %r15
movq 0x18(%rsp), %rax
movq (%rax), %rax
cmpq 0x8(%rsp), %r15
jae 0x1cc5b5
movq (%r13,%r15,8), %rcx
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
imulq $0x78, %rdx, %rdx
addq %rdx, %rax
imulq $0x18, %rcx, %rcx
movq 0x10(%rcx,%rax), %r12
movq 0x20(%rcx,%rax), %rbx
addq $0x8, %rbx
subq $0x1, %r12
jb 0x1cc51b
cmpl $0x0, 0x4(%rbx)
js 0x1cc515
movl (%rbx), %ecx
movq %rcx, %rax
xorq $0x1, %rax
cmpb $0x0, (%rbp,%rax)
jne 0x1cc515
movq (%r14), %rdx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rdx
jne 0x1cc508
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movl (%rbx), %ecx
movq (%r14), %rdx
movl %ecx, %ecx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r14)
movq %rcx, (%rax,%rdx,8)
addq $0x20, %rbx
jmp 0x1cc4b8
movq (%r13,%r15,8), %rax
movl %eax, %ecx
notl %ecx
shrq %rax
andl $0x1, %ecx
imulq $0x78, %rax, %rax
movq 0x18(%rsp), %rdx
addq (%rdx), %rax
imulq $0x18, %rcx, %rcx
movq 0x10(%rcx,%rax), %rbx
movq 0x20(%rcx,%rax), %r12
addq $0x8, %r12
subq $0x1, %rbx
jb 0x1cc47b
cmpl $0x0, 0x4(%r12)
js 0x1cc5af
movl (%r12), %ecx
movq %rcx, %rax
xorq $0x1, %rax
cmpb $0x0, (%rbp,%rax)
jne 0x1cc5af
movq (%r14), %rdx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rdx
jne 0x1cc5a2
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movl (%r12), %ecx
movq (%r14), %rdx
movl %ecx, %ecx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r14)
movq %rcx, (%rax,%rdx,8)
addq $0x20, %r12
jmp 0x1cc548
movq 0x10(%rsp), %rcx
movq (%r13,%rcx,8), %rcx
movq %rcx, %rdx
shrq %rdx
andl $0x1, %ecx
imulq $0x78, %rdx, %rdx
addq %rdx, %rax
imulq $0x18, %rcx, %rcx
movq 0x10(%rcx,%rax), %r15
movq 0x20(%rcx,%rax), %rbx
addq $0x8, %rbx
subq $0x1, %r15
jb 0x1cc644
cmpl $0x0, 0x4(%rbx)
js 0x1cc63e
movl (%rbx), %ecx
movq %rcx, %rax
xorq $0x1, %rax
cmpb $0x0, (%rbp,%rax)
jne 0x1cc63e
movq (%r14), %rdx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rdx
jne 0x1cc631
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movl (%rbx), %ecx
movq (%r14), %rdx
movl %ecx, %ecx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r14)
movq %rcx, (%rax,%rdx,8)
addq $0x20, %rbx
jmp 0x1cc5e1
movq 0x8(%rsp), %rax
movq (%r13,%rax,8), %rax
movl %eax, %ecx
notl %ecx
shrq %rax
andl $0x1, %ecx
imulq $0x78, %rax, %rax
movq 0x18(%rsp), %rdx
addq (%rdx), %rax
imulq $0x18, %rcx, %rcx
movq 0x10(%rcx,%rax), %r15
movq 0x20(%rcx,%rax), %rbx
addq $0x8, %rbx
subq $0x1, %r15
jb 0x1cc6d9
cmpl $0x0, 0x4(%rbx)
js 0x1cc6d3
movl (%rbx), %ecx
movq %rcx, %rax
xorq $0x1, %rax
cmpb $0x0, (%rbp,%rax)
jne 0x1cc6d3
movq (%r14), %rdx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rdx
jne 0x1cc6c6
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movl (%rbx), %ecx
movq (%r14), %rdx
movl %ecx, %ecx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r14)
movq %rcx, (%rax,%rdx,8)
addq $0x20, %rbx
jmp 0x1cc676
xorl %r12d, %r12d
cmpq 0x78(%rsp), %r12
movq 0x30(%rsp), %rbx
jae 0x1cc8d3
movq (%r14), %rdx
cmpq 0x20(%rsp), %rdx
jbe 0x1cc8d3
movq 0x10(%r14), %rcx
leaq -0x1(%rdx), %rax
movq %rax, (%r14)
movq -0x8(%rcx,%rdx,8), %r15
cmpb $0x0, (%rbp,%r15)
movq %rax, %rdx
jne 0x1cc6ef
movq 0x18(%rsp), %rcx
movq (%rcx), %rcx
movq %r15, %r13
xorq $0x1, %r13
movq %r15, %rdx
shrq %rdx
movl %r13d, %esi
andl $0x1, %esi
imulq $0x78, %rdx, %r10
leaq (%rcx,%r10), %rdi
imulq $0x18, %rsi, %rsi
movq 0x10(%rsi,%rdi), %rdx
movq 0x20(%rsi,%rdi), %rsi
addq $0xc, %rsi
xorl %edi, %edi
xorl %r8d, %r8d
cmpq %rdx, %rdi
jae 0x1cc781
testq %r8, %r8
jne 0x1cc781
cmpl $0x0, (%rsi)
js 0x1cc775
movl -0x4(%rsi), %r9d
xorq $0x1, %r9
xorl %r8d, %r8d
cmpb $0x0, (%rbp,%r9)
sete %r8b
jmp 0x1cc778
xorl %r8d, %r8d
incq %rdi
addq $0x20, %rsi
jmp 0x1cc74f
movq %rax, %rdx
testq %r8, %r8
jne 0x1cc6ef
movl 0x4(%rcx,%r10), %esi
movb $0x1, (%rbp,%r15)
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x1cc7de
movq %rsi, 0x10(%rsp)
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
movq %r10, 0x8(%rsp)
callq 0x2370
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %r10
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
movq %r15, (%rax,%rcx,8)
cmpb $0x0, (%rbp,%r13)
jne 0x1cc848
movb $0x1, (%rbp,%r13)
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x1cc83d
movq %rsi, 0x10(%rsp)
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
movq %r10, 0x8(%rsp)
callq 0x2370
movq 0x10(%rsp), %rsi
movq 0x8(%rsp), %r10
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
movq %r13, (%rax,%rcx,8)
addq %rsi, %r12
andl $0x1, %r15d
movq 0x18(%rsp), %rax
addq (%rax), %r10
imulq $0x18, %r15, %rax
movq 0x10(%rax,%r10), %rbx
movq 0x20(%rax,%r10), %r15
addq $0x8, %r15
subq $0x1, %rbx
jb 0x1cc6dc
cmpl $0x0, 0x4(%r15)
js 0x1cc8cd
movl (%r15), %ecx
movq %rcx, %rax
xorq $0x1, %rax
cmpb $0x0, (%rbp,%rax)
jne 0x1cc8cd
movq (%r14), %rdx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rdx
jne 0x1cc8c0
leaq (%rdx,%rdx), %rsi
testq %rdx, %rdx
pushq $0x2
popq %rcx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movl (%r15), %ecx
movq (%r14), %rdx
movl %ecx, %ecx
leaq 0x1(%rdx), %rsi
movq %rsi, (%r14)
movq %rcx, (%rax,%rdx,8)
addq $0x20, %r15
jmp 0x1cc869
movq 0x20(%rsp), %rax
movq %rax, (%r14)
movq 0x28(%rsp), %rcx
cmpq (%rbx), %rcx
jae 0x1cc8f7
movq 0x10(%rbx), %rax
movq (%rax,%rcx,8), %rax
movb $0x0, (%rbp,%rax)
incq %rcx
jmp 0x1cc8e0
movq %r12, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq