// File: /workspace/github_cpp_makefile_star2_O2/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
andq $0x0, 0x8(%rdx)
movq 0x20(%rdi), %rax
movq %rcx, %rdx
shrq %rdx
cmpl $0x0, (%rax,%rdx,8)
js 0x18fbbb
movq %rdi, %r13
movq %rsi, 0x28(%rsp)
movq %rdx, 0x10(%rsp)
movq 0x8(%rdi), %r14
movq 0x28(%rdi), %rax
movq %rcx, 0x20(%rsp)
movq (%rax,%rcx,8), %rax
movl %eax, %ebp
shrq $0x20, %rax
imulq $0x18, %rax, %r15
leaq (%r14,%r15), %rdi
leaq (%r14,%r15), %rax
addq $0xc, %rax
xorl %ecx, %ecx
xorl %r12d, %r12d
cmpq %rbp, %rcx
jae 0x18f7b8
cmpq $0x1, %r12
ja 0x18f7b8
xorl %edx, %edx
cmpl $0x0, (%rax)
setns %dl
addq %rdx, %r12
incq %rcx
addq $0x18, %rax
jmp 0x18f799
cmpq $0x2, %r12
movq %r13, 0x40(%rsp)
movq %rdi, 0x8(%rsp)
jb 0x18fbc2
movq 0x20(%rsp), %rax
shll $0x1f, %eax
movq %rax, 0x20(%rsp)
xorl %r14d, %r14d
movq $0x0, 0x18(%rsp)
movq %rbp, 0x30(%rsp)
cmpq %rbp, %r14
je 0x18fcfb
imulq $0x18, %r14, %r15
cmpl $0x0, 0xc(%rdi,%r15)
js 0x18fa84
addq %rdi, %r15
movl 0x8(%r15), %r12d
movl %r12d, %esi
xorl $0x1, %esi
movq %r13, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1a5422
cmpl $0x2, %eax
jb 0x18f83e
movl %r12d, %ebp
shrl %ebp
movq 0x10(%rsp), %rcx
cmpq %rbp, %rcx
jne 0x18f8c9
movq 0x30(%rsp), %rbp
jmp 0x18f8bf
cmpl $0x1, %eax
jne 0x18f8bf
movl %r12d, %eax
shrl %eax
movq 0x28(%rsp), %rcx
cmpq (%rcx), %rax
movq 0x8(%rsp), %rdi
jae 0x18fa84
movq 0x8(%rcx), %rcx
cmpl $0x0, (%rcx,%rax,4)
js 0x18fa84
movq (%rbx), %rax
movq 0x8(%rbx), %rbp
movq 0x20(%r13), %rcx
movq 0x10(%rsp), %rdx
movl (%rcx,%rdx,8), %edx
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl %ecx, %edx
movl %edx, 0x3c(%rsp)
cmpq 0x10(%rbx), %rbp
jne 0x18fa8c
leaq (,%rbp,2), %rcx
testq %rbp, %rbp
pushq $0x2
popq %rdx
cmoveq %rdx, %rcx
movq %rcx, 0x10(%rbx)
imulq $0x1c, %rcx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
jmp 0x18fa8f
movq 0x8(%rsp), %rdi
jmp 0x18fa84
movq 0x20(%r13), %rax
movl (%rax,%rcx,8), %r13d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %r13d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x18f90b
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
imulq $0x1c, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
imulq $0x1c, %rcx, %rcx
andq $0x0, (%rax,%rcx)
movl %r13d, 0x8(%rax,%rcx)
movq 0x10(%rsp), %rdx
movl %edx, 0xc(%rax,%rcx)
andl $0x0, 0x10(%rax,%rcx)
movq 0x18(%rsp), %rsi
andl $0x3fffffff, %esi       # imm = 0x3FFFFFFF
movq 0x20(%rsp), %rdx
movq %rsi, 0x18(%rsp)
addl %esi, %edx
addl $0x40000000, %edx       # imm = 0x40000000
movl %r13d, 0x14(%rax,%rcx)
movl %edx, 0x18(%rax,%rcx)
movl (%r15), %r8d
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rax
movl (%rax,%rbp,8), %r15d
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl %eax, %r15d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x18f9a5
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
imulq $0x1c, %rdx, %rsi
movq %rax, %rdi
movq %r8, %r13
callq 0x2370
movq %r13, %r8
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
movq 0x8(%rsp), %rdi
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
leal (%r15,%r8), %r13d
shll $0x1f, %r12d
imulq $0x1c, %rcx, %rcx
andl $0x0, (%rax,%rcx)
movq 0x18(%rsp), %rdx
addl %r12d, %edx
addl $0x40000000, %edx       # imm = 0x40000000
movl %r8d, 0x4(%rax,%rcx)
movl %r13d, 0x8(%rax,%rcx)
movl %ebp, 0xc(%rax,%rcx)
andl $0x0, 0x10(%rax,%rcx)
movl %r15d, 0x14(%rax,%rcx)
movq %rdx, 0x18(%rsp)
movl %edx, 0x18(%rax,%rcx)
movq %rdi, %rax
movq 0x40(%rsp), %rcx
subq 0x8(%rcx), %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
movq %rax, %rbp
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq 0x10(%rbx), %rcx
jne 0x18fa45
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
imulq $0x1c, %rdx, %rsi
movq %rax, %rdi
movq %r8, %r12
callq 0x2370
movq %r12, %r8
movq 0x8(%rsp), %rdi
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
leal (%r14,%rbp), %edx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%rbx)
imulq $0x1c, %rcx, %rcx
movl %edx, (%rax,%rcx)
movl %r8d, 0x4(%rax,%rcx)
movl %r13d, 0x8(%rax,%rcx)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rdx, 0xc(%rax,%rcx)
movl %r15d, 0x14(%rax,%rcx)
movq 0x18(%rsp), %rdx
movl %edx, 0x18(%rax,%rcx)
movq 0x40(%rsp), %r13
movq 0x30(%rsp), %rbp
incq %r14
jmp 0x18f7ea
movq %rbp, %rcx
movq 0x18(%rsp), %rsi
andl $0x3fffffff, %esi       # imm = 0x3FFFFFFF
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
imulq $0x1c, %rcx, %rcx
andq $0x0, (%rax,%rcx)
movl 0x3c(%rsp), %edi
movl %edi, 0x8(%rax,%rcx)
movq 0x10(%rsp), %rdx
movl %edx, 0xc(%rax,%rcx)
andl $0x0, 0x10(%rax,%rcx)
movq 0x20(%rsp), %rdx
addl %edx, %esi
addl $0x40000000, %esi       # imm = 0x40000000
movl %edi, 0x14(%rax,%rcx)
movq %rsi, 0x18(%rsp)
movl %esi, 0x18(%rax,%rcx)
movl (%r15), %ecx
movq %r13, %rdi
movq %r12, %rsi
movq 0x28(%rsp), %rdx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x18f4e8
testl %eax, %eax
je 0x18fb31
movq 0x8(%rbx), %rcx
imulq $0x1c, %rbp, %rax
addq $0x28, %rax
movq %rbp, %rdx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %r8
incq %rdx
cmpq %rcx, %rdx
jae 0x18fb3a
movq (%rbx), %rsi
movl (%rsi,%rax), %esi
addq $0x1c, %rax
cmpq %rsi, %r8
jne 0x18fb11
movq %rbp, 0x8(%rbx)
jmp 0x18fa7f
movq %rbp, 0x8(%rbx)
jmp 0x18f834
movq %rdi, %rax
subq 0x8(%r13), %rax
cqto
pushq $0x18
popq %rsi
idivq %rsi
movq %rax, %rbp
movq (%rbx), %rax
cmpq 0x10(%rbx), %rcx
jne 0x18fb7f
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%rbx)
imulq $0x1c, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq 0x8(%rsp), %rdi
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
leal (%r14,%rbp), %edx
leaq 0x1(%rcx), %rsi
movq %rsi, 0x8(%rbx)
imulq $0x1c, %rcx, %rcx
movl %edx, (%rax,%rcx)
andl $0x0, 0x4(%rax,%rcx)
movl 0x3c(%rsp), %esi
movl %esi, 0x8(%rax,%rcx)
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
movq %rdx, 0xc(%rax,%rcx)
movl %esi, 0x14(%rax,%rcx)
movq 0x18(%rsp), %rdx
movl %edx, 0x18(%rax,%rcx)
jmp 0x18fa7f
xorl %eax, %eax
jmp 0x18fcfe
movq 0x20(%rsp), %rax
movl %eax, %esi
xorl $0x1, %esi
movq %r13, %rdi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x1a5422
testl %eax, %eax
jne 0x18fcfb
movq 0x10(%rsp), %rax
movq 0x28(%rsp), %rcx
cmpq (%rcx), %rax
jae 0x18fcfb
movq 0x28(%rsp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rsp), %rcx
cmpl $0x0, (%rax,%rcx,4)
js 0x18fcfb
movq %r13, %rdi
movq 0x8(%rbx), %r13
pushq $0x1
popq %r8
movq 0x20(%rsp), %rsi
movq 0x28(%rsp), %rdx
xorl %ecx, %ecx
movq %rbx, %r9
callq 0x18f4e8
testl %eax, %eax
je 0x18fc5b
movq 0x8(%rbx), %rcx
imulq $0x1c, %r13, %rdi
addq $0x28, %rdi
movq %r13, %rdx
movq 0x8(%rsp), %rax
incq %rdx
cmpq %rcx, %rdx
jae 0x18fc64
movq (%rbx), %rsi
movl (%rsi,%rdi), %esi
addq $0x1c, %rdi
cmpq %rsi, 0x10(%rsp)
jne 0x18fc42
movq %r13, 0x8(%rbx)
jmp 0x18fcfb
cmpq $0x1, %r12
jne 0x18fc93
negq %rbp
leaq (%r15,%r14), %rdi
addq $0xc, %rdi
xorl %esi, %esi
movq 0x40(%rsp), %rdx
cmpq %rsi, %rbp
je 0x18fd0d
cmpl $0x0, (%rdi)
jns 0x18fc99
decq %rsi
addq $0x18, %rdi
jmp 0x18fc7c
pushq $-0x1
popq %r14
jmp 0x18fcab
subq 0x8(%rdx), %rax
pushq $0x18
popq %rdi
cqto
idivq %rdi
movq %rax, %r14
subl %esi, %r14d
movq (%rbx), %rax
cmpq 0x10(%rbx), %rcx
jne 0x18fcd9
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmovneq %rdx, %rcx
movq %rcx, 0x10(%rbx)
imulq $0x1c, %rcx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%rbx)
movq 0x8(%rbx), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%rbx)
imulq $0x1c, %rcx, %rcx
movl %r14d, (%rax,%rcx)
movaps 0x61ce0(%rip), %xmm0    # 0x1f19d0
movups %xmm0, 0x4(%rax,%rcx)
andq $0x0, 0x14(%rax,%rcx)
movl 0x8(%rbx), %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x65b41(%rip), %rdi     # 0x1f5855
leaq 0x61e08(%rip), %rsi     # 0x1f1b23
leaq 0x65b3a(%rip), %rcx     # 0x1f585c
movl $0x4859, %edx           # imm = 0x4859
callq 0x2110