// File: /workspace/github_cpp_makefile_star2_O3/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
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movl %eax, 0x18(%rsp)
movl %eax, 0x24(%rsp)
testq %r9, %r9
je 0x1d5ed1
movl %eax, (%r9)
movl %eax, 0xc(%r9)
leaq 0xc0358(%rip), %rdi     # 0x296230
movq 0x10(%rdi), %rax
movq %rsi, %r12
shrq %r12
cmpq $0x0, (%rax,%r12,8)
je 0x1d5f35
movq 0x28(%r15), %rdx
movq (%rdx), %r10
movl (%r10,%r12,4), %eax
movl 0x4(%r10,%r12,4), %ebx
subl %eax, %ebx
je 0x1d5f35
movq 0x18(%rdx), %rdx
testq %rdx, %rdx
je 0x1d5f35
movl %ecx, 0x38(%rsp)
movq 0x18(%rdi), %rdi
movq (%rdi,%r12,8), %rdi
movq %rcx, %r14
addq %rdi, %r14
movl %r14d, 0x3c(%rsp)
movl %ecx, %r10d
cmpq %r8, %r10
jbe 0x1d5f4a
movl %r8d, 0x38(%rsp)
movl $0x1, %r10d
movl %r8d, %ecx
jmp 0x1d5f4d
xorl %r13d, %r13d
movq %r13, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r10d, %r10d
movl %r14d, %r11d
cmpq %r8, %r11
jbe 0x1d5f63
movl %r8d, 0x3c(%rsp)
movl $0x1, %r10d
movl %r8d, %r14d
movl %r12d, 0x34(%rsp)
shlb $0x5, %sil
andb $0x20, %sil
leal -0x80(%rsi), %r8d
movb %r8b, 0x54(%rsp)
movl $0x0, 0x40(%rsp)
movl %edi, 0x44(%rsp)
xorl %r8d, %r8d
testq %r10, %r10
je 0x1d5fb4
movl %r14d, %r10d
subl %ecx, %r10d
cmpq %r10, %rdi
cmovbq %rdi, %r10
testb %sil, %sil
jne 0x1d5fa9
movl %r10d, 0x44(%rsp)
movl %r10d, %edi
jmp 0x1d5fb4
movl %edi, %r8d
subl %r10d, %r8d
movl %r8d, 0x40(%rsp)
xorl %r13d, %r13d
cmpl %ecx, %r14d
jbe 0x1d5f38
cmpl %r8d, %edi
jbe 0x1d5f38
movq %r9, 0x58(%rsp)
leaq (%rax,%rax,2), %rax
movl 0xa8(%rsp), %ecx
movq 0xa0(%rsp), %r14
leaq (%rdx,%rax,4), %rbp
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
movl %ecx, 0x14(%rsp)
cmpl $0x1, %ebx
adcl $0x0, %ebx
xorl %r13d, %r13d
movl $0x1, (%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %rbp, %rdx
leaq 0x34(%rsp), %rcx
leaq 0x18(%rsp), %r8
movq 0x60(%rsp), %r9
callq 0x1d5d76
testq %rax, %rax
je 0x1d60b8
movl 0x30(%rsp), %eax
shldl $0x1, %eax, 0x24(%rsp)
orl $0x40000000, %eax       # imm = 0x40000000
movl %eax, 0x30(%rsp)
cmpl $-0x1, 0xa8(%rsp)
je 0x1d604f
andl $0xc0000000, %eax       # imm = 0xC0000000
addl 0x14(%rsp), %eax
movl %eax, 0x30(%rsp)
testq %r14, %r14
je 0x1d60b5
movq (%r14), %rax
movq 0x8(%r14), %rcx
cmpq 0x10(%r14), %rcx
jne 0x1d608f
leaq (%rcx,%rcx), %rdx
testq %rcx, %rcx
movl $0x2, %ecx
cmoveq %rcx, %rdx
movq %rdx, 0x10(%r14)
leaq (%rdx,%rdx,8), %rcx
leaq (%rcx,%rcx,2), %rsi
addq %rdx, %rsi
movq %rax, %rdi
callq 0x2370
movq %rax, (%r14)
movq 0x8(%r14), %rcx
leaq 0x1(%rcx), %rdx
movq %rdx, 0x8(%r14)
leaq (%rcx,%rcx,8), %rdx
leaq (%rdx,%rdx,2), %rdx
addq %rcx, %rdx
movups 0x18(%rsp), %xmm0
movups 0x24(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
incq %r13
addq $0xc, %rbp
decq %rbx
jne 0x1d5ff8
movq 0x58(%rsp), %rdx
testq %rdx, %rdx
setne %al
cmpq $0x1, %r13
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1d5f38
movups 0x18(%rsp), %xmm0
movups 0x24(%rsp), %xmm1
movups %xmm1, 0xc(%rdx)
movups %xmm0, (%rdx)
movl $0x1, %r13d
jmp 0x1d5f38