// File: /workspace/github_cpp_makefile_star2_O1/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 $0x0, 0x8(%rdx)
movl (%rdi), %ecx
movl 0xc(%rdi), %eax
movq %rcx, 0x18(%rsp)
leal (%rcx,%rcx), %edx
movl 0x18(%rdi), %r15d
shrdl $0x1f, %eax, %r15d
movq %rsi, (%rsp)
movq 0x18(%rsi), %rcx
movq 0x28(%rcx), %rax
movq %rdx, 0x40(%rsp)
movq (%rax,%rdx,8), %rax
testl %eax, %eax
je 0x1bea5f
movq %rax, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x3, %rdx
addq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movq 0x18(%rsp), %rcx
movl %ecx, %r13d
andl $0x7fffffff, %r13d      # imm = 0x7FFFFFFF
movl %eax, %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 0x1bea4c
movq 0x8(%rsp), %rcx
leaq (%rcx,%rax,8), %rsi
movl 0x8(%rsi), %r14d
movq (%rsp), %rbp
movq %rbp, %rdi
leaq 0x24(%rsp), %rdx
callq 0x1be59e
cmpl %r15d, %r14d
jne 0x1be950
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x1be91e
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%rbx)
movq (%rbx), %rax
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 0x1bea4c
movq 0x18(%rbp), %rax
movq 0x28(%rax), %rcx
xorq $0x1, %r14
movq (%rcx,%r14,8), %rcx
testl %ecx, %ecx
je 0x1bea4c
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 0x1bea3f
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 0x1bea3f
movq (%rsp), %rdi
movq %rbp, %rsi
movl %r15d, %r12d
movl %r13d, %r15d
leaq 0x6c(%rsp), %r13
movq %r13, %rdx
callq 0x1be59e
leaq 0x24(%rsp), %rsi
movq %r13, %rdx
movl %r15d, %r13d
movl %r12d, %r15d
leaq 0x50(%rsp), %rcx
callq 0x1be6f7
testl %eax, %eax
je 0x1bea3f
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x1bea12
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%rbx)
movq (%rbx), %rax
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 0x1be97e
movq 0x10(%rsp), %rax
incq %rax
cmpq 0x48(%rsp), %rax
jne 0x1be8ae
movq (%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x28(%rcx), %rax
movl 0x40(%rsp), %edx
movq 0x8(%rax,%rdx,8), %rax
testl %eax, %eax
je 0x1bec54
movq %rax, %rdx
shrq $0x20, %rdx
leaq (%rdx,%rdx,2), %rdx
shlq $0x3, %rdx
addq 0x8(%rcx), %rdx
movq %rdx, 0x10(%rsp)
movq 0x18(%rsp), %rcx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movq %rcx, 0x18(%rsp)
movl %eax, %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 0x1bec46
movq 0x10(%rsp), %rcx
leaq (%rcx,%rax,8), %rsi
movl 0x8(%rsi), %r14d
movq (%rsp), %rbp
movq %rbp, %rdi
leaq 0x24(%rsp), %rdx
callq 0x1be59e
movl %r14d, %eax
xorl %r15d, %eax
cmpl $0x1, %eax
jne 0x1beb5d
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x1beb2b
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%rbx)
movq (%rbx), %rax
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 0x1bec46
movq 0x18(%rbp), %rax
movq 0x28(%rax), %rcx
xorq $0x1, %r14
movq (%rcx,%r14,8), %rcx
testl %ecx, %ecx
je 0x1bec46
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 0x1bec39
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 0x1bec39
movq (%rsp), %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x1be59e
leaq 0x24(%rsp), %rsi
movq %r12, %rdx
leaq 0x50(%rsp), %rcx
callq 0x1be6f7
testl %eax, %eax
je 0x1bec39
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x1bec0c
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%rbx)
movq (%rbx), %rax
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 0x1beb8b
incq %r13
cmpq 0x8(%rsp), %r13
jne 0x1beab3
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq