// File: /workspace/github_cpp_makefile_star2_O1/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 $0xd8, %rsp
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %r15
movl 0x8(%rdi), %ebp
addl %ebp, %ebp
xorl %eax, %eax
leaq 0xa0(%rsp), %rcx
movq %rax, 0x10(%rcx)
xorps %xmm0, %xmm0
movaps %xmm0, (%rcx)
leaq 0xc0(%rsp), %rdx
movq %rax, 0x10(%rdx)
movaps %xmm0, (%rdx)
testq %r13, %r13
movq %r13, %r12
cmoveq %rcx, %r12
testq %r14, %r14
cmovneq %r14, %rdx
movq %rdx, 0x28(%rsp)
movq %rax, (%rdx)
movq %rax, (%r12)
movq %rax, 0x90(%rsp)
movaps %xmm0, 0x80(%rsp)
movaps %xmm0, 0x70(%rsp)
movaps %xmm0, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movaps %xmm0, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
movl $0x1c, %esi
movq %rbp, %rdi
callq 0x2120
movq %rax, 0x30(%rsp)
testq %rbx, %rbx
movq %r12, 0x8(%rsp)
je 0x20c35a
movq (%rbx), %r12
jmp 0x20c36d
leaq 0x30(%rsp), %rsi
movq %r15, %rdi
movq %r12, %rdx
callq 0x20a800
movq %rax, %r12
movl $0x1, %esi
movq %rbp, %rdi
callq 0x2120
testq %r12, %r12
je 0x20c676
movq %rax, %rbx
movq %r12, 0x10(%rsp)
movq %r13, 0x18(%rsp)
movq %r14, 0x20(%rsp)
testq %rbp, %rbp
movq 0x8(%rsp), %r9
je 0x20c480
xorl %r14d, %r14d
leaq 0x30(%rsp), %r13
movb $0x1, %r12b
cmpb $0x0, (%rbx,%r14)
je 0x20c3c2
incq %r14
cmpq %rbp, %r14
jne 0x20c3ae
jmp 0x20c480
movl %r14d, %eax
shrl %eax
imulq $0x78, %rax, %rax
addq (%r15), %rax
movl %r14d, %ecx
andl $0x1, %ecx
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rax,%rcx,8), %rdx
testl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
je 0x20c3b5
cmpb $0x0, 0x70(%rax)
jne 0x20c3b5
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 0x20c3f8
cmpl $0x2, %edx
jb 0x20c3b5
movq %r15, %rdi
movl %r14d, %esi
movq 0x10(%rsp), %rdx
movq %r13, %rcx
callq 0x20a978
movq 0x8(%rsp), %r9
testq %rax, %rax
je 0x20c3b5
movq 0x68(%rsp), %rax
testq %rax, %rax
je 0x20c467
movq 0x48(%rsp), %rcx
movq 0x78(%rsp), %rdx
xorl %esi, %esi
movl (%rdx,%rsi,4), %edi
cmpq %rdi, %r14
je 0x20c45d
cmpl (%rcx), %edi
je 0x20c45d
movq %rdi, %r8
xorq $0x1, %r8
movb %r12b, (%rbx,%r8)
movb %r12b, (%rbx,%rdi)
incq %rsi
movl %esi, %edi
cmpq %rdi, %rax
ja 0x20c442
movb $0x2, (%rbx,%r14)
movq 0x48(%rsp), %rax
movl (%rax), %eax
xorq $0x1, %rax
movb $0x3, (%rbx,%rax)
jmp 0x20c3b5
movq $0x0, (%r9)
testq %rbp, %rbp
je 0x20c62f
movq 0x18(%rsp), %rax
testq %rax, %rax
movq %rax, %rcx
leaq 0xa0(%rsp), %rax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rsp)
xorl %r14d, %r14d
cmpb $0x2, (%rbx,%r14)
jb 0x20c623
movl %r14d, %eax
xorl $0x1, %eax
movq (%r15), %rcx
movl %eax, %edx
movl %edx, %edi
shrl %edi
movl %edx, %r8d
andl $0x1, %r8d
imulq $0x78, %rdi, %rdi
addq %rcx, %rdi
leaq (%r8,%r8,2), %r8
movl 0x10(%rdi,%r8,8), %r9d
testq %r9, %r9
je 0x20c595
movq 0x20(%rdi,%r8,8), %rdi
movq %r9, %r8
shlq $0x5, %r8
xorl %r10d, %r10d
xorl %r11d, %r11d
movl 0xc(%rdi,%r10), %r12d
notl %r12d
shrl $0x1f, %r12d
addl %r12d, %r11d
addq $0x20, %r10
cmpq %r10, %r8
jne 0x20c4fb
cmpl $0x1, %r11d
jne 0x20c595
testq %r9, %r9
je 0x20c537
xorl %r9d, %r9d
cmpl $0x0, 0xc(%rdi,%r9)
js 0x20c52e
movl 0x8(%rdi,%r9), %esi
addq $0x20, %r9
cmpq %r9, %r8
jne 0x20c521
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 0x20c595
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 0x20c568
cmpl $0x1, %r10d
jne 0x20c595
movl %esi, %edx
cmpl %eax, %esi
jne 0x20c4c5
jmp 0x20c623
movl %edx, %r13d
cmpb $0x2, (%rbx,%r13)
jb 0x20c623
movq %r15, %rdi
movl %r14d, %esi
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x20b385
cmpl $-0x1, %eax
je 0x20c623
movl %eax, %r12d
movq 0x10(%rsp), %rcx
movq 0x8(%rcx), %rax
movq 0x8(%rsp), %rsi
cmpq %rax, (%rsi)
jne 0x20c5fd
leaq (%rax,%rax), %rsi
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rsi
movq %rsi, 0x8(%rcx)
movq 0x10(%rcx), %rdi
shlq $0x3, %rsi
callq 0x2370
movq 0x10(%rsp), %rcx
movq 0x8(%rsp), %rsi
movq %rax, 0x10(%rcx)
notl %r12d
shlq $0x20, %r12
orq %r14, %r12
movq 0x10(%rcx), %rax
movq (%rsi), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rsi)
movq %r12, (%rax,%rcx,8)
xorl %eax, %eax
movb %al, (%rbx,%r13)
movb %al, (%rbx,%r14)
incq %r14
cmpq %rbp, %r14
jne 0x20c4af
movq 0x18(%rsp), %r13
testq %r13, %r13
leaq 0xa0(%rsp), %rax
cmovneq %r13, %rax
movq 0x10(%rax), %rdi
movq 0x8(%rsp), %rbx
movq (%rbx), %rax
leaq (%rdi,%rax,8), %rsi
callq 0x1e3b6a
movq %r15, %rdi
xorl %esi, %esi
movq %rbx, %rdx
movq 0x28(%rsp), %rcx
callq 0x20bf93
testl %eax, %eax
sete %bl
movq 0x20(%rsp), %r14
jmp 0x20c678
movb $0x1, %bl
movq 0x30(%rsp), %rdi
callq 0x2220
movq 0x48(%rsp), %rdi
callq 0x2220
movq 0x60(%rsp), %rdi
callq 0x2220
movq 0x78(%rsp), %rdi
callq 0x2220
movq 0x90(%rsp), %rdi
callq 0x2220
testb %bl, %bl
jne 0x20c6ce
leaq 0x7e0a0(%rip), %rax     # 0x28a758
movl 0x7c(%rax), %edi
movq 0x8(%r15), %rcx
leaq -0x43de(%rip), %rsi     # 0x2082e8
movq %r15, %rdx
callq 0x1047b4
testq %r13, %r13
jne 0x20c6e0
movq 0xb0(%rsp), %rdi
callq 0x2220
testq %r14, %r14
jne 0x20c6f2
movq 0xd0(%rsp), %rdi
callq 0x2220
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq