// File: /workspace/github_cpp_makefile_star2_O3/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, %r12
movq %rcx, %r11
movq 0x10(%rdx), %rax
movl 0x8(%rcx), %ecx
movl %ecx, %r9d
shrl %r9d
leaq (%r9,%r9,4), %r9
leaq (%rax,%r9,8), %r10
movq 0x8(%r8), %r9
movl 0x10(%r10), %eax
movq %r9, %rbx
testl %eax, %eax
movq %r10, 0x8(%rsp)
je 0x1d3359
movq %r9, 0x20(%rsp)
movq %rdi, 0x28(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdx, 0x38(%rsp)
movslq 0xc(%r11), %rbp
movslq 0x10(%r11), %rcx
movq %rcx, 0x40(%rsp)
leaq 0xc2fb0(%rip), %rcx     # 0x296230
movq 0x18(%rcx), %rcx
xorl %r13d, %r13d
xorl %r15d, %r15d
movq 0x18(%r10), %rdx
movq (%rdx,%r13,8), %rbx
movq %rbx, %rdx
shrq $0x20, %rdx
movl %edx, 0x14(%rsp)
movl %r15d, 0x18(%rsp)
movq %rbx, %rdx
shrq $0x21, %rdx
movq (%rcx,%rdx,8), %rdx
addq %r15, %rdx
movl %edx, 0x1c(%rsp)
movl %edx, %edx
cmpq %rbp, %rdx
jbe 0x1d332b
movl %r15d, %eax
cmpq 0x40(%rsp), %rax
jae 0x1d333c
leaq 0x14(%rsp), %rdi
movq %r11, %rsi
movq %r12, %rdx
movq 0x48(%rsp), %rcx
movq %r11, %r14
callq 0x1d2d4d
testq %rax, %rax
je 0x1d341c
movl 0x8(%r14), %eax
movq (%r12), %rcx
movq 0x8(%r12), %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)
leaq 0xc2f15(%rip), %rax     # 0x296230
movq 0x18(%rax), %rcx
movq 0x8(%rsp), %r10
movl 0x10(%r10), %eax
movq %r14, %r11
addq %rbx, %r15
incq %r13
movl %eax, %edx
cmpq %rdx, %r13
jb 0x1d328a
movq 0x8(%r12), %rbx
movl 0x8(%r11), %ecx
movq 0x38(%rsp), %rdx
movq 0x30(%rsp), %rsi
movq 0x28(%rsp), %rdi
movq 0x20(%rsp), %r9
movq 0xc0(%rsp), %r10
movq 0xb8(%rsp), %rax
testb $0x1, %cl
je 0x1d33f4
movq %rbx, %rcx
subq %r9, %rcx
cmpq $0x2, %rcx
jb 0x1d33f4
movq (%r12), %r14
leaq (%r9,%r9,4), %r15
leaq (%r14,%r15,8), %r15
shrq %rcx
leaq (%rbx,%rbx,4), %rbx
leaq (%r14,%rbx,8), %rbx
addq $-0x28, %rbx
movq 0x20(%r15), %r14
movq %r14, 0x70(%rsp)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movaps %xmm1, 0x60(%rsp)
movaps %xmm0, 0x50(%rsp)
movq 0x20(%rbx), %r14
movq %r14, 0x20(%r15)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%r15)
movups %xmm0, (%r15)
movq 0x70(%rsp), %r14
movq %r14, 0x20(%rbx)
movaps 0x50(%rsp), %xmm0
movaps 0x60(%rsp), %xmm1
movups %xmm1, 0x10(%rbx)
movups %xmm0, (%rbx)
addq $0x28, %r15
addq $-0x28, %rbx
decq %rcx
jne 0x1d3399
subq $0x8, %rsp
movq 0x10(%rsp), %rcx
movq %r12, %r8
pushq %r10
pushq %rax
pushq %r11
callq 0x1d2e30
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6f931(%rip), %rdi     # 0x242d54
leaq 0x6c831(%rip), %rsi     # 0x23fc5b
leaq 0x6f94a(%rip), %rcx     # 0x242d7b
movl $0x3c17, %edx           # imm = 0x3C17
callq 0x2110