// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: tes_path_connec(asg_t*, unsigned long, unsigned long, unsigned long*, unsigned long, unsigned long, unsigned long*)
uint64_t tes_path_connec(asg_t *g, uint64_t sn, uint64_t en, uint64_t *pa, uint64_t pn, uint64_t is_single_path, uint64_t *min_ou)
{
	// fprintf(stderr, "-0-[M::%s::]\n", __func__); 
	if(min_ou) (*min_ou) = 0;
	if((sn != (uint64_t)-1) && ((g->seq[sn>>1].del)||(get_arcs(g, sn, NULL, 0)<2))) return 0;
	if((en != (uint64_t)-1) && ((g->seq[en>>1].del)||((get_arcs(g, en^1, NULL, 0)<2)))) return 0;
	uint64_t nv, k, v, w, i, ou = (uint64_t)-1; asg_arc_t *av;
	if((sn != (uint64_t)-1) && (en != (uint64_t)-1) && (!pn)) {
		v = sn; w = en;
		nv = asg_arc_n(g, v); av = asg_arc_a(g, v);
		for (k = 0; k < nv; k++) {
			if(av[k].del) continue;
			if(av[k].v == w) {
				if(((uint64_t)av[k].ou) < ou) ou = av[k].ou;
				break;
			}
		}
		if(k >= nv) return 0;
		
		v = en^1; w = sn^1;
		nv = asg_arc_n(g, v); av = asg_arc_a(g, v);
		for (k = 0; k < nv; k++) {
			if(av[k].del) continue;
			if(av[k].v == w) {
				if(((uint64_t)av[k].ou) < ou) ou = av[k].ou;
				break;
			}
		}
		if(k >= nv) return 0;

		// if(get_arcs(g, sn, NULL, 0) < 2) return 0;
		// if(get_arcs(g, en^1, NULL, 0) < 2) return 0;
		if(min_ou) (*min_ou) = ou;
		return 1;
	}

	// fprintf(stderr, "-1-[M::%s::]\n", __func__); 
	if(sn != (uint64_t)-1) {
		v = sn; i = 0;
	} else {
		v = pa[0]; i = 1; assert(!(pa[0]>>32));
	}
	// fprintf(stderr, "-2-[M::%s::]\n", __func__); 
	for (; i < pn; i++) {
		w = pa[i]; assert(!(pa[i]>>32));
		if(g->seq[v>>1].del || g->seq[w>>1].del) return 0;

		nv = asg_arc_n(g, v); av = asg_arc_a(g, v);
		for (k = 0; k < nv; k++) {
			if(av[k].del) continue;
			if(av[k].v == w) {
				if(((uint64_t)av[k].ou) < ou) ou = av[k].ou;
				break;
			}
		}
		if(k >= nv) return 0;

		nv = asg_arc_n(g, w^1); av = asg_arc_a(g, w^1);
		for (k = 0; k < nv; k++) {
			if(av[k].del) continue;
			if(av[k].v == (v^1)) {
				if(((uint64_t)av[k].ou) < ou) ou = av[k].ou;
				break;
			}
		}
		if(k >= nv) return 0;

		if(is_single_path) {
			if(v != sn && v != en && get_arcs(g, v, NULL, 0) != 1) return 0;
			if(w != sn && w != en && get_arcs(g, w^1, NULL, 0) != 1) return 0;
		}

		v = w;
	}
	// fprintf(stderr, "-3-[M::%s::]\n", __func__); 
	if(en != (uint64_t)-1) {
		w = en;
		if(g->seq[v>>1].del || g->seq[w>>1].del) return 0;
		// fprintf(stderr, "-3a-[M::%s::]\n", __func__); 
		nv = asg_arc_n(g, v); av = asg_arc_a(g, v);
		for (k = 0; k < nv; k++) {
			if(av[k].del) continue;
			if(av[k].v == w) {
				if(((uint64_t)av[k].ou) < ou) ou = av[k].ou;
				break;
			}
		}
		if(k >= nv) return 0;
		// fprintf(stderr, "-3b-[M::%s::]\n", __func__); 
		nv = asg_arc_n(g, w^1); av = asg_arc_a(g, w^1);
		for (k = 0; k < nv; k++) {
			if(av[k].del) continue;
			if(av[k].v == (v^1)) {
				if(((uint64_t)av[k].ou) < ou) ou = av[k].ou;
				break;
			}
		}
		if(k >= nv) return 0;

		if(is_single_path) {
			if(v != sn && v != en && get_arcs(g, v, NULL, 0) != 1) return 0;
			if(w != sn && w != en && get_arcs(g, w^1, NULL, 0) != 1) return 0;
		}
	}



	// fprintf(stderr, "-4-[M::%s::]\n", __func__); 
	if(!path_del_topo(g, pa[0]^1)) return 0;
	// if(sn != ((uint64_t)-1)) {
	// 	v = sn; w = pa[0];
	// 	nv = asg_arc_n(g, v); av = asg_arc_a(g, v);
	// 	for (k = 0; k < nv; k++) {
	// 		if(av[k].del) continue;
	// 		if(av[k].v == w) break;
	// 	}
	// 	if(k >= nv) return 0;

	// 	v = pa[0]^1; w = sn^1;
	// 	nv = asg_arc_n(g, v); av = asg_arc_a(g, v);
	// 	for (k = 0; k < nv; k++) {
	// 		if(av[k].del) continue;
	// 		if(av[k].v == w) break;
	// 	}
	// 	if(k >= nv) return 0;
	// }



	if(!path_del_topo(g, pa[pn-1])) return 0;
	// if(en != ((uint64_t)-1)) {
	// 	v = pa[pn-1]; w = en;
	// 	nv = asg_arc_n(g, v); av = asg_arc_a(g, v);
	// 	for (k = 0; k < nv; k++) {
	// 		if(av[k].del) continue;
	// 		if(av[k].v == w) break;
	// 	}
	// 	if(k >= nv) return 0;

	// 	v = en^1; w = pa[pn-1]^1;
	// 	nv = asg_arc_n(g, v); av = asg_arc_a(g, v);
	// 	for (k = 0; k < nv; k++) {
	// 		if(av[k].del) continue;
	// 		if(av[k].v == w) break;
	// 	}
	// 	if(k >= nv) return 0;
	// }

	if(min_ou) (*min_ou) = ou;
	return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, 0x18(%rsp)
movq %rcx, %r11
movq %rdx, %r13
movq %rsi, %rbx
movq %rdi, %r14
movq 0x60(%rsp), %rax
testq %rax, %rax
je 0x1924e1
andq $0x0, (%rax)
cmpq $-0x1, %rbx
je 0x192521
movq 0x20(%r14), %rax
movq %rbx, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x192959
xorl %ebp, %ebp
movq %r14, %rdi
movl %ebx, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r8, %r15
movq %r11, %r12
callq 0x1a5422
movq %r12, %r11
movq %r15, %r8
cmpl $0x2, %eax
jb 0x19295b
cmpq $-0x1, %r13
je 0x19257a
movq 0x20(%r14), %rax
movq %r13, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x192959
movl %r13d, %esi
xorl $0x1, %esi
xorl %ebp, %ebp
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r8, %r15
movq %r11, %r12
callq 0x1a5422
cmpl $0x2, %eax
jb 0x19295b
movq %r12, %r11
movq %r15, %r8
cmpq $-0x1, %rbx
sete %al
testq %r15, %r15
setne %cl
orb %al, %cl
je 0x19272c
cmpq $-0x1, %rbx
je 0x192588
xorl %r15d, %r15d
movq %rbx, %rsi
jmp 0x19259c
movq (%r11), %rsi
movq %rsi, %rax
shrq $0x20, %rax
jne 0x1929aa
pushq $0x1
popq %r15
pushq $-0x1
popq %rax
movq %rax, (%rsp)
xorl %ebp, %ebp
cmpq %r8, %r15
jae 0x1927cc
movq (%r11,%r15,8), %r12
movq %r12, %rax
shrq $0x20, %rax
jne 0x19298b
movq 0x20(%r14), %rax
movq %rsi, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x19295b
movq %r12, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x19295b
movq 0x8(%r14), %rax
movq 0x28(%r14), %rdx
movq (%rdx,%rsi,8), %rdi
movl %edi, %ecx
shrq $0x20, %rdi
imulq $0x18, %rcx, %rcx
imulq $0x18, %rdi, %rdi
addq %rax, %rdi
addq $0x10, %rdi
xorl %r10d, %r10d
cmpq %r10, %rcx
je 0x19295b
cmpl $0x0, -0x4(%rdi,%r10)
js 0x192624
movl -0x8(%rdi,%r10), %r9d
cmpq %r9, %r12
je 0x19262a
addq $0x18, %r10
jmp 0x192609
movq %r11, 0x8(%rsp)
movzwl (%r10,%rdi), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
movq (%rsp), %rdi
cmpq %rcx, %rdi
cmovbq %rdi, %rcx
movq %r12, %rdi
xorq $0x1, %rdi
movq %rdi, 0x20(%rsp)
movq (%rdx,%rdi,8), %rdx
movl %edx, %edi
shrq $0x20, %rdx
imulq $0x18, %rdi, %rdi
imulq $0x18, %rdx, %rdx
leaq (%rax,%rdx), %r9
addq $0x10, %r9
xorl %r11d, %r11d
cmpq %r11, %rdi
je 0x19295b
cmpl $0x0, -0x4(%r9,%r11)
js 0x19268d
movl -0x8(%r9,%r11), %r10d
xorq %rsi, %r10
cmpq $0x1, %r10
je 0x192693
addq $0x18, %r11
jmp 0x19266e
addq %rdx, %rax
movzwl 0x10(%r11,%rax), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cmpq %rax, %rcx
cmovbq %rcx, %rax
movq %rax, (%rsp)
cmpq $0x0, 0x18(%rsp)
movq 0x8(%rsp), %r11
je 0x192721
cmpq %rbx, %rsi
sete %al
cmpq %r13, %rsi
sete %cl
orb %al, %cl
movq %r8, 0x10(%rsp)
jne 0x1926ed
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1a5422
movq 0x8(%rsp), %r11
movq 0x10(%rsp), %r8
cmpl $0x1, %eax
jne 0x19295b
cmpq %rbx, %r12
sete %al
cmpq %r13, %r12
sete %cl
orb %al, %cl
jne 0x192721
movq %r14, %rdi
movq 0x20(%rsp), %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1a5422
movq 0x8(%rsp), %r11
movq 0x10(%rsp), %r8
cmpl $0x1, %eax
jne 0x19295b
incq %r15
movq %r12, %rsi
jmp 0x1925a5
movq 0x8(%r14), %rax
movq 0x28(%r14), %rdx
movq (%rdx,%rbx,8), %rcx
movl %ecx, %esi
shrq $0x20, %rcx
imulq $0x18, %rsi, %rsi
imulq $0x18, %rcx, %rcx
leaq (%rcx,%rax), %r8
addq $0x10, %r8
xorl %ebp, %ebp
xorl %edi, %edi
cmpq %rdi, %rsi
je 0x19295b
cmpl $0x0, -0x4(%r8,%rdi)
js 0x19276d
movl -0x8(%r8,%rdi), %r9d
cmpq %r13, %r9
je 0x192773
addq $0x18, %rdi
jmp 0x192752
addq %rax, %rcx
movzwl 0x10(%rdi,%rcx), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
xorq $0x1, %r13
movq (%rdx,%r13,8), %rdx
movl %edx, %esi
shrq $0x20, %rdx
imulq $0x18, %rsi, %rdi
imulq $0x18, %rdx, %rdx
leaq (%rdx,%rax), %r8
addq $0x10, %r8
xorl %ebp, %ebp
xorl %esi, %esi
cmpq %rsi, %rdi
je 0x19295b
cmpl $0x0, -0x4(%r8,%rsi)
js 0x1927c6
movl -0x8(%r8,%rsi), %r9d
xorq %rbx, %r9
cmpq $0x1, %r9
je 0x192847
addq $0x18, %rsi
jmp 0x1927a3
cmpq $-0x1, %r13
je 0x192916
movq 0x20(%r14), %rax
movq %rsi, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x192959
movq %r13, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x192959
movq %r11, %r15
movq 0x8(%r14), %rax
movq 0x28(%r14), %rdx
movq (%rdx,%rsi,8), %rcx
movl %ecx, %edi
shrq $0x20, %rcx
imulq $0x18, %rdi, %rdi
imulq $0x18, %rcx, %rcx
leaq (%rcx,%rax), %r9
addq $0x10, %r9
xorl %ebp, %ebp
xorl %r11d, %r11d
cmpq %r11, %rdi
je 0x19295b
cmpl $0x0, -0x4(%r9,%r11)
js 0x192841
movl -0x8(%r9,%r11), %r10d
cmpq %r13, %r10
je 0x19287d
addq $0x18, %r11
jmp 0x192826
cmpq $0x0, 0x60(%rsp)
je 0x192875
addq %rax, %rdx
movzwl 0x10(%rsi,%rdx), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cmpw %ax, %cx
cmovael %eax, %ecx
movzwl %cx, %eax
movq %rax, (%rsp)
movq 0x60(%rsp), %rax
movq (%rsp), %rcx
movq %rcx, (%rax)
pushq $0x1
popq %rbp
jmp 0x19295b
addq %rax, %rcx
movzwl 0x10(%r11,%rcx), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
movq (%rsp), %rdi
cmpq %rcx, %rdi
cmovbq %rdi, %rcx
movq %r13, %rdi
xorq $0x1, %rdi
movq (%rdx,%rdi,8), %rdx
movl %edx, %edi
shrq $0x20, %rdx
imulq $0x18, %rdi, %rdi
imulq $0x18, %rdx, %rdx
leaq (%rdx,%rax), %r9
addq $0x10, %r9
xorl %ebp, %ebp
xorl %r11d, %r11d
cmpq %r11, %rdi
je 0x19295b
cmpl $0x0, -0x4(%r9,%r11)
js 0x1928dc
movl -0x8(%r9,%r11), %r10d
xorq %rsi, %r10
cmpq $0x1, %r10
je 0x1928e2
addq $0x18, %r11
jmp 0x1928bd
addq %rax, %rdx
movzwl 0x10(%r11,%rdx), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cmpq %rax, %rcx
cmovbq %rcx, %rax
cmpq $0x0, 0x18(%rsp)
movq %rax, (%rsp)
je 0x192913
cmpq %rbx, %rsi
sete %al
cmpq %r13, %rsi
sete %cl
orb %al, %cl
je 0x19296d
movq %r15, %r11
movq %r8, %r15
movq (%r11), %rsi
xorq $0x1, %rsi
movq %r14, %rdi
movq %r11, %r12
callq 0x19240e
testq %rax, %rax
je 0x192959
cmpq $0x0, 0x60(%rsp)
sete %bl
movq -0x8(%r12,%r15,8), %rsi
movq %r14, %rdi
callq 0x19240e
movq %rax, %rbp
testq %rax, %rax
sete %al
orb %bl, %al
je 0x192869
jmp 0x19295b
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %ebp, %ebp
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r8, %rbx
callq 0x1a5422
movq %rbx, %r8
cmpl $0x1, %eax
movq %r15, %r11
je 0x192916
jmp 0x19295b
leaq 0x63219(%rip), %rdi     # 0x1f5bab
leaq 0x5f18a(%rip), %rsi     # 0x1f1b23
leaq 0x631a9(%rip), %rcx     # 0x1f5b49
movl $0x4ab1, %edx           # imm = 0x4AB1
callq 0x2110
leaq 0x6318b(%rip), %rdi     # 0x1f5b3c
leaq 0x5f16b(%rip), %rsi     # 0x1f1b23
leaq 0x6318a(%rip), %rcx     # 0x1f5b49
movl $0x4aad, %edx           # imm = 0x4AAD
callq 0x2110