// File: 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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x8(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movl %eax, -0x2c(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x58(%rbp)
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2100
leaq -0x88(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x2100
movq $0x0, -0x90(%rbp)
movq $0x0, -0x98(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x354456
movq -0x18(%rbp), %rax
movq %rax, -0x110(%rbp)
jmp 0x354463
leaq -0x70(%rbp), %rax
movq %rax, -0x110(%rbp)
jmp 0x354463
movq -0x110(%rbp), %rax
movq %rax, -0x90(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x354485
movq -0x20(%rbp), %rax
movq %rax, -0x118(%rbp)
jmp 0x354495
leaq -0x88(%rbp), %rax
movq %rax, -0x118(%rbp)
jmp 0x354495
movq -0x118(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x98(%rbp), %rax
movq $0x0, (%rax)
movq -0x90(%rbp), %rax
movq $0x0, (%rax)
leaq -0x100(%rbp), %rdi
xorl %esi, %esi
movl $0x68, %edx
callq 0x2100
movl -0x2c(%rbp), %eax
movl %eax, %edi
movl $0x1c, %esi
callq 0x2140
movq %rax, -0x100(%rbp)
cmpq $0x0, -0x10(%rbp)
je 0x3544fc
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x354517
movq -0x8(%rbp), %rdi
movq -0x90(%rbp), %rdx
leaq -0x100(%rbp), %rsi
callq 0x3519b0
movq %rax, -0x50(%rbp)
movq $0x0, -0x108(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, %edi
movl $0x1, %esi
callq 0x2140
movq %rax, -0x108(%rbp)
cmpq $0x0, -0x50(%rbp)
jbe 0x3548fd
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x354719
movq -0x108(%rbp), %rax
movl -0x24(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x0, %eax
je 0x35456e
jmp 0x35470b
movq -0x8(%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, -0x34(%rbp)
movq -0x8(%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, -0x58(%rbp)
cmpl $0x2, -0x34(%rbp)
jb 0x3545ed
movq -0x8(%rbp), %rax
movq (%rax), %rax
movl -0x24(%rbp), %ecx
shrl %ecx
movl %ecx, %ecx
imulq $0x78, %rcx, %rcx
addq %rcx, %rax
cmpb $0x0, 0x70(%rax)
je 0x3545f2
jmp 0x35470b
movl $0x0, -0x30(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x354637
movq -0x58(%rbp), %rax
movl -0x38(%rbp), %ecx
shlq $0x5, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
jne 0x35462a
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x35462c
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x354600
cmpl $0x2, -0x30(%rbp)
jae 0x354642
jmp 0x35470b
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
movq -0x50(%rbp), %rdx
leaq -0x100(%rbp), %rcx
callq 0x351c80
cmpq $0x0, %rax
je 0x354709
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpq -0xc8(%rbp), %rax
jae 0x3546e2
movq -0xb8(%rbp), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %eax
cmpl -0x24(%rbp), %eax
je 0x3546a0
movq -0xb8(%rbp), %rax
movl -0x38(%rbp), %ecx
movl (%rax,%rcx,4), %eax
movq -0xe8(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x3546a2
jmp 0x3546d7
movq -0x108(%rbp), %rax
movq -0xb8(%rbp), %rcx
movl -0x38(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movb $0x1, (%rax,%rcx)
movq -0x108(%rbp), %rax
movq -0xb8(%rbp), %rcx
movl -0x38(%rbp), %edx
movl (%rcx,%rdx,4), %ecx
movb $0x1, (%rax,%rcx)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x35466a
movq -0x108(%rbp), %rax
movl -0x24(%rbp), %ecx
movb $0x2, (%rax,%rcx)
movq -0x108(%rbp), %rax
movq -0xe8(%rbp), %rcx
movl (%rcx), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movb $0x3, (%rax,%rcx)
jmp 0x35470b
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x35454a
movq -0x90(%rbp), %rax
movq $0x0, (%rax)
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x3548ae
movq -0x108(%rbp), %rax
movl -0x24(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x1, %eax
jg 0x354752
jmp 0x3548a0
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
xorl $0x1, %esi
leaq -0x28(%rbp), %rdx
xorl %eax, %eax
movl %eax, %r9d
movq %r9, %rcx
movq %r9, %r8
movq $0x0, (%rsp)
callq 0x37d4d0
cmpl $0x7, %eax
je 0x35489e
movq -0x108(%rbp), %rax
movl -0x28(%rbp), %ecx
movzbl (%rax,%rcx), %eax
cmpl $0x1, %eax
jle 0x35489e
movq -0x8(%rbp), %rdi
movl -0x24(%rbp), %esi
movl -0x28(%rbp), %edx
xorl %ecx, %ecx
xorl %eax, %eax
movl %eax, %r8d
callq 0x3529b0
movl %eax, -0x3c(%rbp)
cmpl $-0x1, -0x3c(%rbp)
jne 0x3547bc
jmp 0x3548a0
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
subl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x90(%rbp), %rax
movq (%rax), %rax
movq -0x90(%rbp), %rcx
cmpq 0x8(%rcx), %rax
jne 0x354850
movq -0x90(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x354803
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rax
shlq %rax
movq %rax, -0x120(%rbp)
jmp 0x354811
movl $0x2, %eax
movq %rax, -0x120(%rbp)
jmp 0x354811
movq -0x120(%rbp), %rcx
movq -0x90(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x90(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x90(%rbp), %rax
movq 0x8(%rax), %rsi
shlq $0x3, %rsi
callq 0x2360
movq %rax, %rcx
movq -0x90(%rbp), %rax
movq %rcx, 0x10(%rax)
movl -0x3c(%rbp), %eax
movl %eax, %edx
shlq $0x20, %rdx
movl -0x24(%rbp), %eax
orq %rax, %rdx
movq -0x90(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x90(%rbp), %rsi
movq (%rsi), %rcx
movq %rcx, %rdi
addq $0x1, %rdi
movq %rdi, (%rsi)
movq %rdx, (%rax,%rcx,8)
movq -0x108(%rbp), %rax
movl -0x28(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movq -0x108(%rbp), %rax
movl -0x24(%rbp), %ecx
movb $0x0, (%rax,%rcx)
jmp 0x3548a0
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x35472e
movq -0x90(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x90(%rbp), %rax
movq 0x10(%rax), %rsi
movq -0x90(%rbp), %rax
movq (%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x30ed90
movq -0x8(%rbp), %rdi
movq -0x90(%rbp), %rdx
movq -0x98(%rbp), %rcx
xorl %esi, %esi
callq 0x354100
movl %eax, %eax
addq -0x48(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x100(%rbp), %rdi
callq 0x2210
movq -0xe8(%rbp), %rdi
callq 0x2210
movq -0xd0(%rbp), %rdi
callq 0x2210
movq -0xb8(%rbp), %rdi
callq 0x2210
movq -0xa0(%rbp), %rdi
callq 0x2210
cmpq $0x0, -0x48(%rbp)
je 0x354949
movq -0x8(%rbp), %rdi
callq 0x34d830
cmpq $0x0, -0x18(%rbp)
jne 0x354959
movq -0x60(%rbp), %rdi
callq 0x2210
cmpq $0x0, -0x20(%rbp)
jne 0x354969
movq -0x78(%rbp), %rdi
callq 0x2210
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopw %cs:(%rax,%rax)