// File: /workspace/github_cpp_makefile_star2_O1/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 $0x78, %rsp
cmpl $0x0, 0x10(%rdi)
je 0x1cc511
movq %rdi, %r15
xorl %eax, %eax
movq %rsi, 0x50(%rsp)
movq %rax, 0x8(%rsi)
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
movl %r10d, 0x24(%rsp)
movl %r10d, 0x30(%rsp)
movq 0x18(%rdi), %rcx
movl 0x4(%rcx), %esi
movl (%rdi), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
leaq 0x8(%rsp), %r9
movq %rdx, 0x40(%rsp)
movq %rdx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
pushq %r10
pushq %rax
callq 0x1cbf22
addq $0x10, %rsp
movl 0x10(%r15), %eax
testq %rax, %rax
je 0x1cc511
movq 0x18(%r15), %rcx
movl (%rcx), %r13d
movl $0x1, %r14d
xorl %ebx, %ebx
xorl %r12d, %r12d
xorl %ebp, %ebp
cmpq %rax, %r14
jae 0x1cc2d7
movq 0x18(%r15), %rax
movl 0x4(%rax,%r14,8), %esi
movl (%r15), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq 0x40(%rsp), %rdi
movq %r14, %rdx
movq %r13, %rcx
leaq 0x24(%rsp), %r9
pushq $-0x1
pushq $0x0
callq 0x1cbf22
addq $0x10, %rsp
movl 0x14(%rsp), %eax
cmpl $-0x1, %eax
je 0x1cc2d7
cmpl 0x30(%rsp), %eax
jne 0x1cc2d7
movq %r14, %rax
subq %rbp, %rax
movl 0x8(%rsp), %ecx
addq %rax, %rcx
movl 0x24(%rsp), %edx
cmpq %rdx, %rcx
jne 0x1cc2d7
movl 0x20(%rsp), %ecx
movl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andq %rdx, %rcx
addq %rcx, %rax
movl 0x3c(%rsp), %ecx
andq %rdx, %rcx
cmpq %rcx, %rax
je 0x1cc4e3
movq %r13, 0x58(%rsp)
movl 0x24(%rsp), %eax
movl %eax, 0x4c(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x70(%rsp)
movl 0x30(%rsp), %eax
movl %eax, 0x48(%rsp)
leaq 0x34(%rsp), %rcx
movq (%rcx), %rax
movq %rax, 0x60(%rsp)
movl 0x8(%rcx), %eax
movl %eax, 0x68(%rsp)
movq %r14, %r13
subq %rbp, %r13
cmpq $0x2, %r13
jb 0x1cc475
cmpq %rbp, %r14
jbe 0x1cc3ef
movq 0x18(%r15), %rax
movl 0x4(%rax,%rbp,8), %esi
movl (%r15), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq 0x40(%rsp), %rdi
movq %rbp, %rdx
movq %r12, %rcx
leaq 0x24(%rsp), %r9
pushq $-0x1
pushq $0x0
callq 0x1cbf22
addq $0x10, %rsp
cmpq $0x1, %rax
jne 0x1cc520
movl 0x30(%rsp), %eax
cmpl 0x14(%rsp), %eax
jne 0x1cc532
movl 0x24(%rsp), %ecx
movl 0x8(%rsp), %edx
leaq (%rbx,%rbp), %rax
addq %rax, %rdx
cmpq %rcx, %rdx
jne 0x1cc53b
movl 0x3c(%rsp), %ecx
movl $0x3fffffff, %esi       # imm = 0x3FFFFFFF
andq %rsi, %rcx
movl 0x20(%rsp), %edx
andq %rsi, %rdx
addq %rdx, %rax
cmpq %rcx, %rax
jne 0x1cc529
movl 0x28(%rsp), %eax
cmpl 0xc(%rsp), %eax
jae 0x1cc3af
movl %eax, 0xc(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x10(%rsp), %eax
jbe 0x1cc3bd
movl %eax, 0x10(%rsp)
movl 0x34(%rsp), %eax
cmpl 0x18(%rsp), %eax
jae 0x1cc3cb
movl %eax, 0x18(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x1c(%rsp), %eax
jbe 0x1cc3d9
movl %eax, 0x1c(%rsp)
movq 0x18(%r15), %rax
movl (%rax,%rbp,8), %eax
addq %rax, %r12
incq %rbp
cmpq %rbp, %r14
jne 0x1cc323
andl $0x3fffffff, %r13d      # imm = 0x3FFFFFFF
movl 0x20(%rsp), %eax
movl $0xc0000000, %ecx       # imm = 0xC0000000
andl %ecx, %eax
orl %r13d, %eax
movl %eax, 0x20(%rsp)
movq 0x50(%rsp), %rbx
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x1cc441
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%rbx)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups 0x8(%rsp), %xmm0
movups 0x14(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
movq 0x58(%rsp), %r13
jmp 0x1cc4af
cmpq $0x1, %r13
movq 0x58(%rsp), %r13
jne 0x1cc4af
movq 0x18(%r15), %rax
movl 0x4(%rax,%rbp,8), %esi
movl (%r15), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq 0x40(%rsp), %rdi
movq %rbp, %rdx
movq %r12, %rcx
xorl %r9d, %r9d
pushq $0x1
pushq 0x58(%rsp)
callq 0x1cbf22
addq $0x10, %rsp
movl 0x4c(%rsp), %eax
movl %eax, 0x8(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0xc(%rsp)
movl 0x48(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x68(%rsp), %eax
leaq 0x18(%rsp), %rcx
movl %eax, 0x8(%rcx)
movq 0x60(%rsp), %rax
movq %rax, (%rcx)
movq %r14, %rbp
movq %r13, %r12
movl 0x10(%r15), %eax
cmpq %rax, %r14
jae 0x1cc4f7
movq 0x18(%r15), %rax
movl (%rax,%r14,8), %eax
addq %rax, %r13
leaq 0x1(%r14), %rcx
movq %rbp, %rbx
negq %rbx
movl 0x10(%r15), %eax
cmpq %rax, %r14
movq %rcx, %r14
jb 0x1cc25e
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6ac66(%rip), %rdi     # 0x23718d
jmp 0x1cc542
leaq 0x6acd3(%rip), %rdi     # 0x237203
jmp 0x1cc542
leaq 0x6aca4(%rip), %rdi     # 0x2371dd
jmp 0x1cc542
leaq 0x6acaa(%rip), %rdi     # 0x2371ec
leaq 0x67442(%rip), %rsi     # 0x23398b
leaq 0x6ac44(%rip), %rcx     # 0x237194
movl $0x3fdb, %edx           # imm = 0x3FDB
callq 0x2110