// File: /workspace/github_cpp_makefile_star2_O2/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 0x1d02b5
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 %rbx, (%rsp)
movq %r8, (%rbx)
movq 0x8(%rbp), %rdx
shlq $0x3, %rdx
xorl %ebx, %ebx
movq %r13, %rdi
xorl %esi, %esi
callq 0x20e0
cmpq %r15, %rbx
je 0x1d0308
movq (%r12,%rbx,8), %rax
movl %eax, %ecx
cmpq $0x2, %rcx
jb 0x1d03fd
shrq $0x20, %rax
addq %rax, %rcx
cmpq %rcx, %rax
jae 0x1d0303
movq (%r14,%rax,8), %rdx
andq $-0x2, %rdx
incq (%r13,%rdx,4)
incq %rax
jmp 0x1d02ec
incq %rbx
jmp 0x1d02d0
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x8(%rbp), %rdx
cmpq %rdx, %rcx
jae 0x1d0331
movq (%r13,%rcx,8), %rdx
movq %rax, %rsi
shlq $0x20, %rsi
orq %rdx, %rsi
movq %rsi, (%r13,%rcx,8)
addq %rdx, %rax
incq %rcx
jmp 0x1d030c
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpq %rdx, %rax
jae 0x1d0369
movq (%r13,%rax,8), %rsi
movq %rsi, %rdi
andq %rcx, %rdi
je 0x1d0364
shrq $0x20, %rsi
shlq $0x3, %rsi
movq (%rsp), %rdx
addq 0x10(%rdx), %rsi
andq $0x0, -0x8(%rsi,%rdi,8)
movq 0x8(%rbp), %rdx
incq %rax
jmp 0x1d0338
xorl %eax, %eax
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq (%rsp), %rbp
cmpq %r15, %rax
je 0x1d03ee
movq (%r12,%rax,8), %rdx
movl %edx, %esi
cmpq $0x2, %rsi
jb 0x1d041c
shrq $0x20, %rdx
addq %rdx, %rsi
movq 0x10(%rbp), %rdi
movq %rax, %r8
shlq $0x20, %r8
cmpq %rsi, %rdx
jae 0x1d03e9
movq (%r14,%rdx,8), %r9
andq $-0x2, %r9
movq (%r13,%r9,4), %r9
movq %r9, %r10
andq %rcx, %r10
je 0x1d03e4
shrq $0x20, %r9
leaq (%rdi,%r9,8), %r11
leaq (%r11,%r10,8), %r9
addq $-0x8, %r9
decq %r10
movq (%r9), %rbx
cmpq %r10, %rbx
je 0x1d03db
leaq 0x1(%rbx), %r10
movq %r10, (%r9)
leaq (%r11,%rbx,8), %r9
movq %rdx, %r10
orq %r8, %r10
movq %r10, (%r9)
incq %rdx
jmp 0x1d039b
incq %rax
jmp 0x1d0374
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2a7c7(%rip), %rdi     # 0x1fabcb
leaq 0x270ce(%rip), %rsi     # 0x1f74d9
leaq 0x2aedf(%rip), %rcx     # 0x1fb2f1
movl $0x36bb, %edx           # imm = 0x36BB
callq 0x2110
leaq 0x2a7a8(%rip), %rdi     # 0x1fabcb
leaq 0x270af(%rip), %rsi     # 0x1f74d9
leaq 0x2aec0(%rip), %rcx     # 0x1fb2f1
movl $0x36cb, %edx           # imm = 0x36CB
callq 0x2110