// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: gl_ug2rg_gen(asg_t const*, ul_vec_t*, ma_ug_t*, mg_lchain_t*, vec_mg_lchain_t*, long, long, kv_ul_ov_t*, kv_ul_ov_t*)
void gl_ug2rg_gen(const asg_t *rg, ul_vec_t *rch, ma_ug_t *ug, mg_lchain_t *uo, vec_mg_lchain_t *res, int64_t tOff, 
int64_t ulid, kv_ul_ov_t *raw_idx, kv_ul_ov_t *raw_chn)
{
	// fprintf(stderr, "\n[M::%s::] uo->qs:%d, uo->qe:%d\n", __func__, uo->qs, uo->qe);
	///uo is a unitig alignment
	ma_utg_t *u = &(ug->u.a[uo->v>>1]); int64_t res_n0 = res->n;
	uint64_t rs = uo->rs, re = uo->re, i, l; utg_ct_t p; 

	for (i = l = 0; i < u->n; i++) {
		p.x = u->a[i]>>32; p.s = l; p.e = l + Get_READ_LENGTH(R_INF, (u->a[i]>>33));
		l += (uint32_t)u->a[i];
		if(p.e <= rs) continue; 
		if(p.s >= re) break;
		
		assert(extract_rovlp_by_ug(&p, uo, res, tOff));
		// if(!extract_rovlp_by_ug(&p, uo, res, tOff)) {
		// 	fprintf(stderr, "[M::%s::ulid::%ld]u_rs->%lu, u_re->%lu, p.s->%u, p.e->%u\n", __func__, ulid, rs, re, p.s, p.e); 
		// 	exit(1);
		// }
		res->a[res->n-1].score = uo->v; res->a[res->n-1].cnt = i;
		// fprintf(stderr, "[M::%s::]u_rs->%lu, u_re->%lu, p.s->%u, p.e->%u\n", __func__, rs, re, p.s, p.e); 

		// int64_t read_rs, read_re, read_qs, read_qe;
		// get_r_offset(ug, &(res->a[res->n-1]), &read_rs, &read_re, &read_qs, &read_qe);
		// fprintf(stderr, "\t\t\t(k->%u) r_rs->%ld, r_re->%ld, r_qs->%ld, r_qe->%ld\n", (uint32_t)res->n-1, read_rs, read_re, read_qs, read_qe); 
		///for res->a[res->n-1]
		///ts and te are the coordinates in unitig (res->a[res->n-1].score>>1), instead of HiFi read (res->a[res->n-1].v>>1)
		///qs and qe are the coordinates in UL, 
	}

	mg_lchain_t *a = res->a + res_n0, t; uint64_t a_n = res->n - res_n0; 
	if(uo->v&1) {
		for (i = 0; i < (a_n>>1); i++) {
			t = a[i]; a[i] = a[a_n-i-1]; a[a_n-i-1] = t;
		}
	}

	update_existing_anchors(rg, rch, ug, u, res, res_n0, uo, raw_idx, raw_chn);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %r9, 0x40(%rsp)
movq %r8, %r12
movq %rcx, %r14
movq %rsi, 0x28(%rsp)
movq %rdi, 0x20(%rsp)
movl 0x8(%rcx), %eax
shrl %eax
imulq $0x28, %rax, %r11
movq %rdx, 0x30(%rsp)
addq 0x10(%rdx), %r11
movq 0x8(%r8), %rax
movq %rax, 0x18(%rsp)
movslq 0xc(%rcx), %rbp
movslq 0x10(%rcx), %rax
movq %rax, 0x48(%rsp)
xorl %r13d, %r13d
leaq 0xcd305(%rip), %rsi     # 0x254230
xorl %r15d, %r15d
movq %r11, 0x38(%rsp)
movl 0x10(%r11), %eax
cmpq %rax, %r15
jae 0x186fdf
movq 0x18(%r11), %rax
movq (%rax,%r15,8), %rbx
movq %rbx, %rax
shrq $0x20, %rax
movl %eax, 0xc(%rsp)
movl %r13d, 0x10(%rsp)
movq 0x18(%rsi), %rax
movq %rbx, %rcx
shrq $0x21, %rcx
movq (%rax,%rcx,8), %rax
addq %r13, %rax
movl %eax, 0x14(%rsp)
movl %eax, %eax
cmpq %rbp, %rax
jbe 0x186fd4
movl %r13d, %eax
cmpq 0x48(%rsp), %rax
jae 0x186fdf
leaq 0xc(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
movq 0x40(%rsp), %rcx
callq 0x186a7d
testq %rax, %rax
je 0x1870a6
movl 0x8(%r14), %eax
imulq $0x28, 0x8(%r12), %rcx
movq (%r12), %rdx
movl %eax, -0xc(%rdx,%rcx)
movl %r15d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl -0x24(%rdx,%rcx), %esi
movl $0x80000000, %edi       # imm = 0x80000000
andl %edi, %esi
orl %eax, %esi
movl %esi, -0x24(%rdx,%rcx)
movq 0x38(%rsp), %r11
leaq 0xcd25c(%rip), %rsi     # 0x254230
addq %rbx, %r13
incq %r15
jmp 0x186f33
testb $0x1, 0x8(%r14)
movq 0x18(%rsp), %r9
jne 0x18702b
subq $0x8, %rsp
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %r11, %rcx
movq %r12, %r8
pushq 0xc8(%rsp)
pushq 0xc8(%rsp)
pushq %r14
callq 0x186b50
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r12), %rdx
imulq $0x28, %r9, %rax
addq %rdx, %rax
movq 0x8(%r12), %rcx
imulq $0x28, %rcx, %rsi
subq %r9, %rcx
shrq %rcx
addq %rsi, %rdx
addq $-0x28, %rdx
subq $0x1, %rcx
jb 0x186feb
movq 0x20(%rax), %rsi
movq %rsi, 0x70(%rsp)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movaps %xmm1, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq 0x20(%rdx), %rsi
movq %rsi, 0x20(%rax)
movups (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
movq 0x70(%rsp), %rsi
movq %rsi, 0x20(%rdx)
movaps 0x50(%rsp), %xmm0
movaps 0x60(%rsp), %xmm1
movups %xmm1, 0x10(%rdx)
movups %xmm0, (%rdx)
addq $-0x28, %rdx
addq $0x28, %rax
jmp 0x18704c
leaq 0x6db6f(%rip), %rdi     # 0x1f4c1c
leaq 0x6aa6f(%rip), %rsi     # 0x1f1b23
leaq 0x6db88(%rip), %rcx     # 0x1f4c43
movl $0x3c17, %edx           # imm = 0x3C17
callq 0x2110