// File: /workspace/github_cpp_makefile_star2_O3/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), %r13
leaq 0x1(%r13), %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), %r12
testq %r12, %r12
je 0x1e0b63
movq 0x48(%r14), %rax
xorl %ecx, %ecx
imulq $0x58, %rcx, %rsi
movq 0x20(%rax,%rsi), %rdx
testq %rdx, %rdx
je 0x1e0b5b
addq %rax, %rsi
addq $0x20, %rsi
movq 0x10(%rsi), %rsi
addq $0x20, %rsi
testb $0x40, (%rsi)
jne 0x1e0b52
movl -0x20(%rsi), %edi
incl (%rbx,%rdi,4)
addq $0x24, %rsi
decq %rdx
jne 0x1e0b47
incq %rcx
cmpq %r12, %rcx
jne 0x1e0b2a
testq %r15, %r15
je 0x1e0b7f
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 0x1e0b6c
jmp 0x1e0b81
xorl %edi, %edi
movq %rdi, 0x38(%r14)
movq %rdi, 0x30(%r14)
shlq $0x3, %rdi
callq 0x2280
movq %rax, 0x40(%r14)
testq %r13, %r13
je 0x1e0bc2
movl (%rbx), %edx
xorl %ecx, %ecx
movl 0x4(%rbx,%rcx,4), %esi
movl %esi, %edi
subl %edx, %edi
je 0x1e0bb8
movl %edx, %edx
leaq (%rax,%rdx,8), %rdx
movq $0x0, -0x8(%rdx,%rdi,8)
incq %rcx
movl %esi, %edx
cmpq %rcx, %r13
jne 0x1e0b9f
testq %r12, %r12
je 0x1e0c4e
movq 0x48(%r14), %rcx
xorl %edx, %edx
imulq $0x58, %rdx, %rsi
cmpq $0x0, 0x20(%rcx,%rsi)
je 0x1e0c46
addq %rcx, %rsi
addq $0x20, %rsi
movq 0x10(%rsi), %rdi
movq %rdx, %r8
shlq $0x20, %r8
addq $0x20, %rdi
xorl %r9d, %r9d
testb $0x40, (%rdi)
jne 0x1e0c3a
movl -0x20(%rdi), %r11d
movl (%rbx,%r11,4), %r10d
incl %r11d
movl (%rbx,%r11,4), %r11d
subl %r10d, %r11d
je 0x1e0c3a
leaq (%rax,%r10,8), %r14
leaq (%r14,%r11,8), %r10
addq $-0x8, %r10
decq %r11
movq (%r10), %r15
cmpq %r11, %r15
je 0x1e0c31
leaq 0x1(%r15), %r11
movq %r11, (%r10)
leaq (%r14,%r15,8), %r10
movq %r9, %r11
orq %r8, %r11
movq %r11, (%r10)
incq %r9
addq $0x24, %rdi
cmpq (%rsi), %r9
jb 0x1e0bf6
incq %rdx
cmpq %r12, %rdx
jne 0x1e0bd1
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq