// File: /workspace/github_cpp_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x10(%rsp)
movq %rcx, 0x20(%rsp)
movq %rdx, %r15
movq %rsi, %r12
andq $0x0, 0x8(%rsi)
xorl %ebx, %ebx
movq %rdi, 0x18(%rsp)
cmpq 0x20(%rdi), %rbx
jae 0x182920
cmpq $0x0, 0x20(%rsp)
setne %dl
movq 0x30(%rdi), %r14
imulq $0x24, %rbx, %rax
movzbl 0x20(%r14,%rax), %ecx
testb %cl, %cl
setns %sil
testb $0x40, %cl
jne 0x182913
andb %sil, %dl
jne 0x182913
andl $0x1f, %ecx
cmpq 0x10(%rsp), %rcx
je 0x182913
addq %rax, %r14
movq 0x28(%r15), %rcx
movl (%r14), %edx
movq (%rcx), %rsi
movl (%rsi,%rdx,4), %eax
movl 0x4(%rsi,%rdx,4), %r13d
subl %eax, %r13d
je 0x182913
movq 0x18(%rcx), %rbp
testq %rbp, %rbp
je 0x182913
imulq $0xc, %rax, %rax
addq %rax, %rbp
subq $0x1, %r13
jb 0x182913
movl (%r14), %edi
movq %r15, %rsi
movq %rbp, %rdx
movq %r14, %rcx
leaq 0x2c(%rsp), %r8
pushq $0x1
popq %r9
callq 0x182641
testq %rax, %rax
je 0x18290a
movl 0x44(%rsp), %eax
movl %eax, %ecx
orl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, 0x44(%rsp)
shldl $0x1, %eax, 0x38(%rsp)
movl %ebx, 0x2c(%rsp)
movq (%r12), %rax
movq 0x8(%r12), %rcx
cmpq 0x10(%r12), %rcx
jne 0x1828ea
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r12)
imulq $0x1c, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%r12)
movq 0x8(%r12), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r12)
imulq $0x1c, %rcx, %rcx
movups 0x2c(%rsp), %xmm0
movups 0x38(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
addq $0xc, %rbp
jmp 0x18286f
incq %rbx
movq 0x18(%rsp), %rdi
jmp 0x1827f6
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq