// File: /workspace/github_cpp_makefile_star2_O1/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, 0x48(%rsp)
movq %r8, %r15
movq %rcx, %r14
movq %rsi, 0x28(%rsp)
movq %rdi, 0x20(%rsp)
movq %rdx, 0x30(%rsp)
movq 0x10(%rdx), %rax
movl 0x8(%rcx), %ecx
shrl %ecx
leaq (%rcx,%rcx,4), %rcx
leaq (%rax,%rcx,8), %rcx
movq 0x8(%r8), %rax
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x10(%rcx)
je 0x1c9477
movslq 0xc(%r14), %r12
movslq 0x10(%r14), %rax
movq %rax, 0x40(%rsp)
xorl %r13d, %r13d
leaq 0xc1e65(%rip), %rdi     # 0x28b230
xorl %ebp, %ebp
movq %rcx, 0x38(%rsp)
movq 0x18(%rcx), %rax
movq (%rax,%r13,8), %rbx
movq %rbx, %rax
shrq $0x20, %rax
movl %eax, 0xc(%rsp)
movl %ebp, 0x10(%rsp)
movq 0x18(%rdi), %rax
movq %rbx, %rsi
shrq $0x21, %rsi
movq (%rax,%rsi,8), %rax
addq %rbp, %rax
movl %eax, 0x14(%rsp)
movl %eax, %eax
cmpq %r12, %rax
jbe 0x1c9465
movl %ebp, %eax
cmpq 0x40(%rsp), %rax
jae 0x1c9477
leaq 0xc(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
movq 0x48(%rsp), %rcx
callq 0x1c8e7f
testq %rax, %rax
je 0x1c9552
movl 0x8(%r14), %eax
movq (%r15), %rcx
movq 0x8(%r15), %rdx
leaq (%rdx,%rdx,4), %rdx
movl %eax, -0xc(%rcx,%rdx,8)
movl %r13d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl -0x24(%rcx,%rdx,8), %esi
movl $0x80000000, %edi       # imm = 0x80000000
andl %edi, %esi
orl %eax, %esi
movl %esi, -0x24(%rcx,%rdx,8)
movq 0x38(%rsp), %rcx
leaq 0xc1dcb(%rip), %rdi     # 0x28b230
addq %rbx, %rbp
incq %r13
movl 0x10(%rcx), %eax
cmpq %rax, %r13
jb 0x1c93d2
movq 0xc0(%rsp), %r10
movq 0xb8(%rsp), %rax
testb $0x1, 0x8(%r14)
movq 0x18(%rsp), %r9
je 0x1c9520
movq 0x8(%r15), %rsi
movq %rsi, %rbx
subq %r9, %rbx
cmpq $0x2, %rbx
jb 0x1c9520
movq (%r15), %rdi
leaq (%r9,%r9,4), %rdx
leaq (%rdi,%rdx,8), %rdx
shrq %rbx
cmpq $0x1, %rbx
adcq $0x0, %rbx
leaq (%rsi,%rsi,4), %rsi
leaq (%rdi,%rsi,8), %rsi
addq $-0x28, %rsi
movq 0x20(%rdx), %rdi
movq %rdi, 0x70(%rsp)
movups (%rdx), %xmm0
movups 0x10(%rdx), %xmm1
movaps %xmm1, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq 0x20(%rsi), %rdi
movq %rdi, 0x20(%rdx)
movups (%rsi), %xmm0
movups 0x10(%rsi), %xmm1
movups %xmm1, 0x10(%rdx)
movups %xmm0, (%rdx)
movq 0x70(%rsp), %rdi
movq %rdi, 0x20(%rsi)
movaps 0x50(%rsp), %xmm0
movaps 0x60(%rsp), %xmm1
movups %xmm1, 0x10(%rsi)
movups %xmm0, (%rsi)
addq $0x28, %rdx
addq $-0x28, %rsi
decq %rbx
jne 0x1c94c9
subq $0x8, %rsp
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
movq %r15, %r8
pushq %r10
pushq %rax
pushq %r14
callq 0x1c8f64
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6d52b(%rip), %rdi     # 0x236a84
leaq 0x6a42b(%rip), %rsi     # 0x23398b
leaq 0x6d544(%rip), %rcx     # 0x236aab
movl $0x3c17, %edx           # imm = 0x3C17
callq 0x2110