// File: /workspace/github_cpp_makefile_star2_O1/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, %rbp
movq %r8, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
movq 0x60(%rsp), %rbx
testq %rbx, %rbx
je 0x1d5806
movq $0x0, (%rbx)
cmpq $-0x1, %r12
je 0x1d583c
movq 0x20(%r15), %rax
movq %r12, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x1d5d67
xorl %r13d, %r13d
movq %r15, %rdi
movl %r12d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1e50d4
cmpl $0x2, %eax
jb 0x1d5d6a
cmpq $-0x1, %r14
je 0x1d5875
movq 0x20(%r15), %rax
movq %r14, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x1d5d67
movl %r14d, %esi
xorl $0x1, %esi
xorl %r13d, %r13d
movq %r15, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1e50d4
cmpl $0x2, %eax
jb 0x1d5d6a
cmpq $-0x1, %r12
je 0x1d5900
cmpq $-0x1, %r14
je 0x1d5900
cmpq $0x0, 0x18(%rsp)
jne 0x1d5900
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movq (%rcx,%r12,8), %r8
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
movq $-0x1, %rbp
andq %r8, %rsi
setne %dl
je 0x1d5bba
shrq $0x20, %r8
movq %rsi, %rdi
negq %rdi
leaq (%r8,%r8,2), %r8
leaq (%rax,%r8,8), %r8
addq $0x10, %r8
movl $0x1, %r9d
cmpl $0x0, -0x4(%r8)
js 0x1d58e1
movl -0x8(%r8), %r10d
cmpq %r14, %r10
je 0x1d5bb0
cmpq %rsi, %r9
setb %dl
leaq (%rdi,%r9), %r10
incq %r10
incq %r9
addq $0x18, %r8
cmpq $0x1, %r10
jne 0x1d58cd
jmp 0x1d5bba
movq %rbp, 0x20(%rsp)
cmpq $-0x1, %r12
movq %r12, 0x8(%rsp)
je 0x1d591c
xorl %ebp, %ebp
movq %r12, %rbx
movq 0x10(%rsp), %rcx
jmp 0x1d5936
movq 0x10(%rsp), %rcx
movq (%rcx), %rbx
movq %rbx, %rax
shrq $0x20, %rax
movl $0x1, %ebp
jne 0x1d5dc0
movq $-0x1, (%rsp)
cmpq 0x18(%rsp), %rbp
jae 0x1d5b0b
movq $-0x1, (%rsp)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movq %rbx, %rsi
movq (%rcx,%rbp,8), %rbx
movq %rbx, %rax
shrq $0x20, %rax
jne 0x1d5da1
movq 0x20(%r15), %rax
movq %rsi, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x1d5d67
movq %rbx, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x1d5d67
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movq (%rcx,%rsi,8), %r9
movq %r9, %rdi
andq %r13, %rdi
setne %dl
je 0x1d5a09
shrq $0x20, %r9
movq %rdi, %r8
negq %r8
leaq (%r9,%r9,2), %r9
leaq (%rax,%r9,8), %r9
addq $0x10, %r9
movl $0x1, %r10d
cmpl $0x0, -0x4(%r9)
js 0x1d59d4
movl -0x8(%r9), %r11d
cmpq %r11, %rbx
je 0x1d59f0
cmpq %rdi, %r10
setb %dl
leaq (%r8,%r10), %r11
incq %r11
incq %r10
addq $0x18, %r9
cmpq $0x1, %r11
jne 0x1d59c4
jmp 0x1d5a09
movzwl (%r9), %edi
andl $0x3fff, %edi           # imm = 0x3FFF
movq (%rsp), %r8
cmpq %rdi, %r8
cmovaeq %rdi, %r8
movq %r8, (%rsp)
testb $0x1, %dl
je 0x1d5d67
movq %rbx, %r12
xorq $0x1, %r12
movq (%rcx,%r12,8), %r8
movq %r8, %rdx
andq %r13, %rdx
setne %cl
je 0x1d5a8a
shrq $0x20, %r8
movq %rdx, %rdi
negq %rdi
leaq (%r8,%r8,2), %r8
leaq (%rax,%r8,8), %rax
addq $0x10, %rax
movl $0x1, %r8d
cmpl $0x0, -0x4(%rax)
js 0x1d5a57
movl -0x8(%rax), %r9d
xorq %rsi, %r9
cmpq $0x1, %r9
je 0x1d5a73
cmpq %rdx, %r8
setb %cl
leaq (%rdi,%r8), %r9
incq %r9
incq %r8
addq $0x18, %rax
cmpq $0x1, %r9
jne 0x1d5a44
jmp 0x1d5a8a
movzwl (%rax), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
movq (%rsp), %rdx
cmpq %rax, %rdx
cmovaeq %rax, %rdx
movq %rdx, (%rsp)
testb $0x1, %cl
je 0x1d5d67
cmpq $0x0, 0x20(%rsp)
je 0x1d5af2
cmpq 0x8(%rsp), %rsi
sete %al
cmpq %r14, %rsi
sete %cl
orb %al, %cl
jne 0x1d5ac5
xorl %r13d, %r13d
movq %r15, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1e50d4
cmpl $0x1, %eax
jne 0x1d5d6a
cmpq 0x8(%rsp), %rbx
sete %al
cmpq %r14, %rbx
sete %cl
orb %al, %cl
jne 0x1d5af2
xorl %r13d, %r13d
movq %r15, %rdi
movl %r12d, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1e50d4
cmpl $0x1, %eax
jne 0x1d5d6a
incq %rbp
cmpq 0x18(%rsp), %rbp
movq 0x10(%rsp), %rcx
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
jne 0x1d5957
cmpq $-0x1, %r14
je 0x1d5c26
movq 0x20(%r15), %rax
movq %rbx, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
movq (%rsp), %rbp
js 0x1d5d67
movq %r14, %rcx
andq $-0x2, %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x1d5d67
movq 0x8(%r15), %rax
movq 0x28(%r15), %rcx
movq (%rcx,%rbx,8), %r8
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
andq %r8, %rsi
setne %dl
je 0x1d5cae
shrq $0x20, %r8
movq %rsi, %rdi
negq %rdi
leaq (%r8,%r8,2), %r8
leaq (%rax,%r8,8), %r8
addq $0x10, %r8
movl $0x1, %r9d
movq 0x8(%rsp), %r11
cmpl $0x0, -0x4(%r8)
js 0x1d5b91
movl -0x8(%r8), %r10d
cmpq %r14, %r10
je 0x1d5cb5
cmpq %rsi, %r9
setb %dl
leaq (%rdi,%r9), %r10
incq %r10
incq %r9
addq $0x18, %r8
cmpq $0x1, %r10
jne 0x1d5b7d
jmp 0x1d5cc6
movzwl (%r8), %ebp
andl $0x3fff, %ebp           # imm = 0x3FFF
testb $0x1, %dl
je 0x1d5d67
xorq $0x1, %r14
movq (%rcx,%r14,8), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdi, %rdx
sete %cl
je 0x1d5c8a
shrq $0x20, %rdi
movq %rdx, %rsi
negq %rsi
leaq (%rdi,%rdi,2), %rdi
leaq (%rax,%rdi,8), %rax
addq $0x10, %rax
movl $0x1, %edi
cmpl $0x0, -0x4(%rax)
js 0x1d5c0a
movl -0x8(%rax), %r8d
xorq %r12, %r8
cmpq $0x1, %r8
je 0x1d5c7b
cmpq %rdx, %rdi
setae %cl
leaq (%rsi,%rdi), %r8
incq %r8
incq %rdi
addq $0x18, %rax
cmpq $0x1, %r8
jne 0x1d5bf7
jmp 0x1d5c8a
movq 0x60(%rsp), %rbx
movq (%rsp), %rbp
movq 0x10(%rsp), %r14
movq (%r14), %rsi
xorq $0x1, %rsi
movq %r15, %rdi
callq 0x1d5712
testq %rax, %rax
je 0x1d5d67
testq %rbx, %rbx
sete %bl
movq 0x18(%rsp), %rax
movq -0x8(%r14,%rax,8), %rsi
movq %r15, %rdi
callq 0x1d5712
movq %rax, %r13
testq %rax, %rax
sete %al
orb %bl, %al
movq 0x60(%rsp), %rbx
je 0x1d5ca3
jmp 0x1d5d6a
movzwl (%rax), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cmpq %rax, %rbp
cmovaeq %rax, %rbp
movl %ecx, %r13d
xorb $0x1, %r13b
testq %rbx, %rbx
je 0x1d5d6a
testb $0x1, %cl
jne 0x1d5d6a
movq %rbp, (%rbx)
movb $0x1, %r13b
jmp 0x1d5d6a
movq 0x8(%rsp), %r11
jmp 0x1d5cc6
movzwl (%r8), %esi
andl $0x3fff, %esi           # imm = 0x3FFF
cmpq %rsi, %rbp
cmovaeq %rsi, %rbp
testb $0x1, %dl
je 0x1d5d67
movq %r14, %rdx
xorq $0x1, %rdx
movq (%rcx,%rdx,8), %rdi
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
andq %rdi, %rdx
setne %cl
je 0x1d5d40
shrq $0x20, %rdi
movq %rdx, %rsi
negq %rsi
leaq (%rdi,%rdi,2), %rdi
leaq (%rax,%rdi,8), %rax
addq $0x10, %rax
movl $0x1, %edi
cmpl $0x0, -0x4(%rax)
js 0x1d5d15
movl -0x8(%rax), %r8d
xorq %rbx, %r8
cmpq $0x1, %r8
je 0x1d5d31
cmpq %rdx, %rdi
setb %cl
leaq (%rsi,%rdi), %r8
incq %r8
incq %rdi
addq $0x18, %rax
cmpq $0x1, %r8
jne 0x1d5d02
jmp 0x1d5d40
movzwl (%rax), %eax
andl $0x3fff, %eax           # imm = 0x3FFF
cmpq %rax, %rbp
cmovaeq %rax, %rbp
testb $0x1, %cl
je 0x1d5d67
cmpq $0x0, 0x20(%rsp)
je 0x1d5d5d
cmpq %r11, %rbx
sete %al
cmpq %r14, %rbx
sete %cl
orb %al, %cl
je 0x1d5d80
movq 0x60(%rsp), %rbx
jmp 0x1d5c2f
xorl %r13d, %r13d
movzbl %r13b, %eax
andl $0x1, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r13d, %r13d
movq %r15, %rdi
movl %ebx, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1e50d4
cmpl $0x1, %eax
movq 0x60(%rsp), %rbx
je 0x1d5c2f
jmp 0x1d5d6a
leaq 0x61c6b(%rip), %rdi     # 0x237a13
leaq 0x5dbdc(%rip), %rsi     # 0x23398b
leaq 0x61bfb(%rip), %rcx     # 0x2379b1
movl $0x4ab1, %edx           # imm = 0x4AB1
callq 0x2110
leaq 0x61bdd(%rip), %rdi     # 0x2379a4
leaq 0x5dbbd(%rip), %rsi     # 0x23398b
leaq 0x61bdc(%rip), %rcx     # 0x2379b1
movl $0x4aad, %edx           # imm = 0x4AAD
callq 0x2110