// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: gen_ul_vec_rid_t(all_ul_t*, All_reads*, ma_ug_t*)
void gen_ul_vec_rid_t(all_ul_t *x, All_reads *rdb, ma_ug_t *ug)
{
	ul_vec_rid_t *ridx = &(x->ridx);
	uint64_t k, i, l, m, *a, a_n, idx_n; ul_vec_t *p = NULL;
	idx_n = (rdb?rdb->total_reads:ug->u.n);
	ridx->idx.n = ridx->idx.m = idx_n + 1; CALLOC(ridx->idx.a, ridx->idx.n);

	for (k = 0; k < x->n; k++) {///each UL read
		p = &(x->a[k]);
		for (i = 0; i < p->bb.n; i++) {
			if(p->bb.a[i].base) continue;
			ridx->idx.a[p->bb.a[i].hid]++;
		}
	}

	for (k = l = 0; k < ridx->idx.n; k++) {
		m = ridx->idx.a[k];
		ridx->idx.a[k] = l;
		l += m;
	}

	ridx->occ.n = ridx->occ.m = l; MALLOC(ridx->occ.a, ridx->occ.n);
	for (k = 0; k < idx_n; k++) {
		a = ridx->occ.a + ridx->idx.a[k];
		a_n = ridx->idx.a[k+1] - ridx->idx.a[k];
		if(a_n) a[a_n-1] = 0;
	}

	for (k = 0; k < x->n; k++) {
		p = &(x->a[k]);
		for (i = 0; i < p->bb.n; i++) {
			if(p->bb.a[i].base) continue;
			a = ridx->occ.a + ridx->idx.a[p->bb.a[i].hid];
			a_n = ridx->idx.a[p->bb.a[i].hid+1] - ridx->idx.a[p->bb.a[i].hid];
			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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movq %rdi, %r14
leaq 0x50(%rsi), %rax
testq %rsi, %rsi
cmoveq %rdx, %rax
movq (%rax), %r12
leaq 0x1(%r12), %r15
movq %r15, 0x20(%rdi)
movq %r15, 0x18(%rdi)
movl $0x4, %esi
movq %r15, %rdi
callq 0x2120
movq %rax, %rbx
movq %rax, 0x28(%r14)
movq 0x50(%r14), %rax
testq %rax, %rax
je 0x1d6c43
movq 0x48(%r14), %rcx
xorl %edx, %edx
imulq $0x58, %rdx, %rdi
movq 0x20(%rcx,%rdi), %rsi
testq %rsi, %rsi
je 0x1d6c3b
addq %rcx, %rdi
addq $0x20, %rdi
movq 0x10(%rdi), %rdi
addq $0x20, %rdi
testb $0x40, (%rdi)
jne 0x1d6c32
movl -0x20(%rdi), %r8d
incl (%rbx,%r8,4)
addq $0x24, %rdi
decq %rsi
jne 0x1d6c25
incq %rdx
cmpq %rax, %rdx
jne 0x1d6c08
testq %r15, %r15
je 0x1d6c5f
xorl %eax, %eax
xorl %edi, %edi
movl (%rbx,%rax,4), %ecx
movl %edi, (%rbx,%rax,4)
addq %rcx, %rdi
incq %rax
cmpq %rax, %r15
jne 0x1d6c4c
jmp 0x1d6c61
xorl %edi, %edi
movq %rdi, 0x38(%r14)
movq %rdi, 0x30(%r14)
shlq $0x3, %rdi
callq 0x2280
movq %rax, 0x40(%r14)
testq %r12, %r12
je 0x1d6c9f
xorl %ecx, %ecx
movl (%rbx,%rcx,4), %edx
movl 0x4(%rbx,%rcx,4), %esi
cmpl %edx, %esi
je 0x1d6c97
subl %edx, %esi
leaq (%rax,%rdx,8), %rdx
movq $0x0, -0x8(%rdx,%rsi,8)
incq %rcx
cmpq %rcx, %r12
jne 0x1d6c7d
movq 0x50(%r14), %rcx
testq %rcx, %rcx
je 0x1d6d3b
movq 0x48(%r14), %rdx
xorl %esi, %esi
imulq $0x58, %rsi, %rdi
cmpq $0x0, 0x20(%rdx,%rdi)
je 0x1d6d2f
addq %rdx, %rdi
addq $0x20, %rdi
movq 0x10(%rdi), %r8
movq %rsi, %r9
shlq $0x20, %r9
addq $0x20, %r8
xorl %r10d, %r10d
testb $0x40, (%r8)
jne 0x1d6d23
movl -0x20(%r8), %r11d
movl (%rbx,%r11,4), %r14d
incl %r11d
movl (%rbx,%r11,4), %r11d
subl %r14d, %r11d
je 0x1d6d23
leaq (%rax,%r14,8), %r14
leaq -0x1(%r11), %r12
movq -0x8(%r14,%r11,8), %r15
cmpq %r12, %r15
jne 0x1d6d10
movq %r10, %r15
orq %r9, %r15
movq %r15, -0x8(%r14,%r11,8)
jmp 0x1d6d23
movq %r10, %r12
orq %r9, %r12
leaq 0x1(%r15), %r13
movq %r13, -0x8(%r14,%r11,8)
movq %r12, (%r14,%r15,8)
incq %r10
addq $0x24, %r8
cmpq (%rdi), %r10
jb 0x1d6cd7
incq %rsi
cmpq %rcx, %rsi
jne 0x1d6cb2
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq