// File: 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 %rbp
movq %rsp, %rbp
movb %r8b, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movb %dl, -0x19(%rbp)
movq %rcx, -0x28(%rbp)
movb %al, -0x29(%rbp)
movq %r9, -0x38(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq (%rcx), %rcx
movq -0x18(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, -0x40(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x4(%rax,%rcx,4), %eax
movq -0x10(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq (%rcx), %rcx
movq -0x18(%rbp), %rdx
subl (%rcx,%rdx,4), %eax
movl %eax, %eax
movq %rax, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
cmpq $0x0, -0x38(%rbp)
je 0x10e1d
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x70(%rbp)
jmp 0x10e25
xorl %eax, %eax
movq %rax, -0x70(%rbp)
jmp 0x10e25
movq -0x70(%rbp), %rax
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x58(%rbp)
jne 0x10e40
movl $0x0, -0x4(%rbp)
jmp 0x110b0
movq -0x68(%rbp), %rax
addq $0x1, %rax
cmpq -0x58(%rbp), %rax
jge 0x10e55
cmpq $0x0, -0x68(%rbp)
jge 0x10e5d
movq $0x0, -0x68(%rbp)
cmpb $0x0, -0x19(%rbp)
je 0x10e8b
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq 0x10(%rax), %rax
imulq $0x28, -0x18(%rbp), %rcx
addq %rcx, %rax
movl (%rax), %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
movl %eax, %eax
subq -0x28(%rbp), %rax
subq $0x1, %rax
movq %rax, -0x28(%rbp)
movzbl -0x29(%rbp), %eax
cmpl $0x0, %eax
jne 0x10f8c
movq -0x68(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
addq $0x1, %rax
cmpq -0x58(%rbp), %rax
jge 0x10f0d
movq -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jb 0x10efd
movq -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq 0x8(%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jae 0x10efd
movq -0x40(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x48(%rbp)
movq $0x1, -0x50(%rbp)
jmp 0x10f0d
jmp 0x10eff
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x10ea0
cmpq $0x0, -0x50(%rbp)
jne 0x10f87
movq $0x0, -0x60(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x68(%rbp), %rax
jge 0x10f85
movq -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jb 0x10f75
movq -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq 0x8(%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jae 0x10f75
movq -0x40(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x48(%rbp)
movq $0x1, -0x50(%rbp)
jmp 0x10f85
jmp 0x10f77
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x10f1c
jmp 0x10f87
jmp 0x1107e
movq -0x68(%rbp), %rax
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jl 0x10ffa
movq -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jb 0x10fea
movq -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq 0x8(%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jae 0x10fea
movq -0x40(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x48(%rbp)
movq $0x1, -0x50(%rbp)
jmp 0x10ffa
jmp 0x10fec
movq -0x60(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x10f94
cmpq $0x0, -0x50(%rbp)
jne 0x1107c
movq -0x68(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
addq $0x1, %rax
cmpq -0x58(%rbp), %rax
jge 0x1107a
movq -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq (%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jb 0x1106a
movq -0x28(%rbp), %rax
movq -0x40(%rbp), %rcx
movq -0x60(%rbp), %rdx
movq 0x8(%rcx,%rdx,8), %rcx
shrq $0x20, %rcx
cmpq %rcx, %rax
jae 0x1106a
movq -0x40(%rbp), %rax
movq -0x60(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movl %eax, %eax
movq %rax, -0x48(%rbp)
movq $0x1, -0x50(%rbp)
jmp 0x1107a
jmp 0x1106c
movq -0x60(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x1100d
jmp 0x1107c
jmp 0x1107e
cmpq $0x0, -0x38(%rbp)
je 0x110a9
cmpq $0x0, -0x50(%rbp)
je 0x11096
movq -0x60(%rbp), %rax
movq %rax, -0x78(%rbp)
jmp 0x1109e
xorl %eax, %eax
movq %rax, -0x78(%rbp)
jmp 0x1109e
movq -0x78(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x48(%rbp), %rax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
popq %rbp
retq
nopw %cs:(%rax,%rax)