// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: update_rovlp_chain_qse(ma_ug_t*, long, long, mg_lchain_t*, long, long)
void update_rovlp_chain_qse(ma_ug_t *ug, int64_t sidx, int64_t eidx, mg_lchain_t *a, int64_t a_n, int64_t qlen)
{
	if(eidx - sidx <= 1) return;
	assert(sidx>=0||eidx<a_n);
	// fprintf(stderr, "******[M::%s::] sidx:%ld, eidx:%ld\n", __func__, sidx, eidx);
	int64_t left_r[2], right_r[2], left_q[2], right_q[2], tt; 
	int64_t i, rs, re;//qs or qe might be -1, while rs and re should >= 0
	if(sidx >= 0) {
		get_r_offset(ug, &(a[sidx]), &left_r[0], &left_r[1], &left_q[0], &left_q[1]);
	} else {
		get_r_offset(ug, &(a[0]), &left_r[0], &left_r[1], &left_q[0], &left_q[1]);
	}

	if(eidx < a_n) {
		get_r_offset(ug, &(a[eidx]), &right_r[0], &right_r[1], &right_q[0], &right_q[1]);
	} else {
		get_r_offset(ug, &(a[a_n-1]), &right_r[0], &right_r[1], &right_q[0], &right_q[1]);
	}
	assert((left_q[0] >= 0 && left_q[1] >= 0) || (right_q[0] >= 0 && right_q[1] >= 0)); ///assert(re >= rs);

	if(left_q[0] >= 0 && left_q[1] >= 0 && right_q[0] >= 0 && right_q[1] >= 0) {
		for (i = sidx+1; i < eidx; i++) {
			get_r_offset(ug, &(a[i]), &rs, &re, NULL, NULL);
			a[i].qe = cal_qext_coor(left_r[1], right_r[1], left_q[1], right_q[1], re);
			assert(a[i].qe >= 0 && a[i].qe <= qlen);
			a[i].qs = cal_qext_coor(left_r[0], (a[i].qe<=right_q[0])?re:right_r[0], 
											left_q[0], (a[i].qe<=right_q[0])?a[i].qe:right_q[0], rs);
			assert(a[i].qs >= 0 && a[i].qs <= qlen);
			if(a[i].qs > a[i].qe) {
				tt = a[i].qs; a[i].qs = a[i].qe; a[i].qe = tt;
			}
			left_q[0] = a[i].qs; left_q[1] = a[i].qe;
			left_r[0] = rs; left_r[1] = re;
		}
	}

	if(right_q[0] < 0 || right_q[1] < 0) {
		for (i = sidx+1; i < eidx; i++) {
			get_r_offset(ug, &(a[i]), &rs, &re, NULL, NULL);
			a[i].qe = cal_qext_coor(left_r[1], re, left_q[1], left_q[1] + re - left_r[1], re);
			if(a[i].qe < 0) a[i].qe = 0; if(a[i].qe > qlen) a[i].qe = qlen;
			a[i].qs = cal_qext_coor(left_r[0], (a[i].qe<=left_q[1])?re:left_r[1], 
											left_q[0], (a[i].qe<=left_q[1])?a[i].qe:left_q[1], rs);
			assert(a[i].qs >= 0 && a[i].qs <= qlen);
			if(a[i].qs > a[i].qe) {
				tt = a[i].qs; a[i].qs = a[i].qe; a[i].qe = tt;
			}
			
			left_q[0] = a[i].qs; left_q[1] = a[i].qe;
			left_r[0] = rs; left_r[1] = re;
		}
	}

	if(left_q[0] < 0 || left_q[1] < 0) {
		for (i = eidx-1; i > sidx; i--) {
			get_r_offset(ug, &(a[i]), &rs, &re, NULL, NULL);
			// a[i].qe = right_q[1] - get_offset_adjust(right_r[1]-re, right_r[1]-right_r[0], right_q[1]-right_q[0]);
			// a[i].qs = right_q[0] - (right_r[0]-rs);
			a[i].qe = cal_qext_coor(right_r[0], right_r[1], right_q[0], right_q[1], re);
			assert(a[i].qe >= 0 && a[i].qe <= qlen);
			a[i].qs = cal_qext_coor(rs, right_r[0], right_q[0]-(right_r[0]-rs), right_q[0], rs);
			if(a[i].qs < 0) a[i].qs = 0; if(a[i].qs > qlen) a[i].qs = qlen;
			if(a[i].qs > a[i].qe) {
				tt = a[i].qs; a[i].qs = a[i].qe; a[i].qe = tt;
			}

			right_q[0] = a[i].qs; right_q[1] = a[i].qe;
			right_r[0] = rs; right_r[1] = re;
		}
	}
	// if(left_q[0] < 0) left_q[0] = right_q[0] - (right_r[0] - left_r[0]);
	// if(left_q[1] < 0) left_q[1] = right_q[1] - (right_r[1] - left_r[1]);
	// if(right_q[0] < 0 || right_q[1] < 0) {
	// 	right_q[0] = left_q[0] + (right_r[0] - left_r[0]);
	// 	right_q[1] = left_q[1] + (right_r[1] - left_r[1]);
	// }	
	
	// fprintf(stderr, "******[M::%s::] right_q[0]:%ld, right_q[1]:%ld\n", __func__, right_q[0], right_q[1]);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, 0x48(%rsp)
movq %rdx, %rax
subq %rsi, %rax
cmpq $0x2, %rax
jl 0x1d3df2
movq %r8, %rbx
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, %rbp
movq %r9, 0x88(%rsp)
testq %rsi, %rsi
setns %al
cmpq %r8, %rdx
setl %cl
orb %al, %cl
je 0x1d3e80
xorl %eax, %eax
testq %rbp, %rbp
cmovnsq %rbp, %rax
leaq (%rax,%rax,4), %rax
leaq (%r14,%rax,8), %rsi
leaq 0x28(%rsp), %rcx
leaq 0x98(%rsp), %r9
leaq 0x20(%rsp), %rdx
leaq 0x90(%rsp), %r12
movq 0x48(%rsp), %r15
movq %r15, %rdi
movq %r12, %r8
callq 0x1af0c9
cmpq %rbx, %r13
leaq (%rbx,%rbx,4), %rax
leaq -0x28(%r14,%rax,8), %rax
leaq (%r13,%r13,4), %rcx
movq %r14, 0x60(%rsp)
movq %rcx, 0xb0(%rsp)
leaq (%r14,%rcx,8), %rsi
cmovgeq %rax, %rsi
leaq 0x58(%rsp), %rcx
leaq 0xa8(%rsp), %r9
leaq 0x50(%rsp), %rdx
leaq 0xa0(%rsp), %rbx
movq %r15, %rdi
movq %rbx, %r8
callq 0x1af0c9
movq (%r12), %r15
movq 0x8(%r12), %rdx
movq (%rbx), %rax
movq %rax, 0x68(%rsp)
movq 0x8(%rbx), %rcx
movq %rcx, 0x70(%rsp)
orq %rcx, %rax
setns %al
movq %rdx, %r12
movq %rdx, %rcx
orq %r15, %rcx
movq %r13, 0x8(%rsp)
movq %rbp, 0x78(%rsp)
js 0x1d3b3a
testb %al, %al
je 0x1d3b42
leaq 0x1(%rbp), %rax
cmpq %r13, %rax
jge 0x1d3b42
movq 0x20(%rsp), %r14
movq 0x28(%rsp), %rsi
movq 0x50(%rsp), %rcx
movq %rcx, 0x38(%rsp)
movq 0x58(%rsp), %rcx
movq %rcx, 0x40(%rsp)
movq %rbp, %rdx
notq %rdx
addq %r13, %rdx
leaq (,%rbp,4), %rax
addq %rbp, %rax
movq 0x60(%rsp), %rcx
leaq (%rcx,%rax,8), %rbx
addq $0x28, %rbx
movq %r15, %rax
movq %rax, (%rsp)
movq %r14, %r13
movq %rdx, 0x80(%rsp)
movq %rsi, %r14
movq 0x48(%rsp), %rdi
movq %rbx, %rsi
leaq 0x18(%rsp), %rdx
leaq 0x10(%rsp), %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1af0c9
movq 0x10(%rsp), %r8
movq %r14, %rdi
movq 0x40(%rsp), %rsi
movq %r12, %rdx
movq 0x70(%rsp), %rcx
movq %r8, %rbp
callq 0x1b0132
movq %rax, %r15
movl %r15d, 0x18(%rbx)
testl %r15d, %r15d
movq 0x88(%rsp), %r12
js 0x1d3e42
movl %r15d, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %r12, %rcx
jg 0x1d3e42
movq 0x68(%rsp), %rax
cmpq %rax, %rcx
movq %rbp, %rsi
cmovgq 0x38(%rsp), %rsi
cmovgeq %rax, %rcx
movq 0x18(%rsp), %r14
movq %r13, %rdi
movq (%rsp), %rdx
movq %r14, %r8
callq 0x1b0132
movl %eax, 0x14(%rbx)
testl %eax, %eax
js 0x1d3e61
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
cmpq %r12, %rcx
ja 0x1d3e61
cmpl %eax, %r15d
movq 0x80(%rsp), %rdx
jae 0x1d3afa
movl %r15d, 0x14(%rbx)
movl %eax, 0x18(%rbx)
movq %rax, %r12
jmp 0x1d3b00
movq %r15, %r12
movq %rax, %r15
movq %rbp, %rsi
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andq %rax, %r15
movq %r15, 0x90(%rsp)
andq %rax, %r12
movq %r12, 0x98(%rsp)
movq %r14, 0x20(%rsp)
movq %rbp, 0x28(%rsp)
addq $0x28, %rbx
movq %r15, %rax
decq %rdx
jne 0x1d3a26
jmp 0x1d3b42
testb %al, %al
je 0x1d3e9f
movq 0x70(%rsp), %rax
orq 0x68(%rsp), %rax
jns 0x1d3cb2
movq 0x78(%rsp), %rdx
leaq 0x1(%rdx), %rax
movq 0x8(%rsp), %rcx
cmpq %rcx, %rax
movq %r12, %r13
jge 0x1d3caf
movq 0x20(%rsp), %rbp
movq 0x28(%rsp), %r8
movq %rdx, %rsi
notq %rsi
addq %rcx, %rsi
leaq (%rdx,%rdx,4), %rax
movq 0x60(%rsp), %rcx
leaq (%rcx,%rax,8), %rbx
addq $0x28, %rbx
movq %r15, 0x80(%rsp)
movq %rsi, 0x40(%rsp)
movq %rbp, (%rsp)
movq %r8, %rbp
movq 0x48(%rsp), %rdi
movq %rbx, %rsi
leaq 0x18(%rsp), %rdx
leaq 0x10(%rsp), %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1af0c9
movq 0x10(%rsp), %r15
movq %r15, %rcx
subq %rbp, %rcx
addq %r13, %rcx
movq %rbp, %rdi
movq %r15, %rsi
movq %r13, %rdx
movq %r15, %r8
callq 0x1b0132
movq %rax, %r14
testl %r14d, %r14d
movl $0x0, %eax
cmovlel %eax, %r14d
movq %r13, %rcx
movq 0x88(%rsp), %r13
cmpq %r13, %r14
cmovgl %r13d, %r14d
movslq %r14d, %r12
cmpq %r12, %rcx
movq %r15, 0x38(%rsp)
cmovgeq %r15, %rbp
movl %r14d, 0x18(%rbx)
cmovgeq %r12, %rcx
movq 0x18(%rsp), %r8
movq (%rsp), %rdi
movq %rbp, %rsi
movq 0x80(%rsp), %rdx
movq %r8, %rbp
callq 0x1b0132
movq %rax, %r15
movl %r15d, 0x14(%rbx)
testl %r15d, %r15d
js 0x1d3e04
movl %r15d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %r13, %rax
jg 0x1d3e04
cmpl %r15d, %r14d
jge 0x1d3c72
movl %r14d, 0x14(%rbx)
movl %r15d, 0x18(%rbx)
movl %r15d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %r12, %r15
movq %rax, %r12
jmp 0x1d3c79
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movq 0x40(%rsp), %rsi
movq 0x38(%rsp), %r8
movq %r15, 0x90(%rsp)
movq %r12, 0x98(%rsp)
movq %rbp, 0x20(%rsp)
movq %r8, 0x28(%rsp)
addq $0x28, %rbx
movq %r12, %r13
decq %rsi
jne 0x1d3b90
jmp 0x1d3cb2
movq %r13, %r12
testq %r15, %r15
movq 0x68(%rsp), %r15
movq 0x70(%rsp), %r13
js 0x1d3cca
testq %r12, %r12
jns 0x1d3df2
movq 0x8(%rsp), %rax
decq %rax
movq %rax, 0x8(%rsp)
cmpq 0x78(%rsp), %rax
jle 0x1d3df2
movq 0x50(%rsp), %r14
movq 0x58(%rsp), %r12
movq 0x60(%rsp), %rax
movq 0xb0(%rsp), %rcx
leaq (%rax,%rcx,8), %rbx
addq $-0x28, %rbx
movq 0x48(%rsp), %rdi
movq %rbx, %rsi
leaq 0x18(%rsp), %rdx
leaq 0x10(%rsp), %rcx
xorl %r8d, %r8d
xorl %r9d, %r9d
callq 0x1af0c9
movq 0x10(%rsp), %r8
movq %r14, %rdi
movq %r12, %rsi
movq %r15, %rbp
movq %r15, %rdx
movq %r13, %rcx
movq %r8, (%rsp)
callq 0x1b0132
movq %rax, %r15
movl %r15d, 0x18(%rbx)
testl %r15d, %r15d
movq 0x88(%rsp), %r12
js 0x1d3e23
movl %r15d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
cmpq %r12, %rax
jg 0x1d3e23
movq 0x18(%rsp), %r13
movq %rbp, %rdx
subq %r14, %rdx
addq %r13, %rdx
movq %r13, %rdi
movq %r14, %rsi
movq %rbp, %rcx
movq %r13, %r8
callq 0x1b0132
testl %eax, %eax
movl $0x0, %ecx
cmovlel %ecx, %eax
cmpq %r12, %rax
cmoval %r12d, %eax
movl %eax, 0x14(%rbx)
cmpl %r15d, %eax
jle 0x1d3da7
movl %r15d, 0x14(%rbx)
movl %eax, 0x18(%rbx)
movl %eax, %ecx
jmp 0x1d3dad
movl %r15d, %ecx
movl %eax, %r15d
movq (%rsp), %r12
movslq %r15d, %r15
movq %r15, 0xa0(%rsp)
movl %ecx, %ecx
movq %rcx, 0xa8(%rsp)
movq %r13, 0x50(%rsp)
movq %r12, 0x58(%rsp)
movq 0x8(%rsp), %rax
decq %rax
addq $-0x28, %rbx
movq %r13, %r14
movq %rcx, %r13
movq %rax, 0x8(%rsp)
cmpq 0x78(%rsp), %rax
jg 0x1d3d01
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6f125(%rip), %rdi     # 0x242f30
leaq 0x6be49(%rip), %rsi     # 0x23fc5b
leaq 0x6f09d(%rip), %rcx     # 0x242eb6
movl $0x3cb2, %edx           # imm = 0x3CB2
callq 0x2110
leaq 0x6f0e6(%rip), %rdi     # 0x242f10
leaq 0x6be2a(%rip), %rsi     # 0x23fc5b
leaq 0x6f07e(%rip), %rcx     # 0x242eb6
movl $0x3cc2, %edx           # imm = 0x3CC2
callq 0x2110
leaq 0x6f0c7(%rip), %rdi     # 0x242f10
leaq 0x6be0b(%rip), %rsi     # 0x23fc5b
leaq 0x6f05f(%rip), %rcx     # 0x242eb6
movl $0x3c9f, %edx           # imm = 0x3C9F
callq 0x2110
leaq 0x6f0c8(%rip), %rdi     # 0x242f30
leaq 0x6bdec(%rip), %rsi     # 0x23fc5b
leaq 0x6f040(%rip), %rcx     # 0x242eb6
movl $0x3ca2, %edx           # imm = 0x3CA2
callq 0x2110
leaq 0x6ef7c(%rip), %rdi     # 0x242e03
leaq 0x6bdcd(%rip), %rsi     # 0x23fc5b
leaq 0x6f021(%rip), %rcx     # 0x242eb6
movl $0x3c8a, %edx           # imm = 0x3C8A
callq 0x2110
leaq 0x6efc5(%rip), %rdi     # 0x242e6b
leaq 0x6bdae(%rip), %rsi     # 0x23fc5b
leaq 0x6f002(%rip), %rcx     # 0x242eb6
movl $0x3c99, %edx           # imm = 0x3C99
callq 0x2110