// File: /workspace/github_cpp_makefile_star2_O3/chhylp123[P]hifiasm/inter.cpp
// Function: phase_mul_ways(vec_mg_pathv_t*, st_mt_t*, vec_sp_node_t*, int, mg_path_dst_t*, int, float)
int32_t phase_mul_ways(vec_mg_pathv_t *res, st_mt_t *dst_done, vec_sp_node_t *out, int32_t n_dst, mg_path_dst_t *dst, int32_t max_k, float len_dif)
{
	int64_t i, j, z, zl, n = 0, n_mpath, kk_p, od, res_n = res->n, pid; mg_pathv_t *h;
	dst_done->n = 0; kv_resize(uint64_t, *dst_done, out->n); 
	uint64_t *trans = dst_done->a; memset(dst_done->a, 0, out->n*sizeof(*(dst_done->a)));

	n_mpath = 0;
	for (i = 0; i < n_dst; ++i) { // mark dst vertices with a target distance
		mg_path_dst_t *t = &dst[i];
		if (t->n_path > 0 && t->target_dist >= 0 && t->path_end >= 0){
			assert((int32_t)(out->a[t->path_end]->di>>32) == t->target_dist);
			if(t->n_path >= max_k) {
				t->n_path = 0;
				for (z = zl = t->path_end; z >= 0;) {
					zl = z;
					z = out->a[z]->pre;
				}
				n += 2; trans[t->path_end] = trans[zl] = 1;
			} else {
				kk_p = 0;
				for (j = t->path_end; j < (int32_t)out->n; j++) {
					od = out->a[j]->di>>32;
					if(od >= (t->target_dist*(1-len_dif)) && 
							od <= (t->target_dist*(1+len_dif))) {
						if(out->a[j]->v == t->v) kk_p++;
					} else {
						break;
					}
				}
				for (j = t->path_end-1; j >=0; j--) {
					od = out->a[j]->di>>32;
					if(od >= (t->target_dist*(1-len_dif)) && 
							od <= (t->target_dist*(1+len_dif))) {
						if(out->a[j]->v == t->v) kk_p++;
					} else {
						break;
					}
				}
				assert(kk_p > 0 && kk_p <= t->n_path);
				n_mpath += kk_p;
			}
		}
	}

	// if(detect_mul_way && src == 74) {
	// 	fprintf(stderr, "+[M::%s::] src:%u, dst:%u, n_mpath:%d\n", __func__, src, dst[0].v, n_mpath);
	// }

	if(n_mpath > 1) {
		for (i = 0, pid = 0; i < n_dst; ++i) { // mark dst vertices with a target distance
			mg_path_dst_t *t = &dst[i];
			if (t->n_path > 0 && t->target_dist >= 0 && t->path_end >= 0){
				assert((int32_t)(out->a[t->path_end]->di>>32) == t->target_dist);
				assert(t->n_path < max_k);
				for (j = t->path_end; j < (int32_t)out->n; j++) {
					od = out->a[j]->di>>32;
					if(od >= (t->target_dist*(1-len_dif)) && 
							od <= (t->target_dist*(1+len_dif))) {
						if(out->a[j]->v == t->v) {
							for (z = j; z >= 0;) {
								kv_pushp(mg_pathv_t, *res, &h);
								h->v = out->a[z]->v; h->pre = z;
								h->d = pid; if(j!=t->path_end) h->d |= 0x80000000;
								z = out->a[z]->pre;
							}
							pid++;
						}
					} else {
						break;
					}
				}
				for (j = t->path_end-1; j >=0; j--) {
					od = out->a[j]->di>>32;
					if(od >= (t->target_dist*(1-len_dif)) && 
							od <= (t->target_dist*(1+len_dif))) {
						if(out->a[j]->v == t->v) {
							for (z = j; z >= 0;) {
								kv_pushp(mg_pathv_t, *res, &h);
								h->v = out->a[z]->v; h->pre = z;
								h->d = pid; if(j!=t->path_end) h->d |= 0x80000000;
								z = out->a[z]->pre;
							}
							pid++;
						}
					} else {
						break;
					}
				}
			}
		}

		radix_sort_mg_pathv_t_v_srt(res->a + res_n, res->a + res->n);
		for (i = res_n+1, j = res_n/**, n = 0**/; i <= (int64_t)res->n; ++i) {
			if (i == (int64_t)res->n || res->a[i].v != res->a[j].v) {
				n += select_mul_way_nodes(res->a + j, i - j, out, len_dif, n_mpath, trans);
				j = i;
			}
		}

		res->n = res_n;
	}


	if(n > 0) {//found some nodes
		for (i = n = 0; (uint32_t)i < out->n; ++i) { // generate coordinate translations
			if (trans[i]) {
				trans[i] = n++;
			} else {
				trans[i] = (uint32_t)-1;
			}
		}

		kv_resize(mg_pathv_t, *res, res->n + n); //res->n += n;
		for (i = 0; (uint32_t)i < out->n; ++i) { // generate the backtrack array
			mg_pathv_t *p;
			if (trans[i] == (uint32_t)-1) continue;
			p = &res->a[trans[i]+res->n];
			p->v = out->a[i]->v, p->d = out->a[i]->di >> 32;
			if(out->a[i]->pre < 0) {
				p->pre = out->a[i]->pre;
			} else {
				if(trans[out->a[i]->pre] == (uint32_t)-1) p->pre = -2;
				else p->pre = trans[out->a[i]->pre];
			}
		}

		res->n += n;
		for (i = 0; i < n_dst; ++i) // translate "path_end"
			if (dst[i].path_end >= 0)
				dst[i].path_end = trans[dst[i].path_end];
	}

	return n_mpath;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movss %xmm0, 0x20(%rsp)
movl %r9d, 0x24(%rsp)
movq %r8, %r14
movl %ecx, %ebp
movq %rdx, %r8
movq %rsi, %r13
movq %rdi, %r15
movq 0x8(%rdi), %rax
movq %rax, 0x48(%rsp)
movq $0x0, (%rsi)
movq 0x8(%rdx), %rdx
cmpq %rdx, 0x8(%rsi)
movq %r8, (%rsp)
jae 0x1d078f
decq %rdx
movq %rdx, %rax
shrq %rax
orq %rdx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x8(%r13)
movq 0x10(%r13), %rdi
leaq 0x8(,%rax,8), %rsi
movq %r8, %rbx
callq 0x2370
movq %rax, %rdi
movq %rax, 0x10(%r13)
movq 0x8(%rbx), %rdx
jmp 0x1d0793
movq 0x10(%r13), %rdi
shlq $0x3, %rdx
movq %rdi, 0x8(%rsp)
xorl %esi, %esi
callq 0x20e0
testl %ebp, %ebp
jle 0x1d0c71
movslq %ebp, %rbx
movss 0x5d91a(%rip), %xmm1    # 0x22e0d0
movss 0x20(%rsp), %xmm0
movaps %xmm0, %xmm2
addss %xmm1, %xmm2
movss %xmm2, 0x10(%rsp)
subss %xmm0, %xmm1
movss %xmm1, 0x14(%rsp)
xorl %eax, %eax
movl $0x1, %ecx
movq $0x0, 0x30(%rsp)
movq $0x0, 0x18(%rsp)
movq %r14, 0x38(%rsp)
movq (%rsp), %r11
movq %rbx, 0x28(%rsp)
leaq (%rax,%rax,2), %rsi
shlq $0x4, %rsi
movl 0x14(%r14,%rsi), %r8d
movl %r8d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
je 0x1d0952
addq %r14, %rsi
movl 0x4(%rsi), %r10d
testl %r10d, %r10d
js 0x1d0952
movslq 0x18(%rsi), %r9
testq %r9, %r9
js 0x1d0952
movq (%r11), %rdi
movq (%rdi,%r9,8), %r11
cmpl 0x4(%r11), %r10d
jne 0x1d0e05
cmpl 0x24(%rsp), %edx
jge 0x1d08a8
xorps %xmm0, %xmm0
cvtsi2ss %r10d, %xmm0
movss 0x10(%rsp), %xmm1
mulss %xmm0, %xmm1
movq (%rsp), %r8
movslq 0x8(%r8), %r10
mulss 0x14(%rsp), %xmm0
cmpq %r9, %r10
jle 0x1d08e2
movq %r9, %r11
xorl %r8d, %r8d
movq (%rdi,%r11,8), %rbx
movl 0x4(%rbx), %r14d
xorps %xmm2, %xmm2
cvtsi2ss %r14, %xmm2
ucomiss %xmm0, %xmm2
jb 0x1d08e5
ucomiss %xmm2, %xmm1
jb 0x1d08e5
movl 0x8(%rbx), %ebx
xorl %r14d, %r14d
cmpl (%rsi), %ebx
sete %r14b
addq %r14, %r8
incq %r11
cmpq %r11, %r10
jne 0x1d0875
jmp 0x1d08e5
andl $0x80000000, %r8d       # imm = 0x80000000
movl %r8d, 0x14(%rsi)
movq (%rsp), %r11
movq (%r11), %rsi
movq %r9, %rdi
movq %rdi, %rdx
movq (%rsi,%rdi,8), %rdi
movslq 0xc(%rdi), %rdi
testq %rdi, %rdi
jns 0x1d08bd
addq $0x2, 0x30(%rsp)
movq 0x8(%rsp), %rsi
movq %rcx, (%rsi,%rdx,8)
movq %rcx, (%rsi,%r9,8)
jmp 0x1d0952
xorl %r8d, %r8d
testl %r9d, %r9d
je 0x1d0930
decl %r9d
movslq %r9d, %r9
incq %r9
movq 0x38(%rsp), %r14
movq 0x28(%rsp), %rbx
movq -0x8(%rdi,%r9,8), %r10
movl 0x4(%r10), %r11d
xorps %xmm2, %xmm2
cvtsi2ss %r11, %xmm2
ucomiss %xmm0, %xmm2
jb 0x1d093a
ucomiss %xmm2, %xmm1
jb 0x1d093a
movl 0x8(%r10), %r10d
xorl %r11d, %r11d
cmpl (%rsi), %r10d
sete %r11b
addq %r11, %r8
decq %r9
jg 0x1d08fd
jmp 0x1d093a
movq 0x38(%rsp), %r14
movq 0x28(%rsp), %rbx
movl %edx, %edx
leaq -0x1(%r8), %rsi
cmpq %rdx, %rsi
jae 0x1d0e24
addq %r8, 0x18(%rsp)
movq (%rsp), %r11
incq %rax
cmpq %rbx, %rax
jne 0x1d07fa
cmpq $0x2, 0x18(%rsp)
jl 0x1d0c78
movl %ebp, 0x44(%rsp)
testl %ebp, %ebp
jle 0x1d0bbf
xorl %eax, %eax
xorl %ebp, %ebp
movq %rax, 0x50(%rsp)
leaq (%rax,%rax,2), %rbx
shlq $0x4, %rbx
movl 0x14(%r14,%rbx), %eax
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %eax
je 0x1d0ba7
addq %r14, %rbx
movl 0x4(%rbx), %ecx
testl %ecx, %ecx
js 0x1d0ba7
movslq 0x18(%rbx), %r14
testq %r14, %r14
js 0x1d0ba7
movq (%r11), %rdx
movq (%rdx,%r14,8), %rdx
cmpl 0x4(%rdx), %ecx
jne 0x1d0e43
cmpl 0x24(%rsp), %eax
jge 0x1d0e62
movq 0x8(%r11), %rax
movslq %eax, %rcx
cmpq %r14, %rcx
jle 0x1d0ac0
movq (%r11), %rcx
movq (%rcx,%r14,8), %rcx
movl 0x4(%rcx), %edx
xorps %xmm0, %xmm0
cvtsi2ss %rdx, %xmm0
xorps %xmm1, %xmm1
cvtsi2ssl 0x4(%rbx), %xmm1
movss 0x14(%rsp), %xmm2
mulss %xmm1, %xmm2
ucomiss %xmm2, %xmm0
jb 0x1d0abc
mulss 0x10(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jb 0x1d0abc
movl 0x8(%rcx), %ecx
cmpl (%rbx), %ecx
jne 0x1d0aad
movl %ebp, %r12d
orl $0x80000000, %r12d      # imm = 0x80000000
movq %r14, %r13
movq (%r15), %rax
movq 0x8(%r15), %rcx
cmpq 0x10(%r15), %rcx
jne 0x1d0a6e
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r15)
shlq $0x2, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, %rdi
callq 0x2370
movq (%rsp), %r11
movq %rax, (%r15)
movq 0x8(%r15), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r15)
leaq (%rcx,%rcx,2), %rcx
movq (%r11), %rdx
movq (%rdx,%r13,8), %rdx
movl 0x8(%rdx), %esi
movl %esi, (%rax,%rcx,4)
movl %r13d, 0x8(%rax,%rcx,4)
movslq 0x18(%rbx), %rsi
cmpq %rsi, %r14
movl %r12d, %esi
cmovel %ebp, %esi
movl %esi, 0x4(%rax,%rcx,4)
movslq 0xc(%rdx), %r13
testq %r13, %r13
jns 0x1d0a32
movq 0x8(%r11), %rax
incq %rbp
incq %r14
movslq %eax, %rcx
cmpq %rcx, %r14
jl 0x1d09de
movl 0x18(%rbx), %r14d
testl %r14d, %r14d
jle 0x1d0ba7
decl %r14d
movq (%r11), %rax
movq (%rax,%r14,8), %rax
movl 0x4(%rax), %ecx
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
xorps %xmm1, %xmm1
cvtsi2ssl 0x4(%rbx), %xmm1
movss 0x14(%rsp), %xmm2
mulss %xmm1, %xmm2
ucomiss %xmm2, %xmm0
jb 0x1d0ba7
mulss 0x10(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jb 0x1d0ba7
movl 0x8(%rax), %eax
cmpl (%rbx), %eax
jne 0x1d0b97
movl %ebp, %r12d
orl $0x80000000, %r12d      # imm = 0x80000000
movq %r14, %r13
movq (%r15), %rax
movq 0x8(%r15), %rcx
cmpq 0x10(%r15), %rcx
jne 0x1d0b5c
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r15)
shlq $0x2, %rdx
leaq (%rdx,%rdx,2), %rsi
movq %rax, %rdi
callq 0x2370
movq (%rsp), %r11
movq %rax, (%r15)
movq 0x8(%r15), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r15)
leaq (%rcx,%rcx,2), %rcx
movq (%r11), %rdx
movq (%rdx,%r13,8), %rdx
movl 0x8(%rdx), %esi
movl %esi, (%rax,%rcx,4)
movl %r13d, 0x8(%rax,%rcx,4)
movslq 0x18(%rbx), %rsi
cmpq %rsi, %r14
movl %r12d, %esi
cmovel %ebp, %esi
movl %esi, 0x4(%rax,%rcx,4)
movslq 0xc(%rdx), %r13
testq %r13, %r13
jns 0x1d0b20
incq %rbp
leaq -0x1(%r14), %rax
testq %r14, %r14
movq %rax, %r14
jg 0x1d0acc
movq 0x50(%rsp), %rax
incq %rax
cmpq 0x28(%rsp), %rax
movq 0x38(%rsp), %r14
jne 0x1d097a
movq 0x48(%rsp), %rbp
leaq (,%rbp,2), %rbx
addq %rbp, %rbx
movq (%r15), %rax
movq 0x8(%r15), %rcx
leaq (%rax,%rbx,4), %rdi
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,4), %rsi
callq 0x1a00d5
movq 0x8(%r15), %rax
cmpq %rax, %rbp
jge 0x1d0c7f
leaq 0x1(%rbp), %r12
leaq 0xc(,%rbx,4), %rbx
movq %rbp, %rcx
movq (%rsp), %r11
movq 0x8(%rsp), %r8
movq 0x18(%rsp), %r13
movq (%r15), %rdx
cmpq %rax, %r12
je 0x1d0c25
movl (%rdx,%rbx), %esi
leaq (%rcx,%rcx,2), %rdi
cmpl (%rdx,%rdi,4), %esi
je 0x1d0c5e
leaq (%rcx,%rcx,2), %rax
leaq (%rdx,%rax,4), %rdi
movq %r12, %rsi
subq %rcx, %rsi
movq %r11, %rdx
movss 0x20(%rsp), %xmm0
movl %r13d, %ecx
movq 0x8(%rsp), %r8
callq 0x1d05b3
movq 0x8(%rsp), %r8
movq (%rsp), %r11
addq %rax, 0x30(%rsp)
movq 0x8(%r15), %rax
movq %r12, %rcx
leaq 0x1(%r12), %rdx
addq $0xc, %rbx
cmpq %rax, %r12
movq %rdx, %r12
jl 0x1d0c11
jmp 0x1d0c88
xorl %eax, %eax
jmp 0x1d0df6
movq 0x8(%rsp), %r8
jmp 0x1d0c90
movq (%rsp), %r11
movq 0x8(%rsp), %r8
movq %rbp, 0x8(%r15)
movl 0x44(%rsp), %ebp
cmpq $0x0, 0x30(%rsp)
jle 0x1d0df1
cmpq $0x0, 0x8(%r11)
je 0x1d0cd6
movl $0x1, %ecx
xorl %ebx, %ebx
xorl %eax, %eax
cmpq $0x0, -0x8(%r8,%rcx,8)
setne %al
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmovneq %rbx, %rdx
addq %rax, %rbx
movq %rdx, -0x8(%r8,%rcx,8)
movl %ecx, %edx
movq 0x8(%r11), %rax
incq %rcx
cmpq %rax, %rdx
jb 0x1d0caa
jmp 0x1d0cda
xorl %eax, %eax
xorl %ebx, %ebx
movq 0x8(%r15), %rcx
addq %rbx, %rcx
cmpq %rcx, 0x10(%r15)
jae 0x1d0d47
decq %rcx
movq %rcx, %rax
shrq %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x2, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x4, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x8, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x10, %rax
orq %rcx, %rax
leaq 0x1(%rax), %rcx
movq %rcx, 0x10(%r15)
movq (%r15), %rdi
leaq 0x4(,%rax,4), %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq 0x8(%rsp), %r8
movq (%rsp), %r11
movq %rax, (%r15)
movq 0x8(%r11), %rax
testq %rax, %rax
je 0x1d0dc1
movl $0x1, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movq -0x8(%r8,%rcx,8), %rdi
cmpq %rdx, %rdi
je 0x1d0db7
movq 0x8(%r15), %r8
leaq (%rdi,%rdi,2), %rdi
shlq $0x2, %rdi
addq (%r15), %rdi
leaq (%r8,%r8,2), %r8
movq (%r11), %r9
movq -0x8(%r9,%rcx,8), %r9
movl 0x8(%r9), %r10d
movl %r10d, (%rdi,%r8,4)
movl 0x4(%r9), %r10d
movl %r10d, 0x4(%rdi,%r8,4)
movslq 0xc(%r9), %r9
testq %r9, %r9
js 0x1d0daa
movq 0x8(%rsp), %r10
movq (%r10,%r9,8), %r9
cmpq %rdx, %r9
cmovel %esi, %r9d
leaq (%rdi,%r8,4), %rdi
movl %r9d, 0x8(%rdi)
movq 0x8(%rsp), %r8
movl %ecx, %edi
incq %rcx
cmpq %rax, %rdi
jb 0x1d0d5b
addq %rbx, 0x8(%r15)
testl %ebp, %ebp
jle 0x1d0df1
addq $0x18, %r14
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rdx
movslq (%r14), %rcx
testq %rcx, %rcx
js 0x1d0de6
movl (%r8,%rcx,8), %ecx
movl %ecx, (%r14)
addq $0x30, %r14
decq %rdx
jne 0x1d0dd7
jmp 0x1d0df6
movq 0x18(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7154a(%rip), %rdi     # 0x242356
leaq 0x6ee48(%rip), %rsi     # 0x23fc5b
leaq 0x71575(%rip), %rcx     # 0x24238f
movl $0x3654, %edx           # imm = 0x3654
callq 0x2110
leaq 0x715d3(%rip), %rdi     # 0x2423fe
leaq 0x6ee29(%rip), %rsi     # 0x23fc5b
leaq 0x71556(%rip), %rcx     # 0x24238f
movl $0x3670, %edx           # imm = 0x3670
callq 0x2110
leaq 0x7150c(%rip), %rdi     # 0x242356
leaq 0x6ee0a(%rip), %rsi     # 0x23fc5b
leaq 0x71537(%rip), %rcx     # 0x24238f
movl $0x367e, %edx           # imm = 0x367E
callq 0x2110
leaq 0x715b3(%rip), %rdi     # 0x24241c
leaq 0x6edeb(%rip), %rsi     # 0x23fc5b
leaq 0x71518(%rip), %rcx     # 0x24238f
movl $0x367f, %edx           # imm = 0x367F
callq 0x2110