// File: /workspace/github_cpp_makefile_star2_O1/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 $0x0, 0x8(%rsi)
cmpq $0x0, 0x20(%rdi)
je 0x1c46dd
movq %rdx, %r15
movq %rsi, %r12
xorl %r13d, %r13d
movq %rdi, 0x18(%rsp)
cmpq $0x0, 0x20(%rsp)
setne %sil
movq 0x30(%rdi), %rax
leaq (,%r13,8), %rcx
addq %r13, %rcx
movzbl 0x20(%rax,%rcx,4), %edx
testb %dl, %dl
setns %dil
testb $0x40, %dl
jne 0x1c46cb
andb %dil, %sil
jne 0x1c46cb
andl $0x1f, %edx
cmpq 0x10(%rsp), %rdx
je 0x1c46cb
leaq (%rax,%rcx,4), %rbx
movq 0x28(%r15), %rdx
movl (%rbx), %ecx
movq (%rdx), %rsi
movl (%rsi,%rcx,4), %eax
movl 0x4(%rsi,%rcx,4), %ecx
movl %ecx, %ebp
subl %eax, %ebp
jne 0x1c45f3
xorl %r14d, %r14d
jmp 0x1c45ff
leaq (%rax,%rax,2), %r14
shlq $0x2, %r14
addq 0x18(%rdx), %r14
testq %r14, %r14
je 0x1c46cb
cmpl %eax, %ecx
je 0x1c46cb
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 0x1c444e
testq %rax, %rax
je 0x1c46be
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 0x10(%r12), %rax
cmpq %rax, 0x8(%r12)
jne 0x1c468e
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r12)
movq (%r12), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%r12)
movq (%r12), %rax
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 0x1c4616
incq %r13
movq 0x18(%rsp), %rdi
cmpq 0x20(%rdi), %r13
jb 0x1c4590
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq