// File: /workspace/github_cpp_makefile_star2_O3/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, 0x10(%rsp)
movq %rcx, %r11
movq %rdx, %r13
movq %rsi, %r12
movq %rdi, %r14
movq 0x60(%rsp), %rax
testq %rax, %rax
je 0x1df77e
movq $0x0, (%rax)
cmpq $-0x1, %r12
je 0x1df7bf
movq 0x20(%r14), %rax
movq %r12, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x1dfc10
xorl %ebp, %ebp
movq %r14, %rdi
movl %r12d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r8, %rbx
movq %r11, %r15
callq 0x1efacc
movq %r15, %r11
movq %rbx, %r8
cmpl $0x2, %eax
jb 0x1dfc12
cmpq $-0x1, %r13
je 0x1df818
movq 0x20(%r14), %rax
movq %r13, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x1dfc10
movl %r13d, %esi
xorl $0x1, %esi
xorl %ebp, %ebp
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r8, %rbx
movq %r11, %r15
callq 0x1efacc
cmpl $0x2, %eax
jb 0x1dfc12
movq %r15, %r11
movq %rbx, %r8
cmpq $-0x1, %r12
sete %al
testq %rbx, %rbx
setne %cl
orb %al, %cl
je 0x1dfa8b
cmpq $-0x1, %r12
je 0x1df826
xorl %r9d, %r9d
movq %r12, %rbx
jmp 0x1df83c
movq (%r11), %rbx
movq %rbx, %rax
shrq $0x20, %rax
movl $0x1, %r9d
jne 0x1dfcd3
movq $-0x1, %r15
cmpq %r8, %r9
jae 0x1dfa00
xorl %ebp, %ebp
movq %r11, 0x8(%rsp)
movq %rbx, %rsi
movq (%r11,%r9,8), %rbx
movq %rbx, %rax
shrq $0x20, %rax
jne 0x1dfcb4
movq 0x20(%r14), %rax
movq %rsi, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x1dfc12
movq %rbx, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x1dfc12
movq 0x28(%r14), %rdx
movq (%rdx,%rsi,8), %rcx
movq %rcx, %rdi
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
andq %rax, %rdi
je 0x1dfc12
movq %r9, 0x20(%rsp)
movq 0x8(%r14), %rax
shrq $0x20, %rcx
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdi
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %r9
addq $0x10, %r9
xorl %r11d, %r11d
cmpl $0x0, -0x4(%r9,%r11)
js 0x1df8dc
movl -0x8(%r9,%r11), %r10d
cmpq %r10, %rbx
je 0x1df8ea
addq $0x18, %r11
cmpq %r11, %rdi
jne 0x1df8ca
jmp 0x1dfc12
leaq (%rax,%rcx,8), %rcx
movzwl 0x10(%r11,%rcx), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
cmpq %rcx, %r15
cmovbq %r15, %rcx
movq %rbx, %r15
xorq $0x1, %r15
movq (%rdx,%r15,8), %rdx
movq %rdx, %rdi
movl $0xffffffff, %r9d       # imm = 0xFFFFFFFF
andq %r9, %rdi
je 0x1dfc12
shrq $0x20, %rdx
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdi
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %r9
addq $0x10, %r9
xorl %r11d, %r11d
cmpl $0x0, -0x4(%r9,%r11)
js 0x1df94f
movl -0x8(%r9,%r11), %r10d
xorq %rsi, %r10
cmpq $0x1, %r10
je 0x1df95d
addq $0x18, %r11
cmpq %r11, %rdi
jne 0x1df939
jmp 0x1dfc12
leaq (%rax,%rdx,8), %rax
movzwl 0x10(%r11,%rax), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cmpq %rax, %rcx
cmovbq %rcx, %rax
movq %rax, (%rsp)
cmpq $0x0, 0x10(%rsp)
movq 0x8(%rsp), %r11
je 0x1df9eb
cmpq %r12, %rsi
sete %al
cmpq %r13, %rsi
sete %cl
orb %al, %cl
jne 0x1df9b8
movq %r14, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r8, 0x18(%rsp)
callq 0x1efacc
movq 0x8(%rsp), %r11
movq 0x18(%rsp), %r8
cmpl $0x1, %eax
jne 0x1dfc12
cmpq %r12, %rbx
sete %al
cmpq %r13, %rbx
sete %cl
orb %al, %cl
jne 0x1df9eb
movq %r14, %rdi
movl %r15d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r8, %r15
callq 0x1efacc
movq 0x8(%rsp), %r11
movq %r15, %r8
cmpl $0x1, %eax
jne 0x1dfc12
movq 0x20(%rsp), %r9
incq %r9
cmpq %r8, %r9
movq (%rsp), %r15
jne 0x1df853
cmpq $-0x1, %r13
je 0x1dfae1
movq 0x20(%r14), %rax
movq %rbx, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x1dfc10
movq %r13, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x1dfc10
movq 0x28(%r14), %rdx
movq (%rdx,%rbx,8), %rcx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rcx, %rsi
je 0x1dfc10
movq 0x8(%r14), %rax
shrq $0x20, %rcx
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,8), %rdi
addq $0x10, %rdi
xorl %ebp, %ebp
xorl %r10d, %r10d
cmpl $0x0, -0x4(%rdi,%r10)
js 0x1dfa7d
movl -0x8(%rdi,%r10), %r9d
cmpq %r13, %r9
je 0x1dfba6
addq $0x18, %r10
cmpq %r10, %rsi
jne 0x1dfa67
jmp 0x1dfc12
movq 0x28(%r14), %rcx
movq (%rcx,%r12,8), %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rdx, %rsi
je 0x1dfc10
movq 0x8(%r14), %rax
shrq $0x20, %rdx
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rdi
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %r8
addq $0x10, %r8
xorl %ebp, %ebp
xorl %esi, %esi
cmpl $0x0, -0x4(%r8,%rsi)
js 0x1dfad3
movl -0x8(%r8,%rsi), %r9d
cmpq %r13, %r9
je 0x1dfb40
addq $0x18, %rsi
cmpq %rsi, %rdi
jne 0x1dfac1
jmp 0x1dfc12
movq %r15, (%rsp)
movq %r8, %r15
movq (%r11), %rsi
xorq $0x1, %rsi
movq %r14, %rdi
movq %r11, %r12
callq 0x1df68f
testq %rax, %rax
je 0x1dfc10
cmpq $0x0, 0x60(%rsp)
sete %bl
movq -0x8(%r12,%r15,8), %rsi
movq %r14, %rdi
callq 0x1df68f
movq %rax, %rbp
testq %rax, %rax
sete %al
orb %bl, %al
jne 0x1dfc12
movq 0x60(%rsp), %rax
movq (%rsp), %rcx
movq %rcx, (%rax)
movl $0x1, %ebp
jmp 0x1dfc12
xorq $0x1, %r13
movq (%rcx,%r13,8), %r8
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
andq %r8, %rdi
je 0x1dfc10
leaq (%rax,%rdx,8), %rcx
movzwl 0x10(%rsi,%rcx), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
shrq $0x20, %r8
shlq $0x3, %rdi
leaq (%rdi,%rdi,2), %rdi
leaq (%r8,%r8,2), %rdx
leaq (%rax,%rdx,8), %r8
addq $0x10, %r8
xorl %ebp, %ebp
xorl %esi, %esi
cmpl $0x0, -0x4(%r8,%rsi)
js 0x1dfb9b
movl -0x8(%r8,%rsi), %r9d
xorq %r12, %r9
cmpq $0x1, %r9
je 0x1dfc24
addq $0x18, %rsi
cmpq %rsi, %rdi
jne 0x1dfb81
jmp 0x1dfc12
leaq (%rax,%rcx,8), %rcx
movzwl 0x10(%r10,%rcx), %ecx
andl $0x3fff, %ecx           # imm = 0x3FFF
cmpq %rcx, %r15
cmovbq %r15, %rcx
movq %r13, %rsi
xorq $0x1, %rsi
movq (%rdx,%rsi,8), %rdx
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %rdx, %rsi
je 0x1dfc10
shrq $0x20, %rdx
shlq $0x3, %rsi
leaq (%rsi,%rsi,2), %rsi
leaq (%rdx,%rdx,2), %rdx
leaq (%rax,%rdx,8), %rdi
addq $0x10, %rdi
xorl %ebp, %ebp
xorl %r10d, %r10d
cmpl $0x0, -0x4(%rdi,%r10)
js 0x1dfc05
movl -0x8(%rdi,%r10), %r9d
xorq %rbx, %r9
cmpq $0x1, %r9
je 0x1dfc50
addq $0x18, %r10
cmpq %r10, %rsi
jne 0x1dfbef
jmp 0x1dfc12
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0x60(%rsp)
je 0x1dfb36
leaq (%rax,%rdx,8), %rax
movzwl 0x10(%rsi,%rax), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cmpw %ax, %cx
cmovael %eax, %ecx
movzwl %cx, %eax
movq %rax, (%rsp)
jmp 0x1dfb2a
leaq (%rax,%rdx,8), %rax
movzwl 0x10(%r10,%rax), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cmpq %rax, %rcx
cmovbq %rcx, %rax
cmpq $0x0, 0x10(%rsp)
movq %rax, (%rsp)
je 0x1dfae5
cmpq %r12, %rbx
sete %al
cmpq %r13, %rbx
sete %cl
orb %al, %cl
jne 0x1dfae5
xorl %ebp, %ebp
movq %r14, %rdi
movl %ebx, %esi
xorl %edx, %edx
xorl %ecx, %ecx
movq %r8, %rbx
movq %r11, %r15
callq 0x1efacc
movq %r15, %r11
movq %rbx, %r8
cmpl $0x1, %eax
je 0x1dfae5
jmp 0x1dfc12
leaq 0x64028(%rip), %rdi     # 0x243ce3
leaq 0x5ff99(%rip), %rsi     # 0x23fc5b
leaq 0x63fb8(%rip), %rcx     # 0x243c81
movl $0x4ab1, %edx           # imm = 0x4AB1
callq 0x2110
leaq 0x63f9a(%rip), %rdi     # 0x243c74
leaq 0x5ff7a(%rip), %rsi     # 0x23fc5b
leaq 0x63f99(%rip), %rcx     # 0x243c81
movl $0x4aad, %edx           # imm = 0x4AAD
callq 0x2110