// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: u2g_hybrid_extend(usg_t*, unsigned long*, asg64_v*, asg64_v*)
void u2g_hybrid_extend(usg_t *ng, uint64_t* i_max_dist, asg64_v *in, asg64_v *ib)
{
    uint32_t v, w, n_vtx = ng->n<<1, n_arc, nv, i, mm;
    uint64_t n_pop = 0, max_dist; usg_arc_t *av = NULL; 
    asg64_v tx = {0,0,0}, tb = {0,0,0}, *ob = NULL, *ub = NULL; 
    ob = (in?(in):(&tx)); ub = (ib?(ib):(&tb)); ob->n = ub->n = 0;
    buf_t b; memset(&b, 0, sizeof(buf_t)); CALLOC(b.a, n_vtx);
    if(i_max_dist) max_dist = (*i_max_dist);
    else max_dist = usg_max_bub(ng, &b, ob);
    uint8_t* bs_flag = NULL; CALLOC(bs_flag, n_vtx);

    if(max_dist > 0) {
        for(v = 0; v < n_vtx; ++v) {
            if(bs_flag[v] != 0) continue;
            nv = usg_arc_n(ng, v); av = usg_arc_a(ng, v);
            if(nv < 2 || ng->a[v>>1].del) continue;
            for (i = n_arc = 0; i < nv; ++i) {
                if (!av[i].del) ++n_arc;
            }
            if (n_arc < 2) continue;
            if(usg_bub_pop1(ng, v, max_dist, &b)) {
                //beg is v, end is b.S.a[0]; note b.b include end, does not include beg
                for (i = 0; i < b.b.n; i++) {
                    if(b.b.a[i]==v || b.b.a[i]==b.S.a[0]) continue;
                    bs_flag[b.b.a[i]] = bs_flag[b.b.a[i]^1] = 1;
                }
                bs_flag[v] = 2; bs_flag[b.S.a[0]^1] = 3;
            }
        }

        for(v = ob->n = 0; v < n_vtx; ++v) {
            if(bs_flag[v] <= 1) continue;
            if(get_usg_unitig(ng, v^1, &w, NULL, NULL, NULL, NULL) != LOOP && bs_flag[w] > 1) {
                mm = get_junction_w(ng, v, w, 0, NULL);
                if(mm == (uint32_t)-1) continue;
                mm = ((uint32_t)-1) - mm;
                kv_push(uint64_t, *ob, ((((uint64_t)mm)<<32)|((uint64_t)v)));
                bs_flag[v] = bs_flag[w] = 0;
            }
        }

        radix_sort_srt64(ob->a, ob->a + ob->n); 
        n_pop += u2g_n_hybrid_thread(ng, 0, ob, ub);
    }

    free(b.a); free(b.S.a); free(b.T.a); free(b.b.a); free(b.e.a);
    if(n_pop) usg_cleanup(ng);
    if(!in) free(tx.a); if(!ib) free(tb.a);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rcx, %r13
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r15
movl 0x8(%rdi), %ebp
addl %ebp, %ebp
xorl %eax, %eax
leaq 0x30(%rsp), %rdx
movq %rax, 0x10(%rdx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rdx)
leaq 0xb0(%rsp), %rcx
movq %rax, 0x10(%rcx)
testq %r12, %r12
movq %r12, %r14
cmoveq %rdx, %r14
movaps %xmm0, (%rcx)
testq %r13, %r13
cmovneq %r13, %rcx
movq %rcx, 0x28(%rsp)
movq %rax, (%rcx)
movq %rax, (%r14)
movups %xmm0, 0xa0(%rsp)
movups %xmm0, 0x90(%rsp)
movups %xmm0, 0x80(%rsp)
movups %xmm0, 0x70(%rsp)
movups %xmm0, 0x60(%rsp)
movups %xmm0, 0x50(%rsp)
movl $0x1c, %esi
movq %rbp, %rdi
callq 0x2120
movq %rax, 0x48(%rsp)
testq %rbx, %rbx
movq %r14, (%rsp)
je 0x21768a
movq (%rbx), %r14
jmp 0x21769d
leaq 0x48(%rsp), %rsi
movq %r15, %rdi
movq %r14, %rdx
callq 0x215b80
movq %rax, %r14
movl $0x1, %esi
movq %rbp, %rdi
callq 0x2120
testq %r14, %r14
je 0x217951
testq %rbp, %rbp
je 0x217955
movq %rax, %rbx
movq %r12, 0x8(%rsp)
xorl %r12d, %r12d
cmpb $0x0, (%rbx,%r12)
je 0x2176db
incq %r12
cmpq %rbp, %r12
jne 0x2176c7
jmp 0x217798
movl %r12d, %eax
shrl %eax
imulq $0x78, %rax, %rax
addq (%r15), %rax
movl %r12d, %ecx
andl $0x1, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rax,%rcx,8), %rdx
testl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
je 0x2176ce
cmpb $0x0, 0x70(%rax)
jne 0x2176ce
movq 0x20(%rax,%rcx,8), %rax
movl %edx, %ecx
addq $0xc, %rax
xorl %edx, %edx
movl (%rax), %esi
notl %esi
shrl $0x1f, %esi
addl %esi, %edx
addq $0x20, %rax
decq %rcx
jne 0x217711
cmpl $0x2, %edx
jb 0x2176ce
movq %r15, %rdi
movl %r12d, %esi
movq %r14, %rdx
leaq 0x48(%rsp), %rcx
callq 0x215cfc
movb $0x1, %r9b
testq %rax, %rax
je 0x2176ce
movq 0x60(%rsp), %rax
movq 0x80(%rsp), %rcx
testq %rcx, %rcx
je 0x217784
movq 0x90(%rsp), %rdx
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
cmpq %rdi, %r12
je 0x21777a
cmpl (%rax), %edi
je 0x21777a
movq %rdi, %r8
xorq $0x1, %r8
movb %r9b, (%rbx,%r8)
movb %r9b, (%rbx,%rdi)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rcx
ja 0x21775f
movb $0x2, (%rbx,%r12)
movl (%rax), %eax
xorq $0x1, %rax
movb $0x3, (%rbx,%rax)
jmp 0x2176ce
movq (%rsp), %r14
movq $0x0, (%r14)
testl %ebp, %ebp
je 0x217964
movq %r13, 0x18(%rsp)
movq 0x8(%rsp), %rax
testq %rax, %rax
movq %rax, %rcx
leaq 0x30(%rsp), %rax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rsp)
xorl %r14d, %r14d
movq %r15, 0x20(%rsp)
cmpb $0x2, (%rbx,%r14)
jb 0x217937
movl %r14d, %eax
xorl $0x1, %eax
movq (%r15), %rcx
movl %eax, %edx
movl %edx, %edi
shrl %edi
movl %edx, %r9d
andl $0x1, %r9d
imulq $0x78, %rdi, %r8
addq %rcx, %r8
leaq (%r9,%r9,2), %r9
movl 0x10(%r8,%r9,8), %edi
testq %rdi, %rdi
je 0x2178af
movq 0x20(%r8,%r9,8), %r8
shlq $0x5, %rdi
xorl %r9d, %r9d
xorl %r10d, %r10d
movl 0xc(%r8,%r9), %r11d
notl %r11d
shrl $0x1f, %r11d
addl %r11d, %r10d
addq $0x20, %r9
cmpq %r9, %rdi
jne 0x21781a
cmpl $0x1, %r10d
jne 0x2178af
xorl %r9d, %r9d
cmpl $0x0, 0xc(%r8,%r9)
js 0x217848
movl 0x8(%r8,%r9), %esi
addq $0x20, %r9
cmpq %r9, %rdi
jne 0x21783b
movl %esi, %edi
notl %edi
movl %esi, %r8d
shrl %r8d
andl $0x1, %edi
imulq $0x78, %r8, %r8
addq %rcx, %r8
leaq (%rdi,%rdi,2), %r9
movl 0x10(%r8,%r9,8), %edi
testq %rdi, %rdi
je 0x2178af
movq 0x20(%r8,%r9,8), %r8
shlq $0x5, %rdi
xorl %r9d, %r9d
xorl %r10d, %r10d
movl 0xc(%r8,%r9), %r11d
notl %r11d
shrl $0x1f, %r11d
addl %r11d, %r10d
addq $0x20, %r9
cmpq %r9, %rdi
jne 0x217882
cmpl $0x1, %r10d
jne 0x2178af
movl %esi, %edx
cmpl %eax, %esi
jne 0x2177e7
jmp 0x217937
movl %edx, %r13d
cmpb $0x2, (%rbx,%r13)
jb 0x217937
movq %r15, %rdi
movl %r14d, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x2166ff
cmpl $-0x1, %eax
je 0x217937
movl %eax, %r12d
movq (%rsp), %r15
movq (%r15), %rcx
movq 0x10(%rsp), %rdx
movq 0x10(%rdx), %rax
cmpq 0x8(%rdx), %rcx
jne 0x217913
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rdx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x10(%rsp), %rcx
movq %rax, 0x10(%rcx)
movq (%r15), %rcx
notl %r12d
shlq $0x20, %r12
orq %r14, %r12
leaq 0x1(%rcx), %rdx
movq %rdx, (%r15)
movq %r12, (%rax,%rcx,8)
xorl %eax, %eax
movb %al, (%rbx,%r13)
movb %al, (%rbx,%r14)
movq 0x20(%rsp), %r15
incq %r14
cmpq %rbp, %r14
jne 0x2177d1
movq (%rsp), %r14
movq (%r14), %rax
movq 0x18(%rsp), %r13
jmp 0x217966
movb $0x1, %bl
jmp 0x21799b
movq (%rsp), %r14
movq $0x0, (%r14)
xorl %eax, %eax
jmp 0x21796b
xorl %eax, %eax
movq 0x8(%rsp), %r12
testq %r12, %r12
leaq 0x30(%rsp), %rcx
cmovneq %r12, %rcx
movq 0x10(%rcx), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x1ee586
movq %r15, %rdi
xorl %esi, %esi
movq %r14, %rdx
movq 0x28(%rsp), %rcx
callq 0x2172d6
testl %eax, %eax
sete %bl
movq 0x48(%rsp), %rdi
callq 0x2220
movq 0x60(%rsp), %rdi
callq 0x2220
movq 0x78(%rsp), %rdi
callq 0x2220
movq 0x90(%rsp), %rdi
callq 0x2220
movq 0xa8(%rsp), %rdi
callq 0x2220
testb %bl, %bl
jne 0x2179f4
leaq 0x7dd7a(%rip), %rax     # 0x295758
movl 0x7c(%rax), %edi
movq 0x8(%r15), %rcx
leaq -0x4209(%rip), %rsi     # 0x2137e3
movq %r15, %rdx
callq 0x108f2c
testq %r12, %r12
jne 0x217a03
movq 0x40(%rsp), %rdi
callq 0x2220
testq %r13, %r13
jne 0x217a15
movq 0xc0(%rsp), %rdi
callq 0x2220
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq