// File: chhylp123[P]hifiasm/inter.cpp
// Function: gen_shared_interval(ul_ov_t*, ma_ug_t*, kv_ul_ov_t*)
void gen_shared_interval(ul_ov_t *p, ma_ug_t *ug, kv_ul_ov_t *res)
{
	uint32_t st, et, v, w, i, k, nv, nw; asg_arc_t *av, *aw;
	ul_ov_t s1, s2, rr; res->n = 0;

	st = p->qn<<1; et = (p->tn<<1) + (!!(p->rev));
	// if(p->qn == 101 && p->tn == 102) {
	// if(p->qn == 97 && p->tn == 98) {
	// 	fprintf(stderr, ">[M::%s]\tutg%.6u%c(%c)->utg%.6u%c(%c)\n", __func__, 
	// 			(st>>1)+1, "lc"[ug->u.a[st>>1].circ], "+-"[st&1],
	// 			(et>>1)+1, "lc"[ug->u.a[et>>1].circ], "+-"[et&1]);
	// }
	v = st; av = asg_arc_a(ug->g, v); nv = asg_arc_n(ug->g, v);
	for (i = 0; i < nv; i++) {
        if(av[i].del) continue;
		w = av[i].v;
		cal_s_interval(ug, &(av[i]), &s1);
		// if(p->qn == 101 && p->tn == 102) {
		// if(p->qn == 97 && p->tn == 98) {
		// 	fprintf(stderr, "+[M::%s]\tutg%.6lu%c(%c)->utg%.6u%c(%c)\n", __func__, 
		// 		(av[i].ul>>33)+1, "lc"[ug->u.a[(av[i].ul>>33)].circ], "+-"[(av[i].ul>>32)&1],
		// 		(av[i].v>>1)+1, "lc"[ug->u.a[av[i].v>>1].circ], "+-"[av[i].v&1]);
		// }
		if(w == et) {
			kv_push(ul_ov_t, *res, s1);
		} else {
			aw = asg_arc_a(ug->g, (w^1)); nw = asg_arc_n(ug->g, (w^1));
			for (k = 0; k < nw; k++) {
				if(aw[k].del) continue;
				if((aw[k].v>>1) == (st>>1)) continue;
				// if(p->qn == 101 && p->tn == 102) {
				// if(p->qn == 97 && p->tn == 98) {
				// 	fprintf(stderr, "-[M::%s]\tutg%.6lu%c(%c)->utg%.6u%c(%c)\n", __func__, 
				// 		(aw[k].ul>>33)+1, "lc"[ug->u.a[(aw[k].ul>>33)].circ], "+-"[(aw[k].ul>>32)&1],
				// 		(aw[k].v>>1)+1, "lc"[ug->u.a[aw[k].v>>1].circ], "+-"[aw[k].v&1]);
				// }
				// cal_s_interval(ug, &(aw[k]), &s2);
				// if(!cal_x_interval(ug, &s1, &s2, &rr)) continue;

				if(aw[k].v == (et^1)) {
					// if(p->qn == 101 && p->tn == 102) {
					// if(p->qn == 97 && p->tn == 98) {
					// 	fprintf(stderr, "*[M::%s]\tutg%.6lu%c(%c)->utg%.6u%c(%c)\n", __func__, 
					// 		(aw[k].ul>>33)+1, "lc"[ug->u.a[(aw[k].ul>>33)].circ], "+-"[(aw[k].ul>>32)&1],
					// 		(aw[k].v>>1)+1, "lc"[ug->u.a[aw[k].v>>1].circ], "+-"[aw[k].v&1]);
					// }
					cal_s_interval(ug, &(aw[k]), &s2);
					if(cal_x_interval(ug, &s1, &s2, &rr)) {
						kv_push(ul_ov_t, *res, rr);
					}
				}
			}
		}
    }

	st ^= 1; et ^= 1;
	v = st; av = asg_arc_a(ug->g, v); nv = asg_arc_n(ug->g, v);
	for (i = 0; i < nv; i++) {
        if(av[i].del) continue;
		w = av[i].v;
		cal_s_interval(ug, &(av[i]), &s1);
		// if(p->qn == 101 && p->tn == 102) {
		// if(p->qn == 97 && p->tn == 98) {
		// 	fprintf(stderr, "+[M::%s]\tutg%.6lu%c(%c)->utg%.6u%c(%c)\n", __func__, 
		// 		(av[i].ul>>33)+1, "lc"[ug->u.a[(av[i].ul>>33)].circ], "+-"[(av[i].ul>>32)&1],
		// 		(av[i].v>>1)+1, "lc"[ug->u.a[av[i].v>>1].circ], "+-"[av[i].v&1]);
		// }
		if(w == et) {
			kv_push(ul_ov_t, *res, s1);
		} else {
			aw = asg_arc_a(ug->g, (w^1)); nw = asg_arc_n(ug->g, (w^1));
			for (k = 0; k < nw; k++) {
				if(aw[k].del) continue;
				if((aw[k].v>>1) == (st>>1)) continue;
				// if(p->qn == 101 && p->tn == 102) {
				// if(p->qn == 97 && p->tn == 98) {
				// 	fprintf(stderr, "-[M::%s]\tutg%.6lu%c(%c)->utg%.6u%c(%c)\n", __func__, 
				// 		(aw[k].ul>>33)+1, "lc"[ug->u.a[(aw[k].ul>>33)].circ], "+-"[(aw[k].ul>>32)&1],
				// 		(aw[k].v>>1)+1, "lc"[ug->u.a[aw[k].v>>1].circ], "+-"[aw[k].v&1]);
				// }
				if(aw[k].v == (et^1)) {
					// if(p->qn == 101 && p->tn == 102) {
					// if(p->qn == 97 && p->tn == 98) {
					// 	fprintf(stderr, "*[M::%s]\tutg%.6lu%c(%c)->utg%.6u%c(%c)\n", __func__, 
					// 		(aw[k].ul>>33)+1, "lc"[ug->u.a[(aw[k].ul>>33)].circ], "+-"[(aw[k].ul>>32)&1],
					// 		(aw[k].v>>1)+1, "lc"[ug->u.a[aw[k].v>>1].circ], "+-"[aw[k].v&1]);
					// }
					cal_s_interval(ug, &(aw[k]), &s2);
					if(cal_x_interval(ug, &s1, &s2, &rr)) {
						kv_push(ul_ov_t, *res, rr);
					}
				}
			}
		}
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x8(%rbp), %rax
movl (%rax), %eax
shll %eax
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rax
movl 0xc(%rax), %eax
shll %eax
movq -0x8(%rbp), %rcx
movl 0x18(%rcx), %ecx
shrl $0x1f, %ecx
cmpl $0x0, %ecx
setne %cl
xorb $-0x1, %cl
xorb $-0x1, %cl
andb $0x1, %cl
movzbl %cl, %ecx
addl %ecx, %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x24(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x24(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x34(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x2c52da
movq -0x40(%rbp), %rax
movl -0x2c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2c5013
jmp 0x2c52cc
movq -0x40(%rbp), %rax
movl -0x2c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x2c(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rsi
leaq -0x64(%rbp), %rdx
callq 0x2c4a30
movl -0x28(%rbp), %eax
cmpl -0x20(%rbp), %eax
jne 0x2c5100
jmp 0x2c5050
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2c50bd
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2c5081
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0xa8(%rbp)
jmp 0x2c508f
movl $0x2, %eax
movq %rax, -0xa8(%rbp)
jmp 0x2c508f
movq -0xa8(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0x64(%rbp), %rcx
movq %rcx, (%rax)
movq -0x5c(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x54(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x4c(%rbp), %ecx
movl %ecx, 0x18(%rax)
jmp 0x2c52ca
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x28(%rbp), %edx
xorl $0x1, %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x28(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x38(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x2c52c8
movq -0x48(%rbp), %rax
movl -0x30(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2c517f
jmp 0x2c52ba
movq -0x48(%rbp), %rax
movl -0x30(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shrl %eax
movl -0x1c(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0x2c51a0
jmp 0x2c52ba
movq -0x48(%rbp), %rax
movl -0x30(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl -0x20(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2c52b8
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl -0x30(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rsi
leaq -0x80(%rbp), %rdx
callq 0x2c4a30
movq -0x10(%rbp), %rdi
leaq -0x64(%rbp), %rsi
leaq -0x80(%rbp), %rdx
leaq -0x9c(%rbp), %rcx
callq 0x2c4d40
cmpl $0x0, %eax
je 0x2c52b6
jmp 0x2c51fd
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2c526a
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2c522e
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0xb0(%rbp)
jmp 0x2c523c
movl $0x2, %eax
movq %rax, -0xb0(%rbp)
jmp 0x2c523c
movq -0xb0(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0x9c(%rbp), %rcx
movq %rcx, (%rax)
movq -0x94(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x8c(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x84(%rbp), %ecx
movl %ecx, 0x18(%rax)
jmp 0x2c52b6
jmp 0x2c52b8
jmp 0x2c52ba
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x2c5155
jmp 0x2c52ca
jmp 0x2c52cc
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2c4fe9
movl -0x1c(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x1c(%rbp)
movl -0x20(%rbp), %eax
xorl $0x1, %eax
movl %eax, -0x20(%rbp)
movl -0x1c(%rbp), %eax
movl %eax, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x24(%rbp), %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x24(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x34(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x34(%rbp), %eax
jae 0x2c562e
movq -0x40(%rbp), %rax
movl -0x2c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2c5367
jmp 0x2c5620
movq -0x40(%rbp), %rax
movl -0x2c(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, -0x28(%rbp)
movq -0x10(%rbp), %rdi
movq -0x40(%rbp), %rsi
movl -0x2c(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rsi
leaq -0x64(%rbp), %rdx
callq 0x2c4a30
movl -0x28(%rbp), %eax
cmpl -0x20(%rbp), %eax
jne 0x2c5454
jmp 0x2c53a4
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2c5411
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2c53d5
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0xb8(%rbp)
jmp 0x2c53e3
movl $0x2, %eax
movq %rax, -0xb8(%rbp)
jmp 0x2c53e3
movq -0xb8(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0x64(%rbp), %rcx
movq %rcx, (%rax)
movq -0x5c(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x54(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x4c(%rbp), %ecx
movl %ecx, 0x18(%rax)
jmp 0x2c561e
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x8(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x18(%rcx), %rcx
movq 0x28(%rcx), %rcx
movl -0x28(%rbp), %edx
xorl $0x1, %edx
movl %edx, %edx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq 0x28(%rax), %rax
movl -0x28(%rbp), %ecx
xorl $0x1, %ecx
movl %ecx, %ecx
movq (%rax,%rcx,8), %rax
movl %eax, -0x38(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x38(%rbp), %eax
jae 0x2c561c
movq -0x48(%rbp), %rax
movl -0x30(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %eax
shrl $0x1f, %eax
cmpl $0x0, %eax
je 0x2c54d3
jmp 0x2c560e
movq -0x48(%rbp), %rax
movl -0x30(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
shrl %eax
movl -0x1c(%rbp), %ecx
shrl %ecx
cmpl %ecx, %eax
jne 0x2c54f4
jmp 0x2c560e
movq -0x48(%rbp), %rax
movl -0x30(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl -0x20(%rbp), %ecx
xorl $0x1, %ecx
cmpl %ecx, %eax
jne 0x2c560c
movq -0x10(%rbp), %rdi
movq -0x48(%rbp), %rsi
movl -0x30(%rbp), %eax
imulq $0x18, %rax, %rax
addq %rax, %rsi
leaq -0x80(%rbp), %rdx
callq 0x2c4a30
movq -0x10(%rbp), %rdi
leaq -0x64(%rbp), %rsi
leaq -0x80(%rbp), %rdx
leaq -0x9c(%rbp), %rcx
callq 0x2c4d40
cmpl $0x0, %eax
je 0x2c560a
jmp 0x2c5551
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2c55be
movq -0x18(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2c5582
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0xc0(%rbp)
jmp 0x2c5590
movl $0x2, %eax
movq %rax, -0xc0(%rbp)
jmp 0x2c5590
movq -0xc0(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0x9c(%rbp), %rcx
movq %rcx, (%rax)
movq -0x94(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x8c(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x84(%rbp), %ecx
movl %ecx, 0x18(%rax)
jmp 0x2c560a
jmp 0x2c560c
jmp 0x2c560e
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x2c54a9
jmp 0x2c561e
jmp 0x2c5620
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2c533d
addq $0xc0, %rsp
popq %rbp
retq
nopw (%rax,%rax)