// File: /workspace/github_cpp_makefile_star2_O2/chhylp123[P]hifiasm/inter.cpp
// Function: get_unique_rctg_aln(ul_idx_t const*, unsigned long, unsigned long, unsigned long, unsigned long, ul_ov_t*, kv_ul_ov_t*, unsigned int)
uint64_t get_unique_rctg_aln(const ul_idx_t *uref, uint64_t v, uint64_t vi, uint64_t vs, uint64_t ulen, ul_ov_t *ures, kv_ul_ov_t *rr, uint32_t sec)
{
	utg_rid_dt *a = NULL; uint64_t a_n, k, rrn = 0, over_bd = 0; uc_block_t z; ul_ov_t p;
	p.tn = p.qn = ((uint32_t)-1); if(ures) ures->tn = ures->qn = ((uint32_t)-1);
	if(IS_SCAF_READ(R_INF, (v>>1))) return 0;///actually no scaf nodes within the assembly graph
	a = get_r_ug_region(uref->r_ug, &a_n, v>>1);
	if(!a) return 0;
	
	z.qs = vs; z.qe = vs + Get_READ_LENGTH(R_INF, (v>>1)); 
	if(z.qs > ulen) {
		z.qs = ulen; 
		over_bd = 1;
	} 
	
	if(z.qe > ulen) {
		z.qe = ulen;
		over_bd = 1;
	}

	z.hid = v>>1; z.rev = v&1; z.el = 1;
	z.ts = 0; z.te = Get_READ_LENGTH(R_INF, (v>>1));
	if(over_bd) {//////need to handle it especially for circles
		over_bd = z.qe - z.qs; 
		if(over_bd > Get_READ_LENGTH(R_INF, (v>>1))) {
			over_bd = Get_READ_LENGTH(R_INF, (v>>1));
		}
		if(!(z.rev)) {
			z.ts = 0; z.te = over_bd;
		} else {
			z.ts = Get_READ_LENGTH(R_INF, (v>>1))-over_bd; z.te = Get_READ_LENGTH(R_INF, (v>>1));
		}
	}
	if(z.qe <= z.qs || z.te <= z.ts) return 0;


	for (k = rrn = 0; k < a_n; k++) {
		if(!rov2uov_ctg(v>>1, uref, &(a[k]), &z, &p, vi, 1)) continue;
		p.el = 1; p.tn <<= 1; p.tn |= p.rev; ///p.qn: offset within q; p.sec: offset within t; p.tn: tid
		if(sec != ((uint32_t)-1)) p.sec = sec;
		if(rr) kv_push(ul_ov_t, *rr, p);
		rrn++;
	} 

	if((ures) && (rrn == 1)) *ures = p;
	return rrn;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdx, 0x60(%rsp)
movq %rdi, %r15
orl $-0x1, 0x18(%rsp)
orl $-0x1, 0x24(%rsp)
testq %r9, %r9
je 0x189628
orl $-0x1, (%r9)
orl $-0x1, 0xc(%r9)
leaq 0xcac01(%rip), %rdx     # 0x254230
movq 0x10(%rdx), %rax
movq %rsi, %r12
shrq %r12
cmpq $0x0, (%rax,%r12,8)
je 0x189689
movq 0x28(%r15), %rdi
movq (%rdi), %r10
movl (%r10,%r12,4), %eax
movl 0x4(%r10,%r12,4), %ebx
subl %eax, %ebx
je 0x189689
movq 0x18(%rdi), %r13
testq %r13, %r13
je 0x189689
movl %ecx, 0x38(%rsp)
movq 0x18(%rdx), %rdx
movq (%rdx,%r12,8), %rdx
movq %rcx, %rdi
addq %rdx, %rdi
movl %edi, 0x3c(%rsp)
movl %ecx, %r10d
cmpq %r8, %r10
jbe 0x18969d
movl %r8d, 0x38(%rsp)
pushq $0x1
popq %r11
movl %r8d, %ecx
jmp 0x1896a0
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r11d, %r11d
movl %edi, %r10d
cmpq %r8, %r10
jbe 0x1896b4
movl %r8d, 0x3c(%rsp)
pushq $0x1
popq %r11
movl %r8d, %edi
movl %r12d, 0x34(%rsp)
shlb $0x5, %sil
andb $0x20, %sil
leal -0x80(%rsi), %r8d
movb %r8b, 0x54(%rsp)
andl $0x0, 0x40(%rsp)
movl %edx, 0x44(%rsp)
xorl %r8d, %r8d
testq %r11, %r11
je 0x189702
movl %edi, %r10d
subl %ecx, %r10d
cmpq %r10, %rdx
cmovbq %rdx, %r10
testb %sil, %sil
jne 0x1896f7
movl %r10d, 0x44(%rsp)
movl %r10d, %edx
jmp 0x189702
movl %edx, %r8d
subl %r10d, %r8d
movl %r8d, 0x40(%rsp)
xorl %ebp, %ebp
cmpl %ecx, %edi
jbe 0x18968b
cmpl %r8d, %edx
jbe 0x18968b
movq %r9, 0x58(%rsp)
imulq $0xc, %rax, %rax
movl 0xa8(%rsp), %ecx
movq 0xa0(%rsp), %r14
addq %rax, %r13
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, 0x14(%rsp)
xorl %ebp, %ebp
subq $0x1, %rbx
jb 0x1897fb
movl $0x1, (%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
leaq 0x34(%rsp), %rcx
leaq 0x18(%rsp), %r8
movq 0x60(%rsp), %r9
callq 0x1894cc
testq %rax, %rax
je 0x1897f2
movl 0x30(%rsp), %eax
shldl $0x1, %eax, 0x24(%rsp)
orl $0x40000000, %eax       # imm = 0x40000000
movl %eax, 0x30(%rsp)
cmpl $-0x1, 0xa8(%rsp)
je 0x189799
andl $0xc0000000, %eax       # imm = 0xC0000000
addl 0x14(%rsp), %eax
movl %eax, 0x30(%rsp)
testq %r14, %r14
je 0x1897ef
movq (%r14), %rax
movq 0x8(%r14), %rcx
cmpq 0x10(%r14), %rcx
jne 0x1897d0
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
pushq $0x2
popq %rcx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r14)
imulq $0x1c, %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%r14)
movq 0x8(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
imulq $0x1c, %rcx, %rcx
movups 0x18(%rsp), %xmm0
movups 0x24(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rcx)
movups %xmm0, (%rax,%rcx)
incq %rbp
addq $0xc, %r13
jmp 0x189738
movq 0x58(%rsp), %rdx
testq %rdx, %rdx
setne %al
cmpq $0x1, %rbp
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x18968b
movups 0x18(%rsp), %xmm0
movups 0x24(%rsp), %xmm1
movups %xmm1, 0xc(%rdx)
movups %xmm0, (%rdx)
pushq $0x1
popq %rbp
jmp 0x18968b