// File: /workspace/github_cpp_makefile_star2_O1/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, 0x3c(%rsp)
movl %eax, 0x48(%rsp)
testq %r9, %r9
je 0x1cbf51
movl %eax, (%r9)
movl %eax, 0xc(%r9)
leaq 0xbf2d8(%rip), %rdi     # 0x28b230
movq 0x10(%rdi), %rax
movq %rsi, %r12
shrq %r12
cmpq $0x0, (%rax,%r12,8)
je 0x1cc05e
movq 0x28(%r15), %r10
movq (%r10), %rdx
movl (%rdx,%r12,4), %eax
movl 0x4(%rdx,%r12,4), %edx
movl %edx, %r14d
subl %eax, %r14d
jne 0x1cbf8a
xorl %r13d, %r13d
jmp 0x1cbf96
leaq (%rax,%rax,2), %r13
shlq $0x2, %r13
addq 0x18(%r10), %r13
testq %r13, %r13
je 0x1cc05e
movl %ecx, %r10d
movl %ecx, 0x18(%rsp)
movq 0x18(%rdi), %rdi
movq (%rdi,%r12,8), %rdi
addq %rdi, %rcx
movl %ecx, 0x1c(%rsp)
movl %r10d, %r10d
cmpq %r8, %r10
jbe 0x1cbfca
movl %r8d, 0x18(%rsp)
movl $0x1, %r10d
jmp 0x1cbfcd
xorl %r10d, %r10d
movl %ecx, %ecx
cmpq %r8, %rcx
jbe 0x1cbfdf
movl %r8d, 0x1c(%rsp)
movl $0x1, %r10d
movl %r12d, 0x14(%rsp)
movb 0x34(%rsp), %cl
shlb $0x5, %sil
andb $0x20, %sil
andb $0x5f, %cl
orb %sil, %cl
orb $-0x80, %cl
movb %cl, 0x34(%rsp)
movl $0x0, 0x20(%rsp)
movl %edi, 0x24(%rsp)
testq %r10, %r10
je 0x1cc03a
movl 0x1c(%rsp), %ecx
subl 0x18(%rsp), %ecx
cmpq %rcx, %rdi
cmovbq %rdi, %rcx
testb %sil, %sil
jne 0x1cc02e
movl $0x0, 0x20(%rsp)
movl %ecx, %edi
jmp 0x1cc036
movl %edi, %esi
subl %ecx, %esi
movl %esi, 0x20(%rsp)
movl %edi, 0x24(%rsp)
movl 0x1c(%rsp), %ecx
cmpl 0x18(%rsp), %ecx
jbe 0x1cc05e
movl 0x24(%rsp), %ecx
cmpl 0x20(%rsp), %ecx
jbe 0x1cc05e
movq %r9, 0x58(%rsp)
cmpl %eax, %edx
jne 0x1cc072
xorl %ebp, %ebp
jmp 0x1cc161
xorl %ebp, %ebp
movq %rbp, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0xa8(%rsp), %eax
movq 0xa0(%rsp), %rbx
andl $0x3fffffff, %eax       # imm = 0x3FFFFFFF
movl %eax, 0x38(%rsp)
cmpl $0x1, %r14d
adcl $0x0, %r14d
xorl %ebp, %ebp
movl $0x1, (%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %r13, %rdx
leaq 0x14(%rsp), %rcx
leaq 0x3c(%rsp), %r8
movq 0x60(%rsp), %r9
callq 0x1cbdd7
testq %rax, %rax
je 0x1cc154
movl 0x54(%rsp), %eax
shldl $0x1, %eax, 0x48(%rsp)
orl $0x40000000, %eax       # imm = 0x40000000
movl %eax, 0x54(%rsp)
cmpl $-0x1, 0xa8(%rsp)
je 0x1cc0eb
andl $0xc0000000, %eax       # imm = 0xC0000000
addl 0x38(%rsp), %eax
movl %eax, 0x54(%rsp)
testq %rbx, %rbx
je 0x1cc151
movq 0x10(%rbx), %rax
cmpq %rax, 0x8(%rbx)
jne 0x1cc124
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 (%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
movups 0x3c(%rsp), %xmm0
movups 0x48(%rsp), %xmm1
movups %xmm1, 0xc(%rax,%rdx)
movups %xmm0, (%rax,%rdx)
incq %rbp
addq $0xc, %r13
decq %r14
jne 0x1cc094
movq 0x58(%rsp), %rdx
testq %rdx, %rdx
setne %al
cmpq $0x1, %rbp
sete %cl
andb %al, %cl
cmpb $0x1, %cl
jne 0x1cc060
movups 0x3c(%rsp), %xmm0
movups 0x48(%rsp), %xmm1
movups %xmm1, 0xc(%rdx)
movups %xmm0, (%rdx)
jmp 0x1cc060