// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: gl_rg2ug_gen(ul_vec_t*, kv_ul_ov_t*, ul_idx_t const*, unsigned long, unsigned long, long)
void gl_rg2ug_gen(ul_vec_t *r_cl, kv_ul_ov_t *u_cl, const ul_idx_t *uref, uint64_t is_el, uint64_t n_pchain, int64_t ulid)
{
	uint64_t k, a_k, a_n; uc_block_t *z; utg_rid_dt *a; ul_ov_t p;
	u_cl->n = 0;
	for (k = 0; k < r_cl->bb.n; k++) {
		z = &(r_cl->bb.a[k]);
		if(z->base) continue;
		if(is_el && (!(z->el))) continue;
		if(z->pchain == n_pchain) continue;
		a = get_r_ug_region(uref->r_ug, &a_n, z->hid);
		if(!a) continue;
		for (a_k = 0; a_k < a_n; a_k++) {
			// if(ulid == 14714) {
			// 	fprintf(stderr, "\n+[M::%s::]\tq::[%u, %u)\t%c\t%.*s(%u)\tt::[%u, %u)\n", __func__, z->qs, z->qe, "+-"[z->rev], 
			// 	(int)Get_NAME_LENGTH(R_INF, z->hid), Get_NAME(R_INF, z->hid), (uint32_t)Get_READ_LENGTH(R_INF, z->hid), 
			// 	z->ts, z->te);
			// 	fprintf(stderr, "*[M::%s::] utg%.6d%c(%u)\t%c\toff::%u\tpos::%u\n", __func__, 
			// 	(int32_t)(a[a_k].u>>1)+1, "lc"[uref->ug->u.a[a[a_k].u>>1].circ], uref->ug->u.a[a[a_k].u>>1].len, 
			// 	"+-"[a[a_k].u&1], a[a_k].off, a[a_k].pos);
			// }
			if(!rov2uov(z->hid, uref, &(a[a_k]), z, &p, 1, ulid)) continue;
			p.el = 1; p.tn <<= 1; p.tn |= p.rev; p.qn = k/**uref->r_ug->idx[z->hid] + a_k**/;//for linear chain
			kv_push(ul_ov_t, *u_cl, p);
			// if(ulid == 14714) {
			// 	fprintf(stderr, "[M::%s::]\tutg%.6dl(%c)\tq::[%d, %d)\tt::[%d, %d)\ttlen::%u\n", __func__, 
            //         (int32_t)(p->tn>>1)+1, "+-"[p->tn&1], p->qs, p->qe, 
            //         p->ts, p->te, uref->ug->g->seq[p->tn>>1].len);
			// }
			// if(k == 2) {
			// 	fprintf(stderr, "[M::%s::] p->ts:%u, p->te:%u, z->ts:%u, z->te:%u, a[a_k].off:%u\n", __func__, p->ts, p->te, z->ts, z->te, a[a_k].off);
			// }
			// fprintf(stderr, "-[M::%s::] %u\t%u\t%c\tutg%.6d%c(%u)\t%u\t%u\n", __func__, p->qs, p->qe, "+-"[p->rev], 
			// 				(int32_t)(p->tn>>1)+1, "lc"[uref->ug->u.a[p->tn>>1].circ], uref->ug->u.a[p->tn>>1].len, p->ts, p->te);
		}
	}
}

// Assembly:
movq $0x0, 0x8(%rsi)
movq 0x20(%rdi), %rax
testq %rax, %rax
je 0x1ce6a7
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %r15
movq %rsi, %r12
xorl %r13d, %r13d
movq %r8, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
testq %rcx, %rcx
setne %r11b
movq 0x30(%rdi), %r10
leaq (,%r13,8), %rdx
addq %r13, %rdx
movzbl 0x20(%r10,%rdx,4), %esi
testb %sil, %sil
setns %r9b
testb $0x40, %sil
jne 0x1ce68d
andb %r9b, %r11b
jne 0x1ce68d
andl $0x1f, %esi
cmpq %r8, %rsi
je 0x1ce68d
leaq (%r10,%rdx,4), %rbx
movq 0x28(%r15), %rdx
movl (%rbx), %esi
movq (%rdx), %r10
movl (%r10,%rsi,4), %r9d
movl 0x4(%r10,%rsi,4), %ebp
subl %r9d, %ebp
je 0x1ce68d
movq 0x18(%rdx), %rdx
testq %rdx, %rdx
je 0x1ce68d
leaq (%r9,%r9,2), %rax
leaq (%rdx,%rax,4), %r14
cmpl $0x1, %ebp
adcl $0x0, %ebp
movl (%rbx), %edi
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
leaq 0x2c(%rsp), %r8
movl $0x1, %r9d
callq 0x1ce41d
testq %rax, %rax
je 0x1ce66d
movl 0x44(%rsp), %eax
movl %eax, %ecx
orl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, 0x44(%rsp)
shldl $0x1, %eax, 0x38(%rsp)
movl %r13d, 0x2c(%rsp)
movq (%r12), %rax
movq 0x8(%r12), %rcx
cmpq 0x10(%r12), %rcx
jne 0x1ce646
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r12)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%r12)
movq 0x8(%r12), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r12)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups 0x2c(%rsp), %xmm0
movups 0x38(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
addq $0xc, %r14
decq %rbp
jne 0x1ce5c6
movq 0x10(%rsp), %rdi
movq 0x20(%rdi), %rax
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %rcx
incq %r13
cmpq %rax, %r13
jb 0x1ce54a
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq