// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/gfa_ut.cpp
// Function: gen_hybrid_aln_idx(usg_t*, unsigned long*, unsigned long, unsigned long*, unsigned long, asg64_v*, unsigned long*)
void gen_hybrid_aln_idx(usg_t *ng, uint64_t *int_idx, uint64_t int_idx_n, uint64_t *int_a, uint64_t int_an, asg64_v *b64, uint64_t *ridx)
{
    uint64_t k, i, l, m, v, s, e, *a, a_n; 
    kv_resize(uint64_t, *b64, int_an); b64->n = int_an; 
    memset(ridx, 0, sizeof((*ridx))*ng->n);
    for (k = 0; k < int_idx_n; k++) {///scan all integer contigs
        s = int_idx[k]>>32; e = s + ((uint32_t)int_idx[k]); assert(e > s + 1);//the length is at least 2
        for (i = s; i < e; i++) ridx[int_a[i]>>1]++;
    }

    for (k = l = 0; k < ng->n; k++) {
        m = ridx[k];
        ridx[k] = l; ridx[k] <<= 32; ridx[k] |= m;
        l += m;
    }

    for (k = 0; k < ng->n; k++) {
        a = b64->a + (ridx[k]>>32); a_n = (uint32_t)ridx[k];
        if(a_n) a[a_n-1] = 0;
    }

    for (k = 0; k < int_idx_n; k++) {
        s = int_idx[k]>>32; e = s + ((uint32_t)int_idx[k]); assert(e > s + 1);//the length is at least 2
        for (i = s; i < e; i++) {
            v = int_a[i]>>1;
            a = b64->a + (ridx[v]>>32); 
            a_n = (uint32_t)ridx[v];
            if(a_n) {
                if(a[a_n-1] == a_n-1) {
                    a[a_n-1] = (k<<32)|i; 
                } else {
                    a[a[a_n-1]++] = (k<<32)|i;
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %r9, %rbx
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbp
movq 0x40(%rsp), %r13
cmpq %r8, 0x8(%r9)
jae 0x21f1bf
leaq -0x1(%r8), %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%rbx)
movq 0x10(%rbx), %rdi
leaq 0x8(,%rcx,8), %rsi
movq %r8, (%rsp)
callq 0x2370
movq (%rsp), %r8
movq %rax, 0x10(%rbx)
movq %r8, (%rbx)
movq 0x8(%rbp), %rdx
shlq $0x3, %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
testq %r15, %r15
je 0x21f20f
xorl %eax, %eax
movq (%r12,%rax,8), %rcx
movl %ecx, %edx
cmpq $0x2, %rdx
jb 0x21f308
shrq $0x20, %rcx
addq %rcx, %rdx
movq (%r14,%rcx,8), %rsi
andq $-0x2, %rsi
incq (%r13,%rsi,4)
incq %rcx
cmpq %rdx, %rcx
jb 0x21f1f2
incq %rax
cmpq %r15, %rax
jne 0x21f1db
cmpq $0x0, 0x8(%rbp)
je 0x21f277
xorl %ecx, %ecx
xorl %edx, %edx
movq (%r13,%rcx,8), %rax
movq %rdx, %rsi
shlq $0x20, %rsi
orq %rax, %rsi
movq %rsi, (%r13,%rcx,8)
addq %rax, %rdx
incq %rcx
movq 0x8(%rbp), %rax
cmpq %rax, %rcx
jb 0x21f21a
testq %rax, %rax
je 0x21f277
xorl %ecx, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq (%r13,%rcx,8), %rsi
movq %rsi, %rdi
andq %rdx, %rdi
je 0x21f26f
shrq $0x20, %rsi
shlq $0x3, %rsi
addq 0x10(%rbx), %rsi
movq $0x0, -0x8(%rsi,%rdi,8)
movq 0x8(%rbp), %rax
incq %rcx
cmpq %rax, %rcx
jb 0x21f249
testq %r15, %r15
je 0x21f2f9
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq (%r12,%rax,8), %rdx
movl %edx, %esi
cmpq $0x2, %rsi
jb 0x21f327
shrq $0x20, %rdx
addq %rdx, %rsi
movq 0x10(%rbx), %rdi
movq %rax, %r8
shlq $0x20, %r8
movq (%r14,%rdx,8), %r9
andq $-0x2, %r9
movq (%r13,%r9,4), %r9
movq %r9, %r10
andq %rcx, %r10
je 0x21f2e9
shrq $0x20, %r9
leaq (%rdi,%r9,8), %r11
leaq (%r11,%r10,8), %r9
addq $-0x8, %r9
decq %r10
movq (%r9), %rbp
cmpq %r10, %rbp
je 0x21f2e0
leaq 0x1(%rbp), %r10
movq %r10, (%r9)
leaq (%r11,%rbp,8), %r9
movq %rdx, %r10
orq %r8, %r10
movq %r10, (%r9)
incq %rdx
cmpq %rsi, %rdx
jb 0x21f2a5
incq %rax
cmpq %r15, %rax
jne 0x21f283
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x298fd(%rip), %rdi     # 0x248c0c
leaq 0x262f3(%rip), %rsi     # 0x245609
leaq 0x2a015(%rip), %rcx     # 0x249332
movl $0x36bb, %edx           # imm = 0x36BB
callq 0x2110
leaq 0x298de(%rip), %rdi     # 0x248c0c
leaq 0x262d4(%rip), %rsi     # 0x245609
leaq 0x29ff6(%rip), %rcx     # 0x249332
movl $0x36cb, %edx           # imm = 0x36CB
callq 0x2110