// File: /workspace/github_cpp_makefile_star2_O3/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 0x1d64b3
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, 0x48(%rsp)
movq %rdx, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
pushq %r10
pushq %rax
callq 0x1d5ea2
addq $0x10, %rsp
movl 0x10(%r15), %eax
testq %rax, %rax
je 0x1d64b3
movq 0x18(%r15), %rcx
movl (%rcx), %ebp
movl $0x1, %r14d
xorl %ebx, %ebx
xorl %r12d, %r12d
xorl %r13d, %r13d
cmpq %rax, %r14
movq %rbp, 0x40(%rsp)
jae 0x1d6268
movq 0x18(%r15), %rax
movl 0x4(%rax,%r14,8), %esi
movl (%r15), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq 0x48(%rsp), %rdi
movq %r14, %rdx
movq %rbp, %rcx
leaq 0x24(%rsp), %r9
pushq $-0x1
pushq $0x0
callq 0x1d5ea2
addq $0x10, %rsp
movq %r14, %rbp
subq %r13, %rbp
movl 0x14(%rsp), %edx
cmpl $-0x1, %edx
setne %cl
movl 0x24(%rsp), %esi
movl 0x30(%rsp), %eax
movl %edx, 0x4(%rsp)
cmpl %eax, %edx
sete %dl
andb %cl, %dl
cmpb $0x1, %dl
jne 0x1d627c
movl 0x8(%rsp), %eax
addq %rbp, %rax
cmpq %rsi, %rax
movq %rsi, %rdx
jne 0x1d6283
movl 0x20(%rsp), %eax
movq %rdx, %rsi
movl $0x3fffffff, %edx       # imm = 0x3FFFFFFF
andq %rdx, %rax
addq %rbp, %rax
movl 0x3c(%rsp), %ecx
andq %rdx, %rcx
movq %rsi, %rdx
cmpq %rcx, %rax
jne 0x1d6283
movq 0x40(%rsp), %rbp
jmp 0x1d6491
movl 0x24(%rsp), %edx
movl 0x30(%rsp), %eax
movl %eax, 0x4(%rsp)
movq %r14, %rbp
subq %r13, %rbp
jmp 0x1d6283
movl %eax, 0x4(%rsp)
movq %rsi, %rdx
movq 0x28(%rsp), %rax
movq %rax, 0x70(%rsp)
leaq 0x34(%rsp), %rcx
movq (%rcx), %rax
movq %rax, 0x58(%rsp)
movl 0x8(%rcx), %eax
movl %eax, 0x60(%rsp)
cmpq $0x2, %rbp
jb 0x1d6391
cmpq %r13, %r14
jbe 0x1d63db
movq %rdx, 0x68(%rsp)
movq 0x18(%r15), %rcx
movl 0x4(%rcx,%r13,8), %esi
movl (%r15), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq 0x48(%rsp), %rdi
movq %r13, %rdx
movq %r12, %rcx
leaq 0x24(%rsp), %r9
pushq $-0x1
pushq $0x0
callq 0x1d5ea2
addq $0x10, %rsp
cmpq $0x1, %rax
jne 0x1d64c2
movl 0x30(%rsp), %eax
cmpl 0x14(%rsp), %eax
jne 0x1d64d4
movl 0x24(%rsp), %eax
movl 0x8(%rsp), %edx
leaq (%rbx,%r13), %rcx
addq %rcx, %rdx
cmpq %rax, %rdx
jne 0x1d64dd
movl 0x3c(%rsp), %edx
movl $0x3fffffff, %edi       # imm = 0x3FFFFFFF
andq %rdi, %rdx
movl 0x20(%rsp), %eax
movq %rax, %rsi
andq %rdi, %rsi
addq %rsi, %rcx
cmpq %rdx, %rcx
jne 0x1d64cb
movl 0x28(%rsp), %ecx
cmpl 0xc(%rsp), %ecx
jae 0x1d6349
movl %ecx, 0xc(%rsp)
movl 0x2c(%rsp), %ecx
cmpl 0x10(%rsp), %ecx
jbe 0x1d6357
movl %ecx, 0x10(%rsp)
movl 0x34(%rsp), %ecx
cmpl 0x18(%rsp), %ecx
jae 0x1d6365
movl %ecx, 0x18(%rsp)
movl 0x38(%rsp), %ecx
cmpl 0x1c(%rsp), %ecx
jbe 0x1d6373
movl %ecx, 0x1c(%rsp)
movq 0x18(%r15), %rcx
movl (%rcx,%r13,8), %edx
addq %rdx, %r12
incq %r13
cmpq %r13, %r14
jne 0x1d62bd
movq 0x68(%rsp), %rdx
jmp 0x1d63df
cmpq $0x1, %rbp
movq 0x40(%rsp), %rbp
jne 0x1d6461
movq 0x18(%r15), %rax
movl 0x4(%rax,%r13,8), %esi
movl (%r15), %r8d
andl $0x7fffffff, %r8d       # imm = 0x7FFFFFFF
movq 0x48(%rsp), %rdi
movq %rdx, %rbx
movq %r13, %rdx
movq %r12, %rcx
xorl %r9d, %r9d
pushq $0x1
pushq 0x58(%rsp)
callq 0x1d5ea2
movq %rbx, %rdx
addq $0x10, %rsp
jmp 0x1d6461
movl 0x20(%rsp), %eax
movq %rdx, %r12
andl $0x3fffffff, %ebp       # imm = 0x3FFFFFFF
andl $0xc0000000, %eax       # imm = 0xC0000000
orl %ebp, %eax
movl %eax, 0x20(%rsp)
movq 0x50(%rsp), %rbx
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x1d6433
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
movq 0x40(%rsp), %rbp
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 %r12, %rdx
movl %edx, 0x8(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0xc(%rsp)
movl 0x4(%rsp), %eax
movl %eax, 0x14(%rsp)
movl 0x60(%rsp), %eax
leaq 0x18(%rsp), %rcx
movl %eax, 0x8(%rcx)
movq 0x58(%rsp), %rax
movq %rax, (%rcx)
movq %r14, %r13
movq %rbp, %r12
movl 0x10(%r15), %eax
cmpq %rax, %r14
jae 0x1d64b3
movq 0x18(%r15), %rcx
movl (%rcx,%r14,8), %ecx
addq %rcx, %rbp
incq %r14
movq %r13, %rbx
negq %rbx
jmp 0x1d61c8
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6cf94(%rip), %rdi     # 0x24345d
jmp 0x1d64e4
leaq 0x6d001(%rip), %rdi     # 0x2434d3
jmp 0x1d64e4
leaq 0x6cfd2(%rip), %rdi     # 0x2434ad
jmp 0x1d64e4
leaq 0x6cfd8(%rip), %rdi     # 0x2434bc
leaq 0x69770(%rip), %rsi     # 0x23fc5b
leaq 0x6cf72(%rip), %rcx     # 0x243464
movl $0x3fdb, %edx           # imm = 0x3FDB
callq 0x2110