// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, %rbx
movq %rsi, (%rsp)
movq $0x0, 0x8(%rdx)
movl (%rdi), %r8d
movl 0xc(%rdi), %eax
leal (%r8,%r8), %r9d
movl 0x18(%rdi), %r15d
shrdl $0x1f, %eax, %r15d
movq 0x18(%rsi), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq (%rcx,%r9,8), %rdx
testl %edx, %edx
movq %r8, 0x18(%rsp)
je 0x1c887d
movq %r9, 0x40(%rsp)
movq %rdx, %rcx
shrq $0x20, %rcx
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rax
movq %rax, 0x8(%rsp)
movl %r8d, %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movl %edx, %eax
movq %rax, 0x48(%rsp)
xorl %eax, %eax
movq %rax, 0x10(%rsp)
leaq (%rax,%rax,2), %rax
movq 0x8(%rsp), %rcx
cmpl $0x0, 0xc(%rcx,%rax,8)
js 0x1c8855
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %rsi
movl 0x8(%rsi), %r14d
movq (%rsp), %rbp
movq %rbp, %rdi
leaq 0x24(%rsp), %rdx
callq 0x1c83c0
cmpl %r15d, %r14d
jne 0x1c8753
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x1c8728
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
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups 0x24(%rsp), %xmm0
movups 0x30(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
jmp 0x1c8855
movq 0x18(%rbp), %rax
movq 0x28(%rax), %rcx
xorq $0x1, %r14
movq (%rcx,%r14,8), %rcx
testl %ecx, %ecx
je 0x1c8855
movq %rcx, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rbp
shlq $0x3, %rbp
addq 0x8(%rax), %rbp
movl %ecx, %r14d
cmpl $0x0, 0xc(%rbp)
js 0x1c8848
movl 0x8(%rbp), %eax
movl %eax, %ecx
shrl %ecx
cmpl %r13d, %ecx
setne %cl
xorl %r15d, %eax
cmpl $0x1, %eax
sete %al
andb %cl, %al
cmpb $0x1, %al
jne 0x1c8848
movq (%rsp), %rdi
movq %rbp, %rsi
movq %rbx, %r12
movl %r15d, %ebx
movl %r13d, %r15d
leaq 0x6c(%rsp), %r13
movq %r13, %rdx
callq 0x1c83c0
leaq 0x24(%rsp), %rsi
movq %r13, %rdx
movl %r15d, %r13d
movl %ebx, %r15d
movq %r12, %rbx
leaq 0x50(%rsp), %rcx
callq 0x1c850b
testl %eax, %eax
je 0x1c8848
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x1c8822
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
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups 0x50(%rsp), %xmm0
movups 0x5c(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
addq $0x18, %rbp
decq %r14
jne 0x1c8781
movq 0x10(%rsp), %rax
incq %rax
cmpq 0x48(%rsp), %rax
jne 0x1c86b1
movq (%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x8(%rcx), %rax
movq 0x28(%rcx), %rcx
movq 0x40(%rsp), %r9
movl %r9d, %edx
movq 0x8(%rcx,%rdx,8), %rcx
testl %ecx, %ecx
je 0x1c8a60
movq %rcx, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rax
movq %rax, 0x10(%rsp)
movq 0x18(%rsp), %rax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movq %rax, 0x18(%rsp)
movl %ecx, %eax
movq %rax, 0x8(%rsp)
xorl %r13d, %r13d
leaq 0x6c(%rsp), %r12
leaq (,%r13,2), %rax
addq %r13, %rax
movq 0x10(%rsp), %rcx
cmpl $0x0, 0xc(%rcx,%rax,8)
js 0x1c8a52
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,8), %rsi
movl 0x8(%rsi), %r14d
movq (%rsp), %rbp
movq %rbp, %rdi
leaq 0x24(%rsp), %rdx
callq 0x1c83c0
movl %r14d, %eax
xorl %r15d, %eax
cmpl $0x1, %eax
jne 0x1c8969
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x1c893e
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
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups 0x24(%rsp), %xmm0
movups 0x30(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
jmp 0x1c8a52
movq 0x18(%rbp), %rax
movq 0x28(%rax), %rcx
xorq $0x1, %r14
movq (%rcx,%r14,8), %rcx
testl %ecx, %ecx
je 0x1c8a52
movq %rcx, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rbp
shlq $0x3, %rbp
addq 0x8(%rax), %rbp
movl %ecx, %r14d
cmpl $0x0, 0xc(%rbp)
js 0x1c8a45
movl 0x8(%rbp), %eax
movl %eax, %ecx
shrl %ecx
cmpl 0x18(%rsp), %ecx
setne %cl
cmpl %r15d, %eax
sete %al
andb %cl, %al
cmpb $0x1, %al
jne 0x1c8a45
movq (%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x1c83c0
leaq 0x24(%rsp), %rsi
movq %r12, %rdx
leaq 0x50(%rsp), %rcx
callq 0x1c850b
testl %eax, %eax
je 0x1c8a45
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x1c8a1f
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
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups 0x50(%rsp), %xmm0
movups 0x5c(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
addq $0x18, %rbp
decq %r14
jne 0x1c8997
incq %r13
cmpq 0x8(%rsp), %r13
jne 0x1c88bf
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq