// File: /workspace/github_cpp_makefile_star2_O3/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 0x20(%rdi), %rax
movq %rcx, %rdx
shrq %rdx
cmpl $0x0, (%rax,%rdx,8)
js 0x1dd6c1
movq %rdi, %r12
movq %rsi, 0x28(%rsp)
movq %rdx, 0x18(%rsp)
movq 0x8(%rdi), %r14
movq 0x28(%rdi), %rax
movq (%rax,%rcx,8), %rax
movq %rax, %rdx
shrq $0x20, %rdx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
leaq (%rdx,%rdx,2), %r13
leaq (%r14,%r13,8), %rdi
andq %rax, %r8
movq %rdi, 0x10(%rsp)
movq %r8, 0x20(%rsp)
je 0x1dd6c8
leaq (%r14,%r13,8), %rax
addq $0xc, %rax
movl $0x1, %esi
xorl %r15d, %r15d
movq %r15, %rdx
xorl %r15d, %r15d
cmpl $0x0, (%rax)
setns %r15b
addq %rdx, %r15
cmpq %r8, %rsi
jae 0x1dd253
incq %rsi
addq $0x18, %rax
cmpq $0x2, %r15
jb 0x1dd231
cmpq $0x2, %r15
jb 0x1dd6cb
shll $0x1f, %ecx
movq %rcx, 0x38(%rsp)
movq $0x0, 0x8(%rsp)
xorl %ebp, %ebp
movq %r12, 0x40(%rsp)
leaq (,%rbp,2), %rax
addq %rbp, %rax
cmpl $0x0, 0xc(%rdi,%rax,8)
js 0x1dd54b
leaq (%rdi,%rax,8), %r14
movl 0x8(%r14), %r15d
movl %r15d, %esi
xorl $0x1, %esi
movq %r12, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1efacc
cmpl $0x2, %eax
jb 0x1dd4c5
movl %r15d, %r13d
shrl %r13d
movq 0x18(%rsp), %rcx
cmpq %r13, %rcx
movq 0x20(%rsp), %r8
je 0x1dd546
movq 0x20(%r12), %rax
movl (%rax,%rcx,8), %r12d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %r12d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x1dd313
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
movq 0x38(%rsp), %rdx
movq 0x8(%rsp), %rsi
andl $0x3fffffff, %esi       # imm = 0x3FFFFFFF
movq %rsi, 0x8(%rsp)
addl %esi, %edx
addl $0x40000000, %edx       # imm = 0x40000000
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rcx, %rsi
movq $0x0, (%rax,%rsi)
movl %r12d, 0x8(%rax,%rsi)
movq 0x18(%rsp), %rcx
movl %ecx, 0xc(%rax,%rsi)
movl $0x0, 0x10(%rax,%rsi)
movl %r12d, 0x14(%rax,%rsi)
movl %edx, 0x18(%rax,%rsi)
movl (%r14), %r9d
movq 0x40(%rsp), %r12
movq 0x20(%r12), %rax
movl (%rax,%r13,8), %r14d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %r14d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x1dd3c9
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
movq %r9, %r12
callq 0x2370
movq %r12, %r9
movq 0x40(%rsp), %r12
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
movq 0x10(%rsp), %rdi
leal (%r14,%r9), %r10d
shll $0x1f, %r15d
movq 0x8(%rsp), %rsi
addl %r15d, %esi
addl $0x40000000, %esi       # imm = 0x40000000
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 %r9d, 0x4(%rax,%rdx)
movl %r10d, 0x8(%rax,%rdx)
movl %r13d, 0xc(%rax,%rdx)
movl %ecx, 0x10(%rax,%rdx)
movl %r14d, 0x14(%rax,%rdx)
movq %rsi, 0x8(%rsp)
movl %esi, 0x18(%rax,%rdx)
movq %rdi, %r15
subq 0x8(%r12), %r15
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x1dd476
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
movq %r9, %r12
movl %r10d, %r13d
callq 0x2370
movl %r13d, %r10d
movq %r12, %r9
movq 0x40(%rsp), %r12
movq 0x10(%rsp), %rdi
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
movq 0x20(%rsp), %r8
shrq $0x3, %r15
imull $0xaaaaaaab, %r15d, %edx # imm = 0xAAAAAAAB
addl %ebp, %edx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rcx, %rsi
movl %edx, (%rax,%rsi)
movl %r9d, 0x4(%rax,%rsi)
movl %r10d, 0x8(%rax,%rsi)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0xc(%rax,%rsi)
movl %r14d, 0x14(%rax,%rsi)
movq 0x8(%rsp), %rcx
movl %ecx, 0x18(%rax,%rsi)
jmp 0x1dd54b
cmpl $0x1, %eax
movq 0x20(%rsp), %r8
jne 0x1dd546
movl %r15d, %eax
shrl %eax
movq 0x28(%rsp), %rcx
cmpq (%rcx), %rax
movq 0x10(%rsp), %rdi
jae 0x1dd54b
movq 0x8(%rcx), %rcx
cmpl $0x0, (%rcx,%rax,4)
js 0x1dd54b
movq (%rbx), %rax
movq 0x8(%rbx), %r13
movq 0x20(%r12), %rcx
movq 0x18(%rsp), %rdx
movl (%rcx,%rdx,8), %edx
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %edx
movl %edx, 0x34(%rsp)
cmpq 0x10(%rbx), %r13
jne 0x1dd55c
leaq (,%r13,2), %rcx
testq %r13, %r13
movl $0x2, %edx
cmoveq %rdx, %rcx
movq %rcx, 0x10(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rsi
addq %rcx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
jmp 0x1dd55f
movq 0x10(%rsp), %rdi
incq %rbp
cmpq %r8, %rbp
jne 0x1dd275
jmp 0x1dd850
movq %r13, %rcx
movq 0x38(%rsp), %rdx
movq 0x8(%rsp), %rsi
andl $0x3fffffff, %esi       # imm = 0x3FFFFFFF
addl %edx, %esi
addl $0x40000000, %esi       # imm = 0x40000000
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 0x34(%rsp), %edi
movl %edi, 0x8(%rax,%rdx)
movq 0x18(%rsp), %rcx
movl %ecx, 0xc(%rax,%rdx)
movl $0x0, 0x10(%rax,%rdx)
movl %edi, 0x14(%rax,%rdx)
movq %rsi, 0x8(%rsp)
movl %esi, 0x18(%rax,%rdx)
movl (%r14), %ecx
movq %r12, %rdi
movq %r15, %rsi
movq 0x28(%rsp), %rdx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x1dcf2c
testl %eax, %eax
je 0x1dd61f
movq 0x8(%rbx), %rcx
leaq (,%r13,8), %rax
addq %r13, %rax
leaq (%rax,%rax,2), %rax
leaq 0x28(%r13,%rax), %rax
movq %r13, %rdx
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %r8
movq 0x18(%rsp), %r9
incq %rdx
cmpq %rcx, %rdx
jae 0x1dd632
movq (%rbx), %rsi
movl (%rsi,%rax), %esi
addq $0x1c, %rax
cmpq %rsi, %r9
jne 0x1dd5ff
movq %r13, 0x8(%rbx)
jmp 0x1dd54b
movq %r13, 0x8(%rbx)
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %r8
jmp 0x1dd54b
movq %rdi, %r14
subq 0x8(%r12), %r14
movq (%rbx), %rax
cmpq 0x10(%rbx), %rcx
jne 0x1dd67b
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x20(%rsp), %r8
movq 0x10(%rsp), %rdi
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
shrq $0x3, %r14
imull $0xaaaaaaab, %r14d, %edx # imm = 0xAAAAAAAB
addl %ebp, %edx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%rbx)
leaq (%rcx,%rcx,8), %rsi
leaq (%rsi,%rsi,2), %rsi
addq %rcx, %rsi
movl %edx, (%rax,%rsi)
movl $0x0, 0x4(%rax,%rsi)
movl 0x34(%rsp), %edx
movl %edx, 0x8(%rax,%rsi)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movq %rcx, 0xc(%rax,%rsi)
movl %edx, 0x14(%rax,%rsi)
jmp 0x1dd4b7
xorl %eax, %eax
jmp 0x1dd853
xorl %r15d, %r15d
movq %rcx, %rbp
movl %ecx, %esi
xorl $0x1, %esi
movq %r12, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1efacc
testl %eax, %eax
jne 0x1dd850
movq 0x18(%rsp), %rax
movq 0x28(%rsp), %rcx
cmpq (%rcx), %rax
jae 0x1dd850
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x18(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x1dd850
movq 0x8(%rbx), %rax
movq %rax, 0x8(%rsp)
movl $0x1, %r8d
movq %r12, %rdi
movq %rbp, %rsi
movq 0x28(%rsp), %rdx
xorl %ecx, %ecx
movq %rbx, %r9
callq 0x1dcf2c
testl %eax, %eax
je 0x1dd781
movq 0x8(%rbx), %rcx
movq 0x8(%rsp), %r9
leaq (%r9,%r9,8), %rax
leaq (%rax,%rax,2), %rax
addq %r9, %rax
addq $0x28, %rax
movq %r9, %rdx
movq 0x10(%rsp), %rdi
movq 0x20(%rsp), %r8
incq %rdx
cmpq %rcx, %rdx
jae 0x1dd78f
movq (%rbx), %rsi
movl (%rsi,%rax), %esi
addq $0x1c, %rax
cmpq %rsi, 0x18(%rsp)
jne 0x1dd75f
movq %r9, 0x8(%rbx)
jmp 0x1dd850
movq 0x8(%rsp), %rax
movq %rax, 0x8(%rbx)
jmp 0x1dd850
testq %r15, %r15
je 0x1dd7e9
testq %r8, %r8
je 0x1dd7b7
negq %r8
leaq (%r14,%r13,8), %rdx
addq $0xc, %rdx
xorl %eax, %eax
cmpl $0x0, (%rdx)
jns 0x1dd7d6
decq %rax
addq $0x18, %rdx
cmpq %rax, %r8
jne 0x1dd7a6
leaq 0x661cf(%rip), %rdi     # 0x24398d
leaq 0x62496(%rip), %rsi     # 0x23fc5b
leaq 0x661c8(%rip), %rcx     # 0x243994
movl $0x4859, %edx           # imm = 0x4859
callq 0x2110
subq 0x8(%r12), %rdi
shrq $0x3, %rdi
imull $0xaaaaaaab, %edi, %ebp # imm = 0xAAAAAAAB
subl %eax, %ebp
jmp 0x1dd7ee
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movq (%rbx), %rax
cmpq 0x10(%rbx), %rcx
jne 0x1dd825
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmovneq %rdx, %rcx
movq %rcx, 0x10(%rbx)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rsi
addq %rcx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%rbx)
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 %ebp, (%rax,%rdx)
movaps 0x622be(%rip), %xmm0    # 0x23fb00
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