// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: u2g_hybrid_aln(ul_resolve_t*, usg_t*, asg64_v*, asg64_v*)
void u2g_hybrid_aln(ul_resolve_t *uidx, usg_t *ng, asg64_v *ob, asg64_v *ub)
{
    uint64_t k, m, i, x, *tmp, sn;
    ob->n = ub->n = 0;
    for (k = 0; k < uidx->str_b.n_thread; k++) {
        uidx->str_b.buf[k].res_dump.n = uidx->str_b.buf[k].u.n = uidx->str_b.buf[k].o.n = 0;
    }
    kt_for(uidx->str_b.n_thread, worker_integer_realign_g, uidx, uidx->uovl.i_ug->u.n);

    for (k = ob->n = ub->n = m = 0; k < uidx->str_b.n_thread; k++) {
        for (i = 0; i < uidx->str_b.buf[k].res_dump.n; i++) {
            x = uidx->str_b.buf[k].res_dump.a[i];
            kv_push(uint64_t, *ob, x);//aln details
            if(x&((uint64_t)0x8000000000000000)) {
                x -= ((uint64_t)0x8000000000000000); x >>= 32; x <<= 32;//seq_id
                x |= ob->n;//offset
                kv_push(uint64_t, *ub, x);///idx:: seq_id|offset_in_ob
            } else {
                m++;
            }
        }
    }

    radix_sort_srt64(ub->a, ub->a + ub->n);
    kv_resize(uint64_t, *ub, ub->n+m); tmp = ub->a + ub->n; m = 0;
    for (k = 0; k < ub->n; k++) {
        sn = ((uint32_t)(ob->a[((uint32_t)ub->a[k])-1]));
        memcpy(tmp + m, ob->a + ((uint32_t)ub->a[k]), sn*sizeof((*tmp))); 
        ub->a[k] = m; ub->a[k] <<= 32; ub->a[k] |= sn;//offset_in_ob|occ
        m += sn;
    }
    assert(m <= ob->n);
    memcpy(ob->a, tmp, m*sizeof((*tmp))); ob->n = m;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r14
movq %rdx, %rbx
xorl %eax, %eax
movq %rax, (%rcx)
movq %rax, (%rdx)
movq %rdi, 0x8(%rsp)
movq 0x1e0(%rdi), %rdi
testq %rdi, %rdi
je 0x21dda6
movq 0x8(%rsp), %rax
movq 0x1d8(%rax), %rax
addq $0x78, %rax
xorl %ecx, %ecx
movq %rdi, %rdx
movq %rcx, (%rax)
movq %rcx, 0x18(%rax)
movq %rcx, 0x288(%rax)
addq $0x328, %rax            # imm = 0x328
decq %rdx
jne 0x21dd8d
movq 0x8(%rsp), %r15
movq 0x230(%r15), %rax
movq (%rax), %rcx
leaq -0xa3(%rip), %rsi       # 0x21dd19
movq %r15, %rdx
callq 0x108f2c
xorl %r12d, %r12d
movq %r12, (%r14)
movq %r12, (%rbx)
movq 0x1e0(%r15), %rcx
testq %rcx, %rcx
je 0x21deea
movq 0x8(%rsp), %rax
movq 0x1d8(%rax), %rax
xorl %edx, %edx
xorl %r12d, %r12d
imulq $0x328, %rdx, %rbp      # imm = 0x328
cmpq $0x0, 0x300(%rax,%rbp)
je 0x21dede
movq %rdx, 0x10(%rsp)
xorl %r13d, %r13d
movq 0x310(%rax,%rbp), %rax
movq (%rax,%r13,8), %r15
movq (%rbx), %rcx
movq 0x10(%rbx), %rax
cmpq 0x8(%rbx), %rcx
jne 0x21de4c
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%rbx)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%rbx)
movq (%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%rbx)
movq %r15, (%rax,%rcx,8)
testq %r15, %r15
js 0x21de61
incq %r12
jmp 0x21deb0
movabsq $0x7fffffff00000000, %rax # imm = 0x7FFFFFFF00000000
andq %rax, %r15
orq (%rbx), %r15
movq (%r14), %rcx
movq 0x10(%r14), %rax
cmpq 0x8(%r14), %rcx
jne 0x21dea5
leaq (%rcx,%rcx), %rsi
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rsi
movq %rsi, 0x8(%r14)
shlq $0x3, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, (%r14)
movq %r15, (%rax,%rcx,8)
incq %r13
movq 0x8(%rsp), %rax
movq 0x1d8(%rax), %rax
cmpq 0x300(%rax,%rbp), %r13
jb 0x21de0c
movq 0x8(%rsp), %rcx
movq 0x1e0(%rcx), %rcx
movq 0x10(%rsp), %rdx
incq %rdx
cmpq %rcx, %rdx
jb 0x21ddee
movq (%r14), %rax
movq 0x10(%r14), %rdi
leaq (%rdi,%rax,8), %rsi
callq 0x1ee586
movq (%r14), %rcx
addq %rcx, %r12
movq 0x10(%r14), %rax
cmpq %r12, 0x8(%r14)
jae 0x21df5d
decq %r12
movq %r12, %rcx
shrq %rcx
orq %r12, %rcx
movq %rcx, %rdx
shrq $0x2, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x4, %rcx
orq %rdx, %rcx
movq %rcx, %rdx
shrq $0x8, %rdx
orq %rcx, %rdx
movq %rdx, %rcx
shrq $0x10, %rcx
orq %rdx, %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
leaq 0x8(,%rcx,8), %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, 0x10(%r14)
movq (%r14), %rcx
leaq (%rax,%rcx,8), %r15
testq %rcx, %rcx
je 0x21dfd6
xorl %r13d, %r13d
xorl %r12d, %r12d
movq %r12, %rbp
movq 0x10(%rbx), %rcx
movq (%rax,%r13,8), %rax
leal -0x1(%rax), %edx
movl (%rcx,%rdx,8), %r12d
leaq (%r15,%rbp,8), %rdi
movl %eax, %eax
leaq (%rcx,%rax,8), %rsi
leaq (,%r12,8), %rdx
callq 0x2160
movq 0x10(%r14), %rax
movq %rbp, %rcx
shlq $0x20, %rcx
orq %r12, %rcx
movq %rcx, (%rax,%r13,8)
addq %rbp, %r12
incq %r13
cmpq (%r14), %r13
jb 0x21df6c
cmpq (%rbx), %r12
jbe 0x21dfd9
leaq 0x2b1ab(%rip), %rdi     # 0x249169
leaq 0x27644(%rip), %rsi     # 0x245609
leaq 0x2b22b(%rip), %rcx     # 0x2491f7
movl $0x35d9, %edx           # imm = 0x35D9
callq 0x2110
xorl %r12d, %r12d
movq 0x10(%rbx), %rdi
leaq (,%r12,8), %rdx
movq %r15, %rsi
callq 0x2160
movq %r12, (%rbx)
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq