// File: /workspace/github_cpp_makefile_star2_O1/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 %r8, %rbx
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbp
movq 0x40(%rsp), %r13
cmpq %r8, 0x8(%r9)
movq %r9, (%rsp)
jae 0x213d42
leaq -0x1(%rbx), %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(%r9)
movq 0x10(%r9), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq (%rsp), %r9
movq %rax, 0x10(%r9)
movq %rbx, (%r9)
movq 0x8(%rbp), %rdx
shlq $0x3, %rdx
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
testq %r15, %r15
je 0x213d92
xorl %eax, %eax
movq (%r12,%rax,8), %rcx
movl %ecx, %edx
cmpq $0x2, %rdx
jb 0x213e9e
shrq $0x20, %rcx
addq %rcx, %rdx
movq (%r14,%rcx,8), %rsi
andq $-0x2, %rsi
incq (%r13,%rsi,4)
incq %rcx
cmpq %rdx, %rcx
jb 0x213d75
incq %rax
cmpq %r15, %rax
jne 0x213d5e
cmpq $0x0, 0x8(%rbp)
je 0x213dbd
xorl %eax, %eax
xorl %ecx, %ecx
movq (%r13,%rax,8), %rdx
movq %rcx, %rsi
shlq $0x20, %rsi
orq %rdx, %rsi
movq %rsi, (%r13,%rax,8)
addq %rdx, %rcx
incq %rax
cmpq 0x8(%rbp), %rax
jb 0x213d9d
cmpq $0x0, 0x8(%rbp)
movq (%rsp), %rdi
je 0x213dfa
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq (%r13,%rax,8), %rdx
movq %rdx, %rsi
andq %rcx, %rsi
je 0x213df1
shrq $0x20, %rdx
shlq $0x3, %rdx
addq 0x10(%rdi), %rdx
movq $0x0, -0x8(%rdx,%rsi,8)
incq %rax
cmpq 0x8(%rbp), %rax
jb 0x213dcf
testq %r15, %r15
je 0x213e8f
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq (%r12,%rax,8), %rdx
movl %edx, %esi
cmpq $0x2, %rsi
jb 0x213ebd
shrq $0x20, %rdx
addq %rdx, %rsi
movq 0x10(%rdi), %rdi
movq %rax, %r8
shlq $0x20, %r8
movq (%r14,%rdx,8), %r9
andq $-0x2, %r9
movq (%r13,%r9,4), %r10
movq %r10, %r9
andq %rcx, %r9
je 0x213e77
shrq $0x20, %r10
leaq (%rdi,%r10,8), %r10
leaq -0x1(%r9), %rbp
movq -0x8(%r10,%r9,8), %r11
cmpq %rbp, %r11
jne 0x213e64
movq %rdx, %r11
orq %r8, %r11
movq %r11, -0x8(%r10,%r9,8)
jmp 0x213e77
movq %rdx, %rbp
orq %r8, %rbp
leaq 0x1(%r11), %rbx
movq %rbx, -0x8(%r10,%r9,8)
movq %rbp, (%r10,%r11,8)
incq %rdx
cmpq %rsi, %rdx
jb 0x213e2c
incq %rax
cmpq %r15, %rax
movq (%rsp), %rdi
jne 0x213e0a
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28a83(%rip), %rdi     # 0x23c928
leaq 0x25479(%rip), %rsi     # 0x239325
leaq 0x2919b(%rip), %rcx     # 0x23d04e
movl $0x36bb, %edx           # imm = 0x36BB
callq 0x2110
leaq 0x28a64(%rip), %rdi     # 0x23c928
leaq 0x2545a(%rip), %rsi     # 0x239325
leaq 0x2917c(%rip), %rcx     # 0x23d04e
movl $0x36cb, %edx           # imm = 0x36CB
callq 0x2110