// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: cal_x_interval(ma_ug_t*, ul_ov_t*, ul_ov_t*, ul_ov_t*)
uint32_t cal_x_interval(ma_ug_t *ug, ul_ov_t *v, ul_ov_t *w, ul_ov_t *res)
{
	uint32_t os, oe, rqs, rqe, rts, rte; memset(res, 0, sizeof((*res)));
	// if(v->qn == 97) {
	// 	fprintf(stderr, "-0-v-[M::%s]\tutg%.6u%c\tq::[%u,\t%u)\t%c\tutg%.6u%c\tt::[%u,\t%u)\n", __func__, 
	// 			v->qn+1, "lc"[ug->u.a[v->qn].circ], v->qs, v->qe, "+-"[v->rev],
	// 			v->tn+1, "lc"[ug->u.a[v->tn].circ], v->ts, v->te);
	// 	fprintf(stderr, "-0-w-[M::%s]\tutg%.6u%c\tq::[%u,\t%u)\t%c\tutg%.6u%c\tt::[%u,\t%u)\n", __func__, 
	// 			w->qn+1, "lc"[ug->u.a[w->qn].circ], w->qs, w->qe, "+-"[v->rev],
	// 			w->tn+1, "lc"[ug->u.a[w->tn].circ], w->ts, w->te);
	// }
	if(v->tn == w->qn) {
		os = MAX(v->ts, w->qs); oe = MIN(v->te, w->qe);
		// if(v->qn == 97) {
		// 	fprintf(stderr, "-1-[M::%s]\tutg%.6u%c->utg%.6u%c\tutg%.6u%c->utg%.6u%c\to::[%u,\t%u)\n", __func__, 
		// 			v->qn+1, "lc"[ug->u.a[v->qn].circ],
		// 			v->tn+1, "lc"[ug->u.a[v->tn].circ], 
		// 			w->qn+1, "lc"[ug->u.a[w->qn].circ],
		// 			w->tn+1, "lc"[ug->u.a[w->tn].circ],
		// 			os, oe);
		// }
		if(oe <= os) return 0;
		if(infer_se(v->ts, v->te, v->qs, v->qe, v->rev, os, oe, &rqs, &rqe) &&
			infer_se(w->qs, w->qe, w->ts, w->te, w->rev, os, oe, &rts, &rte)) {
			// if(v->qn == 97) {
			// 	fprintf(stderr, "-2-[M::%s]\tutg%.6u%c->utg%.6u%c\tutg%.6u%c->utg%.6u%c\trq::[%u,\t%u)\trt::[%u,\t%u)\n", __func__, 
			// 			v->qn+1, "lc"[ug->u.a[v->qn].circ],
			// 			v->tn+1, "lc"[ug->u.a[v->tn].circ], 
			// 			w->qn+1, "lc"[ug->u.a[w->qn].circ],
			// 			w->tn+1, "lc"[ug->u.a[w->tn].circ],
			// 			rqs, rqe, rts, rte);
			// }
			if(rqe > rqs && rte > rts) {
				res->qn = v->qn; res->tn = w->tn; res->rev = ((v->rev==w->rev)?0:1);
				res->qs = rqs; res->qe = rqe; res->ts = rts; res->te = rte; 
				return 1;
			}
		}
	}
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %rbx
xorps %xmm0, %xmm0
movups %xmm0, 0xc(%rcx)
movups %xmm0, (%rcx)
movl 0xc(%rsi), %ecx
xorl %eax, %eax
cmpl (%rdx), %ecx
jne 0x1c8626
movq %rdx, %r15
movq %rsi, %r14
movl 0x10(%rsi), %edi
movl 0x14(%rsi), %esi
movl 0x4(%rdx), %ecx
movl 0x8(%rdx), %ebp
cmpl %ecx, %edi
movl %ecx, %r12d
cmoval %edi, %r12d
cmpl %ebp, %esi
movl %ebp, %r13d
cmovbl %esi, %r13d
cmpl %r12d, %r13d
jbe 0x1c8626
movl %ecx, 0x4(%rsp)
movl 0x4(%r14), %edx
movl 0x8(%r14), %ecx
movl 0x18(%r14), %r8d
shrl $0x1f, %r8d
subq $0x8, %rsp
leaq 0x18(%rsp), %rax
leaq 0x1c(%rsp), %r10
movl %r12d, %r9d
pushq %rax
pushq %r10
pushq %r13
callq 0x1c847b
addq $0x20, %rsp
testl %eax, %eax
je 0x1c8624
movl 0x10(%r15), %edx
movl 0x14(%r15), %ecx
movl 0x18(%r15), %r8d
shrl $0x1f, %r8d
subq $0x8, %rsp
leaq 0x10(%rsp), %rax
leaq 0x14(%rsp), %r10
movl 0xc(%rsp), %edi
movl %ebp, %esi
movl %r12d, %r9d
pushq %rax
pushq %r10
pushq %r13
callq 0x1c847b
addq $0x20, %rsp
testl %eax, %eax
je 0x1c8624
movl 0x10(%rsp), %r8d
movl 0x14(%rsp), %ecx
cmpl %ecx, %r8d
movl $0x0, %eax
jbe 0x1c8626
movl 0x8(%rsp), %edx
movl 0xc(%rsp), %esi
cmpl %esi, %edx
jbe 0x1c8626
movl (%r14), %edi
movl %edi, (%rbx)
movl 0xc(%r15), %edi
movl %edi, 0xc(%rbx)
movl 0x18(%r15), %edi
xorl 0x18(%r14), %edi
andl $0x80000000, %edi       # imm = 0x80000000
movl %edi, 0x18(%rbx)
movl %ecx, 0x4(%rbx)
movl %r8d, 0x8(%rbx)
movl %esi, 0x10(%rbx)
movl %edx, 0x14(%rbx)
movl $0x1, %eax
jmp 0x1c8626
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq