// File: /workspace/github_cpp_makefile_star2_O1/chhylp123[P]hifiasm/Process_Read.cpp
// Function: retrieve_u_cov(ul_idx_t const*, unsigned long, unsigned char, unsigned long, unsigned char, long*)
uint32_t retrieve_u_cov(const ul_idx_t *ul, uint64_t id, uint8_t strand, uint64_t pos, uint8_t dir, int64_t *pi)
{
	uint64_t *a = ul->cc->interval.a + ul->cc->idx[id], cc = 0, ff = 0;
	int64_t a_n = ul->cc->idx[id+1]-ul->cc->idx[id], k = 0, cc_i = pi? *pi:0;
	if(a_n == 0) return 0;
	if(cc_i + 1 >= a_n || cc_i < 0) cc_i = 0;
	if(strand) pos = ul->ug->u.a[id].len - pos - 1;
	if(dir == 0) {
		for (k = cc_i; k + 1 < a_n; k++) {
			if(pos>=(a[k]>>32) && pos<(a[k+1]>>32)) {
				cc = (uint32_t)a[k];
				ff = 1;
				break;
			}
		}

		if(ff == 0) {
			for (k = 0; k < cc_i; k++) {
					if(pos>=(a[k]>>32) && pos<(a[k+1]>>32)) {
					cc = (uint32_t)a[k];
					ff = 1;
					break;
				}
			}
		}
	} else {
		for (k = cc_i; k >= 0; k--) {
			if(pos>=(a[k]>>32) && pos<(a[k+1]>>32)) {
				cc = (uint32_t)a[k];
				ff = 1;
				break;
			}
		}

		if(ff == 0) {
			for (k = cc_i+1; k + 1 < a_n; k++) {
				if(pos>=(a[k]>>32) && pos<(a[k+1]>>32)) {
					cc = (uint32_t)a[k];
					ff = 1;
					break;
				}
			}
		}
	}
	
	if(pi) *pi = ff?k:0;
	return cc;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movq 0x10(%rdi), %r14
movq (%r14), %rax
movl (%rax,%rsi,4), %ebx
movl 0x4(%rax,%rsi,4), %r11d
xorl %eax, %eax
testq %r9, %r9
je 0x36d37
movq (%r9), %r10
jmp 0x36d3a
xorl %r10d, %r10d
cmpl %ebx, %r11d
je 0x36eb9
subl %ebx, %r11d
leaq 0x1(%r10), %rax
xorl %r15d, %r15d
testq %r10, %r10
cmovleq %r15, %r10
cmpq %r11, %rax
cmovgeq %r15, %r10
testb %dl, %dl
je 0x36d78
movq (%rdi), %rax
movq 0x10(%rax), %rax
leaq (%rsi,%rsi,4), %rdx
movl (%rax,%rdx,8), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
notq %rcx
addq %rax, %rcx
movq 0x18(%r14), %rsi
testb %r8b, %r8b
je 0x36e1f
leaq (%rsi,%rbx,8), %rsi
addq $0x8, %rsi
xorl %edi, %edi
movq %r10, %rdx
movq -0x8(%rsi,%rdx,8), %rax
movq %rax, %r8
shrq $0x20, %r8
cmpq %r8, %rcx
jb 0x36dad
movl 0x4(%rsi,%rdx,8), %r8d
cmpq %r8, %rcx
jb 0x36dc6
leaq -0x1(%rdx), %rax
testq %rdx, %rdx
setle %dil
movq %rax, %rdx
jg 0x36d92
movq $-0x1, %rdx
xorl %eax, %eax
testb $0x1, %dil
je 0x36eb1
leaq 0x2(%r10), %rdx
cmpq %r11, %rdx
jae 0x36eaf
incq %r10
movl $0x2, %edi
subq %r11, %rdi
movq %r10, %rdx
movq -0x8(%rsi,%rdx,8), %r8
movq %r8, %r10
shrq $0x20, %r10
cmpq %r10, %rcx
jb 0x36e0a
movl 0x4(%rsi,%rdx,8), %r10d
cmpq %r10, %rcx
jb 0x36ebf
leaq (%rdi,%rdx), %r8
incq %r8
incq %rdx
cmpq $0x1, %r8
jne 0x36deb
jmp 0x36eaf
leaq 0x1(%r10), %rax
cmpq %r11, %rax
setb %dil
jae 0x36e6d
leaq -0x1(%r11), %rdx
leaq (%rsi,%rbx,8), %r8
addq $0x8, %r8
movq %r10, %r14
movq -0x8(%r8,%r14,8), %rax
movq %rax, %r15
shrq $0x20, %r15
cmpq %r15, %rcx
jb 0x36e56
movl 0x4(%r8,%r14,8), %r15d
cmpq %r15, %rcx
jb 0x36e74
leaq 0x2(%r14), %rax
cmpq %r11, %rax
setb %dil
incq %r14
cmpq %r14, %rdx
jne 0x36e3b
xorl %eax, %eax
jmp 0x36e77
xorl %eax, %eax
movq %r10, %rdx
jmp 0x36e77
movq %r14, %rdx
testb $0x1, %dil
jne 0x36eb1
testq %r10, %r10
je 0x36eaf
leaq (%rsi,%rbx,8), %rsi
addq $0x8, %rsi
xorl %edx, %edx
movq -0x8(%rsi,%rdx,8), %rdi
movq %rdi, %r8
shrq $0x20, %r8
cmpq %r8, %rcx
jb 0x36ea7
movl 0x4(%rsi,%rdx,8), %r8d
cmpq %r8, %rcx
jb 0x36ec4
incq %rdx
cmpq %rdx, %r10
jne 0x36e8c
xorl %edx, %edx
testq %r9, %r9
je 0x36eb9
movq %rdx, (%r9)
popq %rbx
popq %r14
popq %r15
retq
movq %r8, %rax
jmp 0x36eb1
movq %rdi, %rax
jmp 0x36eb1