// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: ctg_rg2ug_gen(ma_utg_t*, kv_ul_ov_t*, ul_idx_t const*, unsigned long)
void ctg_rg2ug_gen(ma_utg_t *r_cl, kv_ul_ov_t *u_cl, const ul_idx_t *uref, uint64_t id)
{
	if(r_cl->n <= 0) return ;
	uint64_t k, i, m, l, is_push, vs, ls; ul_ov_t kp, lp, kp0; 
	u_cl->n = 0; kp.tn = kp.qn = kp0.tn = kp0.qn = ((uint32_t)-1); 

	k = 1; l = 0; ls = 0; vs = 0;
	get_unique_rctg_aln(uref, r_cl->a[l]>>32, l, ls, r_cl->len, &lp, NULL, ((uint32_t)-1)); ///get lp for l = 0
	vs += (uint32_t)(r_cl->a[l]);

	for (; k <= r_cl->n; k++) {
		is_push = 0;
		if(k < r_cl->n) {
			get_unique_rctg_aln(uref, r_cl->a[k]>>32, k, vs, r_cl->len, &kp, NULL, ((uint32_t)-1)); 
			if(cmp_shrink_ul_ov_t(&lp, &kp, k - l)) is_push = 1;
		} else {
			is_push = 1;
		}

		if(is_push) {
			kp0 = kp;
			if(k - l > 1) {
				for (i = l; i < k; i++) {///could be merged
					m = get_unique_rctg_aln(uref, r_cl->a[i]>>32, i, ls, r_cl->len, &kp, NULL, ((uint32_t)-1)); 
					assert(m == 1); assert(kp.tn == lp.tn); assert(kp.qn == lp.qn + i - l); assert(kp.sec == lp.sec + i - l);
					if(kp.qs < lp.qs) lp.qs = kp.qs; if(kp.qe > lp.qe) lp.qe = kp.qe;
					if(kp.ts < lp.ts) lp.ts = kp.ts; if(kp.te > lp.te) lp.te = kp.te;
					ls += (uint32_t)(r_cl->a[i]); 

					// if(id == 123) {
					// 	fprintf(stderr, "-0-[M::%s::]\tutg%.6dl(%c)\tq::[%d, %d)<l::%u>\tt::[%d, %d)<l::%u>\tsc::%d\n", __func__, 
					// 					(int32_t)(kp.tn>>1)+1, "+-"[kp.tn&1], kp.qs, kp.qe, kp.qe-kp.qs, kp.ts, kp.te, kp.te-kp.ts, kp.sec);
					// }
				}
				lp.sec = k - l;
				kv_push(ul_ov_t, *u_cl, lp);
			} else if(k - l == 1) {
				m = get_unique_rctg_aln(uref, r_cl->a[l]>>32, l, ls, r_cl->len, NULL, u_cl, 1); 
				// if(id == 123) {
				// 	fprintf(stderr, "-1-[M::%s::]\tutg%.6dl(%c)\tq::[%d, %d)<l::%u>\tt::[%d, %d)<l::%u>\tsc::%d\n", __func__, 
				// 						(int32_t)(kp.tn>>1)+1, "+-"[kp.tn&1], kp.qs, kp.qe, kp.qe-kp.qs, kp.ts, kp.te, kp.te-kp.ts, kp.sec);
				// }
			}

			l = k; lp = kp0; ls = vs;
		}

		if(k < r_cl->n) vs += (uint32_t)(r_cl->a[k]);
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
cmpl $0x0, 0x10(%rdi)
je 0x189bd2
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r15
andq $0x0, 0x8(%rsi)
leaq 0x64(%rsp), %rax
orl $-0x1, -0x10(%rax)
orl $-0x1, -0x4(%rax)
movq 0x18(%rdi), %rax
movl 0x4(%rax), %esi
movl (%rdi), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
subq $0x10, %rsp
orl $-0x1, 0x8(%rsp)
andq $0x0, (%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x34(%rsp), %r9
movq %rdx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1895fa
popq %rcx
popq %rdx
movq 0x18(%r15), %rax
movl (%rax), %eax
movq %rax, 0x48(%rsp)
movl 0x10(%r15), %eax
pushq $0x1
popq %rdi
xorl %r13d, %r13d
movq %r12, 0x80(%rsp)
movl %eax, %eax
cmpq %rax, %rdi
ja 0x189bd2
movq %rdi, 0x18(%rsp)
jae 0x189975
movq 0x18(%r15), %rax
movl 0x4(%rax,%rdi,8), %esi
movl (%r15), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq %rbx, %rdi
movq 0x18(%rsp), %rdx
movq 0x48(%rsp), %rcx
movq %rbx, %r14
leaq 0x54(%rsp), %rbx
movq %rbx, %r9
pushq $-0x1
pushq $0x0
callq 0x1895fa
popq %rcx
popq %rdx
movq 0x18(%rsp), %rbp
subq 0x10(%rsp), %rbp
leaq 0x24(%rsp), %rdi
movq %rbx, %rsi
movq %r14, %rbx
movq %rbp, %rdx
callq 0x189831
movq 0x18(%rsp), %rdi
testq %rax, %rax
jne 0x18997d
jmp 0x189bb5
movq %rdi, %rbp
subq 0x10(%rsp), %rbp
movl 0x54(%rsp), %r14d
movq 0x58(%rsp), %rcx
movl 0x60(%rsp), %edx
leaq 0x64(%rsp), %rsi
movq (%rsi), %rax
movq %rax, 0x70(%rsp)
movl 0x8(%rsi), %eax
movl %eax, 0x78(%rsp)
cmpq $0x2, %rbp
jb 0x189aa8
movl %edx, 0xc(%rsp)
movq %rcx, 0x40(%rsp)
movl %r14d, 0x50(%rsp)
movq %rbx, %r14
movq 0x10(%rsp), %rax
leaq (,%rax,8), %rbx
xorl %r12d, %r12d
movq 0x10(%rsp), %rax
leaq (%rax,%r12), %rdx
cmpq %rdi, %rdx
jae 0x189afb
movq 0x18(%r15), %rax
addq %rbx, %rax
movl 0x4(%rax,%r12,8), %esi
movl (%r15), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq %r14, %rdi
movq %r13, %rcx
leaq 0x54(%rsp), %r9
pushq $-0x1
pushq $0x0
callq 0x1895fa
addq $0x10, %rsp
cmpq $0x1, %rax
jne 0x189bf6
movl 0x60(%rsp), %eax
cmpl 0x30(%rsp), %eax
jne 0x189be4
movl 0x54(%rsp), %eax
movl 0x24(%rsp), %ecx
addq %r12, %rcx
cmpq %rax, %rcx
jne 0x189bed
movl 0x6c(%rsp), %eax
movl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andq %rdx, %rax
movl 0x3c(%rsp), %ecx
andq %rdx, %rcx
addq %r12, %rcx
cmpq %rax, %rcx
jne 0x189bff
movl 0x58(%rsp), %eax
cmpl 0x28(%rsp), %eax
jae 0x189a63
movl %eax, 0x28(%rsp)
movl 0x5c(%rsp), %eax
cmpl 0x2c(%rsp), %eax
movq 0x18(%rsp), %rdi
jbe 0x189a76
movl %eax, 0x2c(%rsp)
movl 0x64(%rsp), %eax
cmpl 0x34(%rsp), %eax
jae 0x189a84
movl %eax, 0x34(%rsp)
movl 0x68(%rsp), %eax
cmpl 0x38(%rsp), %eax
jbe 0x189a92
movl %eax, 0x38(%rsp)
movq 0x18(%r15), %rax
addq %rbx, %rax
movl (%rax,%r12,8), %eax
addq %rax, %r13
incq %r12
jmp 0x1899ca
cmpq $0x1, %rbp
jne 0x189b88
movq 0x18(%r15), %rax
movq %rcx, 0x40(%rsp)
movl %edx, 0xc(%rsp)
movq 0x10(%rsp), %rdx
movl 0x4(%rax,%rdx,8), %esi
movl (%r15), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq %rbx, %rdi
movq %r13, %rcx
xorl %r9d, %r9d
pushq $0x1
pushq %r12
callq 0x1895fa
movq 0x28(%rsp), %rdi
movl 0x1c(%rsp), %edx
movq 0x50(%rsp), %rcx
addq $0x10, %rsp
jmp 0x189b88
andl $0x3fffffff, %ebp       # imm = 0x3FFFFFFF
movl 0x3c(%rsp), %eax
movl $0xc0000000, %ecx       # imm = 0xC0000000
andl %ecx, %eax
orl %ebp, %eax
movl %eax, 0x3c(%rsp)
movq 0x80(%rsp), %r12
movq (%r12), %rax
movq 0x8(%r12), %rcx
cmpq 0x10(%r12), %rcx
jne 0x189b57
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r12)
imulq $0x1c, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x18(%rsp), %rdi
movq %rax, (%r12)
movq 0x8(%r12), %rcx
movq %r14, %rbx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r12)
imulq $0x1c, %rcx, %rcx
movups 0x24(%rsp), %xmm0
movups 0x30(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
movl 0x50(%rsp), %r14d
movq 0x40(%rsp), %rcx
movl 0xc(%rsp), %edx
movl %r14d, 0x24(%rsp)
movq %rcx, 0x28(%rsp)
movl %edx, 0x30(%rsp)
movl 0x78(%rsp), %eax
leaq 0x24(%rsp), %rcx
movl %eax, 0x18(%rcx)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rcx)
movq %rdi, 0x10(%rsp)
movq 0x48(%rsp), %r13
movl 0x10(%r15), %eax
cmpq %rax, %rdi
jae 0x189bca
movq 0x18(%r15), %rcx
movl (%rcx,%rdi,8), %ecx
addq %rcx, 0x48(%rsp)
incq %rdi
jmp 0x189902
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6b78a(%rip), %rdi     # 0x1f5375
jmp 0x189c06
leaq 0x6b790(%rip), %rdi     # 0x1f5384
jmp 0x189c06
leaq 0x6b728(%rip), %rdi     # 0x1f5325
jmp 0x189c06
leaq 0x6b795(%rip), %rdi     # 0x1f539b
leaq 0x67f16(%rip), %rsi     # 0x1f1b23
leaq 0x6b718(%rip), %rcx     # 0x1f532c
movl $0x3fdb, %edx           # imm = 0x3FDB
callq 0x2110