// File: 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
movq %rsp, %rbp
subq $0xb0, %rsp
movl 0x18(%rbp), %eax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movl $0xffffffff, -0xa0(%rbp) # imm = 0xFFFFFFFF
movl $0xffffffff, -0x94(%rbp) # imm = 0xFFFFFFFF
cmpq $0x0, -0x38(%rbp)
je 0x2dd672
movq -0x38(%rbp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq -0x38(%rbp), %rax
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
leaq 0xe7c57(%rip), %rax     # 0x3c52d0
movq 0x10(%rax), %rax
movq -0x18(%rbp), %rcx
shrq %rcx
cmpq $0x0, (%rax,%rcx,8)
jne 0x2dd698
movq $0x0, -0x8(%rbp)
jmp 0x2dda0d
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x18(%rbp), %rdx
shrq %rdx
leaq -0x48(%rbp), %rsi
callq 0x2cf9e0
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x2dd6c8
movq $0x0, -0x8(%rbp)
jmp 0x2dda0d
movq -0x28(%rbp), %rax
movl %eax, -0x80(%rbp)
movq -0x28(%rbp), %rax
leaq 0xe7bf6(%rip), %rcx     # 0x3c52d0
movq 0x18(%rcx), %rcx
movq -0x18(%rbp), %rdx
shrq %rdx
addq (%rcx,%rdx,8), %rax
movl %eax, -0x7c(%rbp)
movl -0x80(%rbp), %eax
cmpq -0x30(%rbp), %rax
jbe 0x2dd704
movq -0x30(%rbp), %rax
movl %eax, -0x80(%rbp)
movq $0x1, -0x60(%rbp)
movl -0x7c(%rbp), %eax
cmpq -0x30(%rbp), %rax
jbe 0x2dd71c
movq -0x30(%rbp), %rax
movl %eax, -0x7c(%rbp)
movq $0x1, -0x60(%rbp)
movq -0x18(%rbp), %rax
shrq %rax
movl %eax, -0x84(%rbp)
movq -0x18(%rbp), %rax
andq $0x1, %rax
movb %al, %cl
movb -0x64(%rbp), %al
andb $0x1, %cl
shlb $0x5, %cl
andb $-0x21, %al
orb %cl, %al
movb %al, -0x64(%rbp)
movb -0x64(%rbp), %al
andb $0x7f, %al
orb $-0x80, %al
movb %al, -0x64(%rbp)
movl $0x0, -0x78(%rbp)
leaq 0xe7b75(%rip), %rax     # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
shrq %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x74(%rbp)
cmpq $0x0, -0x60(%rbp)
je 0x2dd80e
movl -0x7c(%rbp), %eax
subl -0x80(%rbp), %eax
movl %eax, %eax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
leaq 0xe7b41(%rip), %rcx     # 0x3c52d0
movq 0x18(%rcx), %rcx
movq -0x18(%rbp), %rdx
shrq %rdx
cmpq (%rcx,%rdx,8), %rax
jbe 0x2dd7ba
leaq 0xe7b29(%rip), %rax     # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
shrq %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x60(%rbp)
movb -0x64(%rbp), %al
shrb $0x5, %al
andb $0x1, %al
cmpb $0x0, %al
jne 0x2dd7d6
movl $0x0, -0x78(%rbp)
movq -0x60(%rbp), %rax
movl %eax, -0x74(%rbp)
jmp 0x2dd80c
leaq 0xe7af3(%rip), %rax     # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
shrq %rcx
movq (%rax,%rcx,8), %rax
subq -0x60(%rbp), %rax
movl %eax, -0x78(%rbp)
leaq 0xe7ad6(%rip), %rax     # 0x3c52d0
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
shrq %rcx
movq (%rax,%rcx,8), %rax
movl %eax, -0x74(%rbp)
jmp 0x2dd80e
movl -0x7c(%rbp), %eax
cmpl -0x80(%rbp), %eax
jbe 0x2dd81e
movl -0x74(%rbp), %eax
cmpl -0x78(%rbp), %eax
ja 0x2dd82b
movq $0x0, -0x8(%rbp)
jmp 0x2dda0d
movq $0x0, -0x58(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x50(%rbp), %rax
cmpq -0x48(%rbp), %rax
jae 0x2dd9ca
movq -0x18(%rbp), %rdi
shrq %rdi
movq -0x10(%rbp), %rsi
movq -0x40(%rbp), %rdx
imulq $0xc, -0x50(%rbp), %rax
addq %rax, %rdx
movq -0x20(%rbp), %rax
movl %eax, %r9d
leaq -0x84(%rbp), %rcx
leaq -0xa0(%rbp), %r8
movl $0x1, (%rsp)
callq 0x2dd360
cmpq $0x0, %rax
jne 0x2dd88c
jmp 0x2dd9b9
movl -0x88(%rbp), %eax
andl $0xbfffffff, %eax       # imm = 0xBFFFFFFF
orl $0x40000000, %eax       # imm = 0x40000000
movl %eax, -0x88(%rbp)
movl -0x94(%rbp), %eax
shll %eax
movl %eax, -0x94(%rbp)
movl -0x88(%rbp), %eax
shrl $0x1f, %eax
orl -0x94(%rbp), %eax
movl %eax, -0x94(%rbp)
cmpl $-0x1, 0x18(%rbp)
je 0x2dd8e7
movl 0x18(%rbp), %ecx
movl -0x88(%rbp), %eax
andl $0x3fffffff, %ecx       # imm = 0x3FFFFFFF
andl $0xc0000000, %eax       # imm = 0xC0000000
orl %ecx, %eax
movl %eax, -0x88(%rbp)
cmpq $0x0, 0x10(%rbp)
je 0x2dd9ad
jmp 0x2dd8f4
movq 0x10(%rbp), %rax
movq 0x8(%rax), %rax
movq 0x10(%rbp), %rcx
cmpq 0x10(%rcx), %rax
jne 0x2dd961
movq 0x10(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2dd925
movq 0x10(%rbp), %rax
movq 0x10(%rax), %rax
shlq %rax
movq %rax, -0xa8(%rbp)
jmp 0x2dd933
movl $0x2, %eax
movq %rax, -0xa8(%rbp)
jmp 0x2dd933
movq -0xa8(%rbp), %rcx
movq 0x10(%rbp), %rax
movq %rcx, 0x10(%rax)
movq 0x10(%rbp), %rax
movq (%rax), %rdi
movq 0x10(%rbp), %rax
imulq $0x1c, 0x10(%rax), %rsi
callq 0x2360
movq %rax, %rcx
movq 0x10(%rbp), %rax
movq %rcx, (%rax)
movq 0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rbp), %rdx
movq 0x8(%rdx), %rcx
movq %rcx, %rsi
addq $0x1, %rsi
movq %rsi, 0x8(%rdx)
imulq $0x1c, %rcx, %rcx
addq %rcx, %rax
movq -0xa0(%rbp), %rcx
movq %rcx, (%rax)
movq -0x98(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x90(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x88(%rbp), %ecx
movl %ecx, 0x18(%rax)
jmp 0x2dd9ad
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x50(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x50(%rbp)
jmp 0x2dd83b
cmpq $0x0, -0x38(%rbp)
je 0x2dda05
cmpq $0x1, -0x58(%rbp)
jne 0x2dda05
movq -0x38(%rbp), %rax
movq -0xa0(%rbp), %rcx
movq %rcx, (%rax)
movq -0x98(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x90(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x88(%rbp), %ecx
movl %ecx, 0x18(%rax)
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xb0, %rsp
popq %rbp
retq
nopw (%rax,%rax)