// File: 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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
movq %r9, -0x30(%rbp)
movq -0x10(%rbp), %rax
movq $0x0, 0x8(%rax)
movq $0x0, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq -0x8(%rbp), %rcx
cmpq 0x20(%rcx), %rax
jae 0x2cffd3
movq -0x8(%rbp), %rax
movq 0x30(%rax), %rax
imulq $0x24, -0x38(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x6, %al
andb $0x1, %al
cmpb $0x0, %al
je 0x2cfe32
jmp 0x2cffc2
cmpq $0x0, -0x20(%rbp)
je 0x2cfe4c
movq -0x50(%rbp), %rax
movb 0x20(%rax), %al
shrb $0x7, %al
cmpb $0x0, %al
jne 0x2cfe4c
jmp 0x2cffc2
movq -0x50(%rbp), %rax
movb 0x20(%rax), %al
andb $0x1f, %al
movzbl %al, %eax
cmpq -0x28(%rbp), %rax
jne 0x2cfe63
jmp 0x2cffc2
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x50(%rbp), %rax
movl (%rax), %eax
movl %eax, %edx
leaq -0x48(%rbp), %rsi
callq 0x2cf9e0
movq %rax, -0x58(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x2cfe8c
jmp 0x2cffc2
movq $0x0, -0x40(%rbp)
movq -0x40(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x2cffc0
movq -0x50(%rbp), %rax
movl (%rax), %eax
movl %eax, %edi
movq -0x18(%rbp), %rsi
movq -0x58(%rbp), %rdx
imulq $0xc, -0x40(%rbp), %rax
addq %rax, %rdx
movq -0x50(%rbp), %rcx
movq -0x30(%rbp), %rax
leaq -0x74(%rbp), %r8
movl $0x1, %r9d
movq %rax, (%rsp)
callq 0x2cfa60
cmpq $0x0, %rax
jne 0x2cfee0
jmp 0x2cffaf
movl -0x5c(%rbp), %eax
andl $0xbfffffff, %eax       # imm = 0xBFFFFFFF
orl $0x40000000, %eax       # imm = 0x40000000
movl %eax, -0x5c(%rbp)
movl -0x68(%rbp), %eax
shll %eax
movl %eax, -0x68(%rbp)
movl -0x5c(%rbp), %eax
shrl $0x1f, %eax
orl -0x68(%rbp), %eax
movl %eax, -0x68(%rbp)
movq -0x38(%rbp), %rax
movl %eax, -0x74(%rbp)
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2cff6f
movq -0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2cff39
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0x80(%rbp)
jmp 0x2cff44
movl $0x2, %eax
movq %rax, -0x80(%rbp)
jmp 0x2cff44
movq -0x80(%rbp), %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq -0x10(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0x74(%rbp), %rcx
movq %rcx, (%rax)
movq -0x6c(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x64(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x5c(%rbp), %ecx
movl %ecx, 0x18(%rax)
jmp 0x2cffaf
movq -0x40(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
jmp 0x2cfe94
jmp 0x2cffc2
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x2cfdf7
addq $0x90, %rsp
popq %rbp
retq
nopl (%rax)