// File: /workspace/github_cpp_makefile_star2_O1/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 $0x68, %rsp
movss %xmm0, 0x14(%rsp)
movl %r9d, 0x34(%rsp)
movq %r8, %r13
movl %ecx, %ebp
movq %rsi, %r12
movq %rdi, %r15
movq 0x8(%rdi), %rax
movq %rax, 0x58(%rsp)
movq $0x0, (%rsi)
movq 0x8(%rdx), %rax
cmpq %rax, 0x8(%rsi)
movq %rdx, 0x8(%rsp)
jae 0x1c6733
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x8(%r12)
movq 0x10(%r12), %rdi
leaq 0x8(,%rcx,8), %rsi
callq 0x2370
movq 0x8(%rsp), %rdx
movq %rax, 0x10(%r12)
movq 0x10(%r12), %r14
movq 0x8(%rdx), %rdx
shlq $0x3, %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x20e0
movslq %ebp, %rbx
testl %ebx, %ebx
movq %r14, 0x18(%rsp)
movq %rbx, 0x40(%rsp)
jle 0x1c68fc
movss 0x5b959(%rip), %xmm0    # 0x2220c0
movss 0x14(%rsp), %xmm2
movaps %xmm2, %xmm1
addss %xmm0, %xmm1
subss %xmm2, %xmm0
xorl %eax, %eax
movl $0x1, %ecx
movq $0x0, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x8(%rsp), %r11
leaq (%rax,%rax,2), %rsi
shlq $0x4, %rsi
movl 0x14(%r13,%rsi), %r8d
movl %r8d, %edx
andl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
je 0x1c68ee
addq %r13, %rsi
movl 0x4(%rsi), %r10d
testl %r10d, %r10d
js 0x1c68ee
movslq 0x18(%rsi), %r9
testq %r9, %r9
js 0x1c68ee
movq (%r11), %rdi
movq (%rdi,%r9,8), %r11
cmpl 0x4(%r11), %r10d
jne 0x1c6ddc
cmpl 0x34(%rsp), %edx
jge 0x1c6843
xorps %xmm2, %xmm2
cvtsi2ss %r10d, %xmm2
movaps %xmm1, %xmm3
mulss %xmm2, %xmm3
movq 0x8(%rsp), %r8
movslq 0x8(%r8), %r10
cmpq %r9, %r10
jle 0x1c6879
movaps %xmm0, %xmm4
mulss %xmm2, %xmm4
movq %r9, %r11
xorl %r8d, %r8d
movq (%rdi,%r11,8), %rbx
movl 0x4(%rbx), %r14d
xorps %xmm5, %xmm5
cvtsi2ss %r14, %xmm5
ucomiss %xmm4, %xmm5
jb 0x1c687c
ucomiss %xmm5, %xmm3
jb 0x1c687c
movl 0x8(%rbx), %ebx
xorl %r14d, %r14d
cmpl (%rsi), %ebx
sete %r14b
addq %r14, %r8
incq %r11
cmpq %r11, %r10
jne 0x1c6810
jmp 0x1c687c
andl $0x80000000, %r8d       # imm = 0x80000000
movl %r8d, 0x14(%rsi)
movq 0x8(%rsp), %r11
movq (%r11), %rsi
movq %r9, %rdi
movq %rdi, %rdx
movq (%rsi,%rdi,8), %rdi
movslq 0xc(%rdi), %rdi
testq %rdi, %rdi
jns 0x1c6859
addq $0x2, 0x28(%rsp)
movq %rcx, (%r14,%rdx,8)
movq %rcx, (%r14,%r9,8)
jmp 0x1c68ee
xorl %r8d, %r8d
testl %r9d, %r9d
je 0x1c68cb
decl %r9d
movslq %r9d, %r9
mulss %xmm0, %xmm2
incq %r9
movq 0x18(%rsp), %r14
movq 0x40(%rsp), %rbx
movq -0x8(%rdi,%r9,8), %r10
movl 0x4(%r10), %r11d
xorps %xmm4, %xmm4
cvtsi2ss %r11, %xmm4
ucomiss %xmm2, %xmm4
jb 0x1c68d5
ucomiss %xmm4, %xmm3
jb 0x1c68d5
movl 0x8(%r10), %r10d
xorl %r11d, %r11d
cmpl (%rsi), %r10d
sete %r11b
addq %r11, %r8
decq %r9
jg 0x1c6898
jmp 0x1c68d5
movq 0x18(%rsp), %r14
movq 0x40(%rsp), %rbx
movl %edx, %edx
leaq -0x1(%r8), %rsi
cmpq %rdx, %rsi
jae 0x1c6e1a
addq %r8, 0x20(%rsp)
movq 0x8(%rsp), %r11
incq %rax
cmpq %rbx, %rax
jne 0x1c6796
jmp 0x1c6913
movq $0x0, 0x20(%rsp)
movq $0x0, 0x28(%rsp)
movq 0x8(%rsp), %r11
cmpq $0x2, 0x20(%rsp)
jl 0x1c6c7d
movq %r13, 0x48(%rsp)
movl %ebp, 0x54(%rsp)
testl %ebp, %ebp
jle 0x1c6bbb
movss 0x5b788(%rip), %xmm1    # 0x2220c0
movss 0x14(%rsp), %xmm0
movaps %xmm0, %xmm2
addss %xmm1, %xmm2
movss %xmm2, 0x38(%rsp)
subss %xmm0, %xmm1
movss %xmm1, 0x3c(%rsp)
xorl %edx, %edx
xorl %ebp, %ebp
leaq (%rdx,%rdx,2), %rbx
shlq $0x4, %rbx
movq 0x48(%rsp), %rcx
movl 0x14(%rcx,%rbx), %eax
movl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
andl %esi, %eax
movq %rdx, 0x60(%rsp)
je 0x1c6ba8
addq %rcx, %rbx
movl 0x4(%rbx), %ecx
testl %ecx, %ecx
js 0x1c6ba8
movslq 0x18(%rbx), %r14
testq %r14, %r14
js 0x1c6ba3
movq (%r11), %rdx
movq (%rdx,%r14,8), %rdx
cmpl 0x4(%rdx), %ecx
jne 0x1c6dfb
cmpl 0x34(%rsp), %eax
jge 0x1c6e39
movslq 0x8(%r11), %rax
cmpq %r14, %rax
jle 0x1c6a9e
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 0x3c(%rsp), %xmm2
mulss %xmm1, %xmm2
ucomiss %xmm2, %xmm0
jb 0x1c6a9e
mulss 0x38(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jb 0x1c6a9e
movl 0x8(%rax), %eax
cmpl (%rbx), %eax
jne 0x1c6a8e
movl %ebp, %r12d
orl $0x80000000, %r12d      # imm = 0x80000000
movq %r14, %r13
movq 0x10(%r15), %rax
cmpq %rax, 0x8(%r15)
jne 0x1c6a48
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r15)
movq (%r15), %rdi
shlq $0x2, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq 0x8(%rsp), %r11
movq %rax, (%r15)
movq (%r15), %rax
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)
movl %ebp, 0x4(%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 0x1c6a12
incq %rbp
incq %r14
movslq 0x8(%r11), %rax
cmpq %rax, %r14
jl 0x1c69be
movslq 0x18(%rbx), %r13
testq %r13, %r13
jle 0x1c6ba3
decq %r13
movq 0x18(%rsp), %r14
movq (%r11), %rax
movq (%rax,%r13,8), %rax
movl 0x4(%rax), %ecx
xorps %xmm0, %xmm0
cvtsi2ss %rcx, %xmm0
xorps %xmm1, %xmm1
cvtsi2ssl 0x4(%rbx), %xmm1
movss 0x3c(%rsp), %xmm2
mulss %xmm1, %xmm2
ucomiss %xmm2, %xmm0
jb 0x1c6ba8
mulss 0x38(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jb 0x1c6ba8
movl 0x8(%rax), %eax
cmpl (%rbx), %eax
jne 0x1c6b91
testq %r13, %r13
js 0x1c6b89
movl %ebp, %r12d
orl $0x80000000, %r12d      # imm = 0x80000000
movq %r13, %r14
movq 0x10(%r15), %rax
cmpq %rax, 0x8(%r15)
jne 0x1c6b46
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%r15)
movq (%r15), %rdi
shlq $0x2, %rcx
leaq (%rcx,%rcx,2), %rsi
callq 0x2370
movq 0x8(%rsp), %r11
movq %rax, (%r15)
movq (%r15), %rax
movq 0x8(%r15), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r15)
leaq (%rcx,%rcx,2), %rcx
movq (%r11), %rdx
movq (%rdx,%r14,8), %rdx
movl 0x8(%rdx), %esi
movl %esi, (%rax,%rcx,4)
movl %r14d, 0x8(%rax,%rcx,4)
movl %ebp, 0x4(%rax,%rcx,4)
movslq 0x18(%rbx), %rsi
cmpq %rsi, %r13
movl %r12d, %esi
cmovel %ebp, %esi
movl %esi, 0x4(%rax,%rcx,4)
movslq 0xc(%rdx), %r14
testq %r14, %r14
jns 0x1c6b10
incq %rbp
movq 0x18(%rsp), %r14
leaq -0x1(%r13), %rax
testq %r13, %r13
movq %rax, %r13
jg 0x1c6ab3
jmp 0x1c6ba8
movq 0x18(%rsp), %r14
movq 0x60(%rsp), %rdx
incq %rdx
cmpq 0x40(%rsp), %rdx
jne 0x1c6959
movq 0x58(%rsp), %r13
leaq (,%r13,2), %rbx
addq %r13, %rbx
movq (%r15), %rax
movq 0x8(%r15), %rcx
leaq (%rax,%rbx,4), %rdi
leaq (%rcx,%rcx,2), %rcx
leaq (%rax,%rcx,4), %rsi
callq 0x197345
movq 0x8(%r15), %rcx
cmpq %rcx, %r13
jge 0x1c6c66
leaq 0x1(%r13), %r12
leaq 0xc(,%rbx,4), %rbx
movq %r13, %rax
movq 0x48(%rsp), %r13
movq 0x8(%rsp), %r11
movq 0x20(%rsp), %rbp
cmpq %rcx, %r12
je 0x1c6c1e
movq (%r15), %rcx
movl (%rcx,%rbx), %edx
leaq (%rax,%rax,2), %rsi
cmpl (%rcx,%rsi,4), %edx
je 0x1c6c4f
leaq (%rax,%rax,2), %rdi
shlq $0x2, %rdi
addq (%r15), %rdi
movq %r12, %rsi
subq %rax, %rsi
movq %r11, %rdx
movss 0x14(%rsp), %xmm0
movl %ebp, %ecx
movq %r14, %r8
callq 0x1c6560
movq 0x8(%rsp), %r11
addq %rax, 0x28(%rsp)
movq %r12, %rax
movq 0x8(%r15), %rcx
leaq 0x1(%r12), %rdx
addq $0xc, %rbx
cmpq %rcx, %r12
movq %rdx, %r12
jl 0x1c6c0a
jmp 0x1c6c70
movq 0x48(%rsp), %r13
movq 0x8(%rsp), %r11
movq 0x58(%rsp), %rax
movq %rax, 0x8(%r15)
movl 0x54(%rsp), %ebp
movq 0x28(%rsp), %rax
testq %rax, %rax
jle 0x1c6dc8
cmpq $0x0, 0x8(%r11)
je 0x1c6cc2
movl $0x1, %eax
xorl %ebx, %ebx
xorl %ecx, %ecx
cmpq $0x0, -0x8(%r14,%rax,8)
setne %cl
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
cmovneq %rbx, %rdx
addq %rcx, %rbx
movq %rdx, -0x8(%r14,%rax,8)
movl %eax, %ecx
incq %rax
cmpq 0x8(%r11), %rcx
jb 0x1c6c99
jmp 0x1c6cc4
xorl %ebx, %ebx
movq 0x8(%r15), %rax
addq %rbx, %rax
cmpq %rax, 0x10(%r15)
jae 0x1c6d29
decq %rax
movq %rax, %rcx
shrq %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x2, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x4, %rcx
orq %rax, %rcx
movq %rcx, %rax
shrq $0x8, %rax
orq %rcx, %rax
movq %rax, %rcx
shrq $0x10, %rcx
orq %rax, %rcx
leaq 0x1(%rcx), %rax
movq %rax, 0x10(%r15)
movq (%r15), %rdi
leaq 0x4(,%rcx,4), %rax
leaq (%rax,%rax,2), %rsi
callq 0x2370
movq 0x8(%rsp), %r11
movq %rax, (%r15)
movq 0x8(%r11), %rax
testq %rax, %rax
je 0x1c6d9d
movl $0x1, %ecx
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movl $0xfffffffe, %esi       # imm = 0xFFFFFFFE
movq -0x8(%r14,%rcx,8), %rdi
cmpq %rdx, %rdi
je 0x1c6d93
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 0x1c6d8b
movq (%r14,%r9,8), %r9
cmpq %rdx, %r9
cmovel %esi, %r9d
leaq (%rdi,%r8,4), %rdi
movl %r9d, 0x8(%rdi)
movl %ecx, %edi
incq %rcx
cmpq %rax, %rdi
jb 0x1c6d41
addq %rbx, 0x8(%r15)
testl %ebp, %ebp
movq 0x40(%rsp), %rcx
jle 0x1c6dc8
addq $0x18, %r13
movslq (%r13), %rax
testq %rax, %rax
js 0x1c6dbf
movl (%r14,%rax,8), %eax
movl %eax, (%r13)
addq $0x30, %r13
decq %rcx
jne 0x1c6dae
movq 0x20(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6f2a3(%rip), %rdi     # 0x236086
leaq 0x6cba1(%rip), %rsi     # 0x23398b
leaq 0x6f2ce(%rip), %rcx     # 0x2360bf
movl $0x3654, %edx           # imm = 0x3654
callq 0x2110
leaq 0x6f284(%rip), %rdi     # 0x236086
leaq 0x6cb82(%rip), %rsi     # 0x23398b
leaq 0x6f2af(%rip), %rcx     # 0x2360bf
movl $0x367e, %edx           # imm = 0x367E
callq 0x2110
leaq 0x6f30d(%rip), %rdi     # 0x23612e
leaq 0x6cb63(%rip), %rsi     # 0x23398b
leaq 0x6f290(%rip), %rcx     # 0x2360bf
movl $0x3670, %edx           # imm = 0x3670
callq 0x2110
leaq 0x6f30c(%rip), %rdi     # 0x23614c
leaq 0x6cb44(%rip), %rsi     # 0x23398b
leaq 0x6f271(%rip), %rcx     # 0x2360bf
movl $0x367f, %edx           # imm = 0x367F
callq 0x2110