// File: 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
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x28(%rbp), %rdi
xorl %esi, %esi
movl $0x1c, %edx
callq 0x2100
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x2c4f2e
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jb 0x2c4d97
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x44(%rbp)
jmp 0x2c4da1
movq -0x20(%rbp), %rax
movl 0x4(%rax), %eax
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x20(%rbp), %rcx
cmpl 0x8(%rcx), %eax
ja 0x2c4dc3
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x48(%rbp)
jmp 0x2c4dcd
movq -0x20(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x48(%rbp)
movl -0x48(%rbp), %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x2c(%rbp), %eax
ja 0x2c4de7
movl $0x0, -0x4(%rbp)
jmp 0x2c4f35
movq -0x18(%rbp), %rax
movl 0x10(%rax), %edi
movq -0x18(%rbp), %rax
movl 0x14(%rax), %esi
movq -0x18(%rbp), %rax
movl 0x4(%rax), %edx
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
movq -0x18(%rbp), %rax
movl 0x18(%rax), %r8d
shrl $0x1f, %r8d
movl -0x2c(%rbp), %r9d
movl -0x30(%rbp), %r11d
leaq -0x34(%rbp), %r10
leaq -0x38(%rbp), %rax
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x2c4c30
cmpl $0x0, %eax
je 0x2c4f2c
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x20(%rbp), %rax
movl 0x8(%rax), %esi
movq -0x20(%rbp), %rax
movl 0x10(%rax), %edx
movq -0x20(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x20(%rbp), %rax
movl 0x18(%rax), %r8d
shrl $0x1f, %r8d
movl -0x2c(%rbp), %r9d
movl -0x30(%rbp), %r11d
leaq -0x3c(%rbp), %r10
leaq -0x40(%rbp), %rax
movl %r11d, (%rsp)
movq %r10, 0x8(%rsp)
movq %rax, 0x10(%rsp)
callq 0x2c4c30
cmpl $0x0, %eax
je 0x2c4f2c
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jbe 0x2c4f2a
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jbe 0x2c4f2a
movq -0x18(%rbp), %rax
movl (%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl 0xc(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x18(%rbp), %rax
movl 0x18(%rax), %ecx
shrl $0x1f, %ecx
movq -0x20(%rbp), %rax
movl 0x18(%rax), %esi
shrl $0x1f, %esi
movl $0x1, %edx
xorl %eax, %eax
cmpl %esi, %ecx
cmovel %eax, %edx
movq -0x28(%rbp), %rax
movl 0x18(%rax), %ecx
andl $0x1, %edx
shll $0x1f, %edx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
orl %edx, %ecx
movl %ecx, 0x18(%rax)
movl -0x34(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x38(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x3c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movl -0x40(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x14(%rax)
movl $0x1, -0x4(%rbp)
jmp 0x2c4f35
jmp 0x2c4f2c
jmp 0x2c4f2e
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x60, %rsp
popq %rbp
retq
nop