// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/inter.cpp
// Function: gen_dup_path(asg_t const*, R_to_U*, kv_ul_ov_t*, unsigned long)
uint32_t gen_dup_path(const asg_t *g, R_to_U *ri, kv_ul_ov_t *res, uint64_t v)
{
    asg_t *rg = (asg_t *)g; res->n = 0;
	if(rg->seq[v>>1].del) return res->n;
	uint64_t nv = asg_arc_n(rg, v); asg_arc_t *av = asg_arc_a(rg, v);
	uint64_t k, kv, w = (uint64_t)-1, kw, l, rn, z; ul_ov_t p; memset(&p, 0, sizeof(p));

	// for (k = 0; k < nv; k++) {
	// 	if(av[k].del) continue;
	// 	asg_arc_t *aw = asg_arc_a(rg, av[k].v);
	// 	uint64_t nw = asg_arc_n(rg, av[k].v);
	// 	for (l = 0; l < nw; l++) {
	// 		if(aw[l].del) continue;
	// 		for (rn = 0; rn < nv; rn++) {
	// 			if(av[rn].del) continue;
	// 			if(av[rn].v == aw[l].v) break;
	// 		}
	// 		if(rn < nv) {
	// 			fprintf(stderr, "[M::%s] v0::%lu, w::%u, v1::%u\n", __func__, v, av[k].v, aw[l].v);
	// 		}
	// 	}
	// }
	



	for (k = kv = 0; k < nv && kv < 2; k++) {
		if(!(av[k].del)) kv++; 
	}
	// if(v == 7723) {
	// 	fprintf(stderr, "[M::%s] v0::%lu, kv::%lu\n", __func__, v, kv);
	// }
	if(kv > 1) {
		for (k = 0; k < nv; k++) {
			if(av[k].del) continue;
			w = av[k].v; kw = get_arcs(rg, w^1, NULL, 0);
			// if(v == 7723) {
			// 	fprintf(stderr, "*[M::%s] v0::%lu, av[%lu].v::%u, kw::%lu,\n", __func__, v, k, av[k].v, kw);
			// }
			if(kw > 1) {///kv > 1 && kw > 1
				if((v>>1) != (w>>1)) {///cannot handle if the prefix and suffix nodes are the same
					l = 0;
					p.qn = 0; p.qs = l; p.qe = l + rg->seq[v>>1].len; 
					p.tn = v>>1; p.ts = 0; p.te = rg->seq[v>>1].len;
					p.el = 1; p.rev = v&1; kv_push(ul_ov_t, *res, p);
					// if(v == 7723) {
					// 	fprintf(stderr, "*[M::%s] v0::%lu, p.tn::%u, p.rev::%u\n", __func__, v, p.tn, p.rev);
					// }

					l += asg_arc_len(av[k]);
					p.qn = 0; p.qs = l; p.qe = l + rg->seq[w>>1].len; 
					p.tn = w>>1; p.ts = 0; p.te = rg->seq[w>>1].len;
					p.el = 1; p.rev = w&1; kv_push(ul_ov_t, *res, p);

					// if(v == 7723) {
					// 	fprintf(stderr, "*[M::%s] v0::%lu, p.tn::%u, p.rev::%u\n", __func__, v, p.tn, p.rev);
					// }

					p.tn = (uint32_t)-1; p.qn = ((uint64_t)(av-g->arc+k));
					kv_push(ul_ov_t, *res, p);
				}
			} else if((kw == 1) && (is_contain_r((*ri), (w>>1)))) {///kv > 1 && kw == 1 && w is contained
				rn = res->n; l = 0;
				p.qn = 0; p.qs = l; p.qe = l + rg->seq[v>>1].len; 
				p.tn = v>>1; p.ts = 0; p.te = rg->seq[v>>1].len;
				p.el = 1; p.rev = v&1; kv_push(ul_ov_t, *res, p);
				l += asg_arc_len(av[k]);
				if(!extract_contain_tig(rg, w, ri, l, 0, res)) {
					res->n = rn;
				} else {
					for (z = rn+1; z < res->n; z++) {
						if(res->a[z].tn == (v>>1)) break;
					}
					if(z >= res->n) {///cannot handle circles
						p.tn = (uint32_t)-1; p.qn = ((uint64_t)(av-g->arc+k));
						kv_push(ul_ov_t, *res, p);
					} else {
						res->n = rn;
					}
				}
			}
		}
	} else if(((kv == 1) || (kv == 0)) && (!get_arcs(rg, v^1, NULL, 0)) && (is_contain_r((*ri), (v>>1)))) {
		///1. kv == 1 && kv^ == 0 && v is contained
		///2. kv == 0 && kv^ == 0 && v is contained; an isolated single contained read
		rn = res->n; l = 0;
		if(!extract_contain_tig(rg, v, ri, l, 1, res)) {
			res->n = rn;
		} else {
			for (z = rn+1; z < res->n; z++) {
				if(res->a[z].tn == (v>>1)) break;
			}
			if(z >= res->n) {///cannot handle circles
				p.tn = (uint32_t)-1; p.qn = (uint32_t)-1;
				if(kv > 0) {
					for (k = 0; k < nv; k++) {
						if(!(av[k].del)) break; 
					}
					assert(k < nv);
					p.qn = ((uint64_t)(av-g->arc+k));
				}

				kv_push(ul_ov_t, *res, p);
			} else {
				res->n = rn;
			}
		}
	} 
	// if(v == 7723) {
	// 	fprintf(stderr, "[M::%s] v0::%lu, res->n::%lu,\n", __func__, v, (uint64_t)res->n);
	// }
    return res->n;///# chains have contained reads
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdx, %rbx
movq $0x0, 0x8(%rdx)
movq %rdi, 0x8(%rsp)
movq 0x20(%rdi), %rax
movq %rcx, %rdx
shrq %rdx
cmpl $0x0, (%rax,%rdx,8)
js 0x1d31bd
movq %rsi, 0x38(%rsp)
movq %rdx, 0x20(%rsp)
movq 0x8(%rsp), %rax
movq 0x8(%rax), %r14
movq 0x28(%rax), %rax
movq %rcx, 0x30(%rsp)
movq (%rax,%rcx,8), %rax
movq %rax, %rcx
shrq $0x20, %rcx
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
leaq (%rcx,%rcx,2), %r13
andq %rax, %r12
je 0x1d31c4
leaq (%r14,%r13,8), %rax
addq $0xc, %rax
movl $0x1, %ecx
xorl %r15d, %r15d
movq %r15, %rdx
xorl %r15d, %r15d
cmpl $0x0, (%rax)
setns %r15b
addq %rdx, %r15
cmpq %r12, %rcx
jae 0x1d31c7
incq %rcx
addq $0x18, %rax
cmpq $0x2, %r15
jb 0x1d3199
jmp 0x1d31c7
xorl %eax, %eax
jmp 0x1d37d1
xorl %r15d, %r15d
leaq (%r14,%r13,8), %rdi
cmpq $0x2, %r15
movq %r12, 0x18(%rsp)
movq %rdi, 0x10(%rsp)
jb 0x1d364a
testq %r12, %r12
je 0x1d37ce
movq 0x30(%rsp), %rax
shll $0x1f, %eax
movq %rax, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
xorl %r14d, %r14d
leaq (%r14,%r14,2), %rax
cmpl $0x0, 0xc(%rdi,%rax,8)
js 0x1d3639
leaq (%rdi,%rax,8), %r15
movl 0x8(%r15), %r12d
movl %r12d, %esi
xorl $0x1, %esi
movq 0x8(%rsp), %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1e50d4
cmpl $0x2, %eax
jb 0x1d3433
movl %r12d, %r13d
shrl %r13d
movq 0x20(%rsp), %rcx
cmpq %r13, %rcx
je 0x1d362f
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
movl (%rax,%rcx,8), %ebp
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %ebp
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x1d3290
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%rbx)
movq 0x28(%rsp), %rcx
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movq 0x30(%rsp), %rax
movq %rcx, 0x28(%rsp)
addl %ecx, %eax
addl $0x40000000, %eax       # imm = 0x40000000
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%rbx)
leaq (%rdx,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdx, %rsi
movq $0x0, (%rcx,%rsi)
movl %ebp, 0x8(%rcx,%rsi)
movq 0x20(%rsp), %rdx
movl %edx, 0xc(%rcx,%rsi)
movl $0x0, 0x10(%rcx,%rsi)
movl %ebp, 0x14(%rcx,%rsi)
movl %eax, 0x18(%rcx,%rsi)
movl (%r15), %ebp
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
movl (%rax,%r13,8), %r15d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %r15d
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x1d3337
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%rbx)
leal (%r15,%rbp), %r9d
shll $0x1f, %r12d
movq 0x28(%rsp), %rsi
addl %r12d, %esi
addl $0x40000000, %esi       # imm = 0x40000000
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
xorl %ecx, %ecx
movl %ecx, (%rax,%rdx)
movl %ebp, 0x4(%rax,%rdx)
movl %r9d, 0x8(%rax,%rdx)
movl %r13d, 0xc(%rax,%rdx)
movl %ecx, 0x10(%rax,%rdx)
movl %r15d, 0x14(%rax,%rdx)
movq %rsi, 0x28(%rsp)
movl %esi, 0x18(%rax,%rdx)
movq 0x10(%rsp), %rdi
movq %rdi, %r12
movq 0x8(%rsp), %rax
subq 0x8(%rax), %r12
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x1d33e2
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
movq %rbp, %r13
movl %r9d, %ebp
callq 0x2370
movl %ebp, %r9d
movq %r13, %rbp
movq 0x10(%rsp), %rdi
movq %rax, (%rbx)
shrq $0x3, %r12
imull $0xaaaaaaab, %r12d, %eax # imm = 0xAAAAAAAB
addl %r14d, %eax
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%rbx)
leaq (%rdx,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdx, %rsi
movl %eax, (%rcx,%rsi)
movl %ebp, 0x4(%rcx,%rsi)
movl %r9d, 0x8(%rcx,%rsi)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0xc(%rcx,%rsi)
movl %r15d, 0x14(%rcx,%rsi)
movq 0x28(%rsp), %rax
movl %eax, 0x18(%rcx,%rsi)
jmp 0x1d3584
cmpl $0x1, %eax
jne 0x1d362f
movl %r12d, %eax
shrl %eax
movq 0x38(%rsp), %rcx
cmpq (%rcx), %rax
movq 0x10(%rsp), %rdi
jae 0x1d3584
movq 0x8(%rcx), %rcx
cmpl $0x0, (%rcx,%rax,4)
js 0x1d3584
movq 0x8(%rbx), %r13
movq 0x10(%rbx), %rax
movq 0x8(%rsp), %rcx
movq 0x20(%rcx), %rcx
movq 0x20(%rsp), %rdx
movl (%rcx,%rdx,8), %edx
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %edx
movl %edx, 0x44(%rsp)
cmpq %rax, %r13
jne 0x1d34b5
leaq (%rax,%rax), %rcx
testq %rax, %rax
movl $0x2, %eax
cmoveq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%rbx)
movq 0x28(%rsp), %rsi
andl $0x3fffffff, %esi       # imm = 0x3FFFFFFF
movq 0x30(%rsp), %rax
addl %eax, %esi
addl $0x40000000, %esi       # imm = 0x40000000
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movq $0x0, (%rax,%rdx)
movl 0x44(%rsp), %edi
movl %edi, 0x8(%rax,%rdx)
movq 0x20(%rsp), %rcx
movl %ecx, 0xc(%rax,%rdx)
movl $0x0, 0x10(%rax,%rdx)
movl %edi, 0x14(%rax,%rdx)
movq %rsi, 0x28(%rsp)
movl %esi, 0x18(%rax,%rdx)
movl (%r15), %ecx
movq 0x8(%rsp), %rdi
movq %r12, %rsi
movq 0x38(%rsp), %rdx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x1d2e96
testl %eax, %eax
je 0x1d362b
movq 0x8(%rbx), %rax
leaq (,%r13,8), %rcx
addq %r13, %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r13, %rcx
addq $0x28, %rcx
movq %r13, %rdx
movq 0x18(%rsp), %r12
movq 0x20(%rsp), %rdi
incq %rdx
cmpq %rax, %rdx
jae 0x1d358e
movq (%rbx), %rsi
movl (%rsi,%rcx), %esi
addq $0x1c, %rcx
cmpq %rsi, %rdi
jne 0x1d355f
cmpq %rax, %rdx
jae 0x1d358e
movq %r13, 0x8(%rbx)
jmp 0x1d3634
movq 0x18(%rsp), %r12
jmp 0x1d3639
movq 0x10(%rsp), %rdi
movq %rdi, %r15
movq 0x8(%rsp), %rcx
subq 0x8(%rcx), %r15
movq 0x10(%rbx), %rcx
cmpq %rcx, %rax
jne 0x1d35d7
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rax
movq %rax, 0x10(%rbx)
movq (%rbx), %rdi
leaq (%rax,%rax,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rax, %rsi
callq 0x2370
movq 0x10(%rsp), %rdi
movq %rax, (%rbx)
shrq $0x3, %r15
imull $0xaaaaaaab, %r15d, %eax # imm = 0xAAAAAAAB
addl %r14d, %eax
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
leaq 0x1(%rdx), %rsi
movq %rsi, 0x8(%rbx)
leaq (%rdx,%rdx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rdx, %rsi
movl %eax, (%rcx,%rsi)
movl $0x0, 0x4(%rcx,%rsi)
movl 0x44(%rsp), %edx
movl %edx, 0x8(%rcx,%rsi)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %rax, 0xc(%rcx,%rsi)
movl %edx, 0x14(%rcx,%rsi)
movq 0x28(%rsp), %rax
movl %eax, 0x18(%rcx,%rsi)
jmp 0x1d3639
movq %r13, 0x8(%rbx)
movq 0x18(%rsp), %r12
movq 0x10(%rsp), %rdi
incq %r14
cmpq %r12, %r14
jne 0x1d3201
jmp 0x1d37ce
movq 0x30(%rsp), %rax
movl %eax, %esi
xorl $0x1, %esi
movq 0x8(%rsp), %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1e50d4
testl %eax, %eax
jne 0x1d37ce
movq 0x20(%rsp), %rax
movq 0x38(%rsp), %rcx
cmpq (%rcx), %rax
jae 0x1d37ce
movq 0x38(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x20(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x1d37ce
movq 0x8(%rbx), %r12
movl $0x1, %r8d
movq 0x8(%rsp), %rdi
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
xorl %ecx, %ecx
movq %rbx, %r9
callq 0x1d2e96
testl %eax, %eax
je 0x1d36f5
movq 0x8(%rbx), %rax
leaq (%r12,%r12,8), %rcx
leaq (%rcx,%rcx,2), %rcx
addq %r12, %rcx
addq $0x28, %rcx
movq %r12, %rdx
movq 0x10(%rsp), %rdi
incq %rdx
cmpq %rax, %rdx
jae 0x1d36fe
movq (%rbx), %rsi
movl (%rsi,%rcx), %esi
addq $0x1c, %rcx
cmpq %rsi, 0x20(%rsp)
jne 0x1d36d7
cmpq %rax, %rdx
jae 0x1d36fe
movq %r12, 0x8(%rbx)
jmp 0x1d37ce
movl $0xffffffff, %r12d      # imm = 0xFFFFFFFF
cmpq $0x1, %r15
jne 0x1d3768
movq 0x18(%rsp), %rsi
testq %rsi, %rsi
je 0x1d3732
negq %rsi
leaq (%r14,%r13,8), %rdx
addq $0xc, %rdx
xorl %ecx, %ecx
cmpl $0x0, (%rdx)
jns 0x1d3751
decq %rcx
addq $0x18, %rdx
cmpq %rcx, %rsi
jne 0x1d3721
leaq 0x63f84(%rip), %rdi     # 0x2376bd
leaq 0x6024b(%rip), %rsi     # 0x23398b
leaq 0x63f7d(%rip), %rcx     # 0x2376c4
movl $0x4859, %edx           # imm = 0x4859
callq 0x2110
movq 0x8(%rsp), %rdx
subq 0x8(%rdx), %rdi
shrq $0x3, %rdi
imull $0xaaaaaaab, %edi, %r12d # imm = 0xAAAAAAAB
subl %ecx, %r12d
movq 0x10(%rbx), %rcx
cmpq %rcx, %rax
jne 0x1d379b
leaq (%rcx,%rcx), %rax
testq %rcx, %rcx
movl $0x2, %ecx
cmovneq %rax, %rcx
movq %rcx, 0x10(%rbx)
movq (%rbx), %rdi
leaq (%rcx,%rcx,8), %rax
leaq (%rax,%rax,2), %rsi
addq %rcx, %rsi
callq 0x2370
movq %rax, (%rbx)
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movl %r12d, (%rax,%rdx)
movaps 0x600b0(%rip), %xmm0    # 0x233870
movups %xmm0, 0x4(%rax,%rdx)
movq $0x0, 0x14(%rax,%rdx)
movl 0x8(%rbx), %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq