// File: /workspace/github_cpp_makefile_star2_O2/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, 0x18(%rsp)
movl %r9d, 0x1c(%rsp)
movq %r8, 0x38(%rsp)
movl %ecx, %ebx
movq %rsi, %rbp
movq %rdi, %r15
movq 0x8(%rdi), %rax
movq %rax, 0x40(%rsp)
andq $0x0, (%rsi)
movq %rdx, %r8
movq 0x8(%rdx), %rdx
cmpq %rdx, 0x8(%rsi)
movq %r8, 0x8(%rsp)
jae 0x18469e
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(%rbp)
movq 0x10(%rbp), %rdi
leaq 0x8(,%rax,8), %rsi
movq %r8, %r14
callq 0x2370
movq %rax, 0x10(%rbp)
movq %rax, %rbp
movq 0x8(%r14), %rdx
jmp 0x1846a2
movq 0x10(%rbp), %rbp
shlq $0x3, %rdx
xorl %r14d, %r14d
movq %rbp, %rdi
xorl %esi, %esi
callq 0x20e0
movss 0x5ba15(%rip), %xmm1    # 0x1e00d0
movss 0x18(%rsp), %xmm0
movaps %xmm0, %xmm2
addss %xmm1, %xmm2
movss %xmm2, 0x10(%rsp)
movq %rbx, %r13
testl %r13d, %r13d
movl $0x0, %eax
movq %rax, 0x20(%rsp)
cmovlel %r14d, %r13d
subss %xmm0, %xmm1
movss %xmm1, 0x14(%rsp)
movq $0x0, 0x28(%rsp)
xorl %ecx, %ecx
movq 0x38(%rsp), %r12
movq 0x8(%rsp), %rdx
cmpq %r13, %rcx
je 0x18484e
movq %rbp, %rax
imulq $0x30, %rcx, %rbp
movl 0x14(%r12,%rbp), %r9d
movl %r9d, %esi
andl $0x7fffffff, %esi       # imm = 0x7FFFFFFF
je 0x184843
addq %r12, %rbp
movl 0x4(%rbp), %r10d
testl %r10d, %r10d
js 0x184843
movslq 0x18(%rbp), %r8
testq %r8, %r8
js 0x184843
movq (%rdx), %rdi
movq (%rdi,%r8,8), %r11
cmpl 0x4(%r11), %r10d
jne 0x184c60
cmpl 0x1c(%rsp), %esi
jge 0x1847ae
cvtsi2ss %r10d, %xmm0
movss 0x10(%rsp), %xmm1
mulss %xmm0, %xmm1
movq 0x8(%rsp), %rdx
movslq 0x8(%rdx), %r10
mulss 0x14(%rsp), %xmm0
xorl %r9d, %r9d
movq %r8, %r11
cmpq %r10, %r11
jge 0x1847dc
movq (%rdi,%r11,8), %rbx
movl 0x4(%rbx), %r14d
cvtsi2ss %r14, %xmm2
ucomiss %xmm0, %xmm2
jb 0x1847dc
ucomiss %xmm2, %xmm1
jb 0x1847dc
movl 0x8(%rbx), %ebx
xorl %r14d, %r14d
cmpl (%rbp), %ebx
sete %r14b
addq %r14, %r9
incq %r11
jmp 0x18477d
andl $0x80000000, %r9d       # imm = 0x80000000
movl %r9d, 0x14(%rbp)
movq 0x8(%rsp), %rdx
movq (%rdx), %r10
movq %r8, %rsi
movq %r8, %rdi
movq %rax, %rbp
testq %rdi, %rdi
js 0x184815
movq (%r10,%rdi,8), %r9
movq %rdi, %rsi
movslq 0xc(%r9), %rdi
jmp 0x1847ca
decl %r8d
movslq %r8d, %r8
testq %r8, %r8
js 0x18482a
movq (%rdi,%r8,8), %r10
movl 0x4(%r10), %r11d
cvtsi2ss %r11, %xmm2
ucomiss %xmm0, %xmm2
jb 0x18482a
ucomiss %xmm2, %xmm1
jb 0x18482a
movl 0x8(%r10), %r10d
xorl %r11d, %r11d
cmpl (%rbp), %r10d
sete %r11b
addq %r11, %r9
decq %r8
jmp 0x1847e2
addq $0x2, 0x28(%rsp)
pushq $0x1
popq %rax
movq %rax, (%rbp,%rsi,8)
movq %rax, (%rbp,%r8,8)
jmp 0x184846
movl %esi, %edx
leaq -0x1(%r9), %rsi
cmpq %rdx, %rsi
jae 0x184c7f
addq %r9, 0x20(%rsp)
movq 0x8(%rsp), %rdx
movq %rax, %rbp
incq %rcx
jmp 0x184701
cmpq $0x2, 0x20(%rsp)
jl 0x184b29
movq %rbp, 0x50(%rsp)
movq %r13, 0x48(%rsp)
xorl %ebp, %ebp
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
xorl %esi, %esi
cmpq 0x48(%rsp), %rsi
je 0x184a88
imulq $0x30, %rsi, %rbx
movq 0x38(%rsp), %rcx
movl 0x14(%rcx,%rbx), %eax
andl %edx, %eax
je 0x184a80
addq %rcx, %rbx
movl 0x4(%rbx), %ecx
testl %ecx, %ecx
js 0x184a80
movslq 0x18(%rbx), %r12
testq %r12, %r12
js 0x184a80
movq %rsi, 0x30(%rsp)
movq 0x8(%rsp), %rdi
movq (%rdi), %rdx
movq (%rdx,%r12,8), %rdx
cmpl 0x4(%rdx), %ecx
jne 0x184c9e
cmpl 0x1c(%rsp), %eax
jge 0x184cbd
movslq 0x8(%rdi), %rax
cmpq %rax, %r12
jge 0x1849a3
movq (%rdi), %rax
movq (%rax,%r12,8), %rax
movl 0x4(%rax), %ecx
cvtsi2ss %rcx, %xmm0
cvtsi2ssl 0x4(%rbx), %xmm1
movss 0x14(%rsp), %xmm2
mulss %xmm1, %xmm2
ucomiss %xmm2, %xmm0
jb 0x1849a3
mulss 0x10(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jb 0x1849a3
movl 0x8(%rax), %eax
cmpl (%rbx), %eax
jne 0x18499b
movl %ebp, %r14d
orl $0x80000000, %r14d      # imm = 0x80000000
movq %r12, %r13
testq %r13, %r13
js 0x184998
movq (%r15), %rax
movq 0x8(%r15), %rcx
cmpq 0x10(%r15), %rcx
jne 0x184963
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r15)
imulq $0xc, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x8(%rsp), %rdi
movq %rax, (%r15)
movq 0x8(%r15), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r15)
imulq $0xc, %rcx, %rcx
movq (%rdi), %rdx
movq (%rdx,%r13,8), %rdx
movl 0x8(%rdx), %esi
movl %esi, (%rax,%rcx)
movl %r13d, 0x8(%rax,%rcx)
movslq 0x18(%rbx), %rsi
cmpq %rsi, %r12
movl %r14d, %esi
cmovel %ebp, %esi
movl %esi, 0x4(%rax,%rcx)
movslq 0xc(%rdx), %r13
jmp 0x184927
incq %rbp
incq %r12
jmp 0x1848cc
movslq 0x18(%rbx), %r13
decq %r13
testq %r13, %r13
js 0x184a76
movq (%rdi), %rax
movq (%rax,%r13,8), %rax
movl 0x4(%rax), %ecx
cvtsi2ss %rcx, %xmm0
cvtsi2ssl 0x4(%rbx), %xmm1
movss 0x14(%rsp), %xmm2
mulss %xmm1, %xmm2
ucomiss %xmm2, %xmm0
jb 0x184a76
mulss 0x10(%rsp), %xmm1
ucomiss %xmm0, %xmm1
jb 0x184a76
movl 0x8(%rax), %eax
cmpl (%rbx), %eax
jne 0x1849a7
movl %ebp, %r14d
orl $0x80000000, %r14d      # imm = 0x80000000
movq %r13, %r12
testq %r12, %r12
js 0x184a6e
movq (%r15), %rax
movq 0x8(%r15), %rcx
cmpq 0x10(%r15), %rcx
jne 0x184a39
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r15)
imulq $0xc, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x8(%rsp), %rdi
movq %rax, (%r15)
movq 0x8(%r15), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r15)
imulq $0xc, %rcx, %rcx
movq (%rdi), %rdx
movq (%rdx,%r12,8), %rdx
movl 0x8(%rdx), %esi
movl %esi, (%rax,%rcx)
movl %r12d, 0x8(%rax,%rcx)
movslq 0x18(%rbx), %rsi
cmpq %rsi, %r13
movl %r14d, %esi
cmovel %ebp, %esi
movl %esi, 0x4(%rax,%rcx)
movslq 0xc(%rdx), %r12
jmp 0x1849fd
incq %rbp
jmp 0x1849a7
movl $0x7fffffff, %edx       # imm = 0x7FFFFFFF
movq 0x30(%rsp), %rsi
incq %rsi
jmp 0x18486d
movq (%r15), %rax
movq 0x40(%rsp), %rbx
imulq $0xc, %rbx, %rdi
addq %rax, %rdi
imulq $0xc, 0x8(%r15), %rsi
addq %rax, %rsi
callq 0x158d0a
movq 0x38(%rsp), %r12
movq 0x48(%rsp), %r13
movq 0x50(%rsp), %rbp
movq 0x8(%r15), %rax
movq %rbx, %rcx
subq %rax, %rcx
incq %rcx
imulq $0xc, %rbx, %r10
leaq 0xc(%r10), %rsi
xorl %r8d, %r8d
movq 0x8(%rsp), %rdx
leaq (%rbx,%r8), %rdi
cmpq %rax, %rdi
jge 0x184b20
movq %r8, %r14
movq %rcx, %r8
movq (%r15), %rdi
addq %r14, %r8
je 0x184af9
movl (%rdi,%rsi), %r9d
leaq 0x1(%r14), %r8
addq $0xc, %rsi
cmpl (%rdi,%r10), %r9d
je 0x184ad0
addq %r10, %rdi
leaq 0x1(%r14), %rsi
movss 0x18(%rsp), %xmm0
movq 0x20(%rsp), %rcx
movq %rbp, %r8
callq 0x1844bf
addq %rax, 0x28(%rsp)
addq %r14, %rbx
incq %rbx
jmp 0x184ab3
movq 0x40(%rsp), %rax
movq %rax, 0x8(%r15)
cmpq $0x0, 0x28(%rsp)
jle 0x184c4c
xorl %ebx, %ebx
xorl %ecx, %ecx
movl %ecx, %esi
movq 0x8(%rdx), %rax
cmpq %rax, %rsi
jae 0x184b65
xorl %eax, %eax
cmpq $0x0, (%rbp,%rcx,8)
movl $0xffffffff, %esi       # imm = 0xFFFFFFFF
cmovneq %rbx, %rsi
setne %al
addq %rax, %rbx
movq %rsi, (%rbp,%rcx,8)
incq %rcx
jmp 0x184b39
movq 0x8(%r15), %rcx
addq %rbx, %rcx
cmpq %rcx, 0x10(%r15)
jae 0x184bc5
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
incq %rax
movq %rax, 0x10(%r15)
movq (%r15), %rdi
imulq $0xc, %rax, %rsi
callq 0x2370
movq 0x8(%rsp), %rdx
movq %rax, (%r15)
movq 0x8(%rdx), %rax
xorl %ecx, %ecx
movl $0xffffffff, %r11d      # imm = 0xFFFFFFFF
pushq $-0x2
popq %rsi
cmpq %rcx, %rax
je 0x184c24
movq (%rbp,%rcx,8), %rdi
cmpq %r11, %rdi
je 0x184c1f
imulq $0xc, %rdi, %rdi
addq (%r15), %rdi
imulq $0xc, 0x8(%r15), %r8
movq (%rdx), %r9
movq (%r9,%rcx,8), %r9
movl 0x8(%r9), %r10d
movl %r10d, (%r8,%rdi)
movl 0x4(%r9), %r10d
movl %r10d, 0x4(%r8,%rdi)
movslq 0xc(%r9), %r9
testq %r9, %r9
js 0x184c18
movq (%rbp,%r9,8), %r9
cmpq %r11, %r9
cmovel %esi, %r9d
addq %r8, %rdi
movl %r9d, 0x8(%rdi)
incq %rcx
jmp 0x184bd0
addq %rbx, 0x8(%r15)
imulq $0x30, %r13, %rax
xorl %ecx, %ecx
cmpq %rcx, %rax
je 0x184c4c
movslq 0x18(%r12,%rcx), %rdx
testq %rdx, %rdx
js 0x184c46
movl (%rbp,%rdx,8), %edx
movl %edx, 0x18(%r12,%rcx)
addq $0x30, %rcx
jmp 0x184c2e
movq 0x20(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x6f5b7(%rip), %rdi     # 0x1f421e
leaq 0x6ceb5(%rip), %rsi     # 0x1f1b23
leaq 0x6f5e2(%rip), %rcx     # 0x1f4257
movl $0x3654, %edx           # imm = 0x3654
callq 0x2110
leaq 0x6f640(%rip), %rdi     # 0x1f42c6
leaq 0x6ce96(%rip), %rsi     # 0x1f1b23
leaq 0x6f5c3(%rip), %rcx     # 0x1f4257
movl $0x3670, %edx           # imm = 0x3670
callq 0x2110
leaq 0x6f579(%rip), %rdi     # 0x1f421e
leaq 0x6ce77(%rip), %rsi     # 0x1f1b23
leaq 0x6f5a4(%rip), %rcx     # 0x1f4257
movl $0x367e, %edx           # imm = 0x367E
callq 0x2110
leaq 0x6f620(%rip), %rdi     # 0x1f42e4
leaq 0x6ce58(%rip), %rsi     # 0x1f1b23
leaq 0x6f585(%rip), %rcx     # 0x1f4257
movl $0x367f, %edx           # imm = 0x367F
callq 0x2110