// File: /workspace/github_c_makefile_star2_O0/ToniWestbrook[P]paladin/bntseq.c
// Function: bns_fetch_seq
uint8_t *bns_fetch_seq(const bntseq_t *bns, const uint8_t *pac, int64_t *beg, int64_t mid, int64_t *end, int *rid)
{
	int64_t far_beg, far_end, len;
	int is_rev;
	uint8_t *seq;

	if (*end < *beg) *end ^= *beg, *beg ^= *end, *end ^= *beg; // if end is smaller, swap
	assert(*beg <= mid && mid < *end);
	*rid = bns_pos2rid(bns, bns_depos(bns, mid, &is_rev));
	far_beg = bns->anns[*rid].offset;
	far_end = far_beg + bns->anns[*rid].len;
	if (is_rev) { // flip to the reverse strand
		int64_t tmp = far_beg;
		far_beg = (bns->l_pac<<1) - far_end;
		far_end = (bns->l_pac<<1) - tmp;
	}
	*beg = *beg > far_beg? *beg : far_beg;
	*end = *end < far_end? *end : far_end;
	seq = bns_get_seq(bns->l_pac, pac, *beg, *end, &len);
	if (seq == 0 || *end - *beg != len) {
		fprintf(stderr, "[E::%s] begin=%ld, mid=%ld, end=%ld, len=%ld, seq=%p, rid=%d, far_beg=%ld, far_end=%ld\n",
				__func__, (long)*beg, (long)mid, (long)*end, (long)len, seq, *rid, (long)far_beg, (long)far_end);
	}
	assert(seq && *end - *beg == len); // assertion failure should never happen
	return seq;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r14
pushq %rbx
subq $0xa0, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq %rdx, -0x28(%rbp)
movq %rcx, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movq %r9, -0x40(%rbp)
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
cmpq (%rcx), %rax
jge 0x18039
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x38(%rbp), %rax
xorq (%rax), %rcx
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rcx
movq -0x28(%rbp), %rax
xorq (%rax), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x38(%rbp), %rax
xorq (%rax), %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpq -0x30(%rbp), %rax
jg 0x18055
movq -0x30(%rbp), %rax
movq -0x38(%rbp), %rcx
cmpq (%rcx), %rax
jge 0x18055
jmp 0x18074
leaq 0x22211(%rip), %rdi     # 0x3a26d
leaq 0x220d5(%rip), %rsi     # 0x3a138
movl $0x1f0, %edx            # imm = 0x1F0
leaq 0x22218(%rip), %rcx     # 0x3a287
callq 0x3190
movq -0x18(%rbp), %rax
movq %rax, -0x78(%rbp)
movq -0x18(%rbp), %rdi
movq -0x30(%rbp), %rsi
leaq -0x5c(%rbp), %rdx
callq 0x17b90
movq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0x179d0
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x40(%rbp), %rcx
movslq (%rcx), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x10(%rcx), %rcx
movq -0x40(%rbp), %rdx
movslq (%rdx), %rdx
imulq $0x28, %rdx, %rdx
addq %rdx, %rcx
movslq 0x8(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
cmpl $0x0, -0x5c(%rbp)
je 0x18115
movq -0x48(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
shlq %rax
subq -0x50(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x18(%rbp), %rax
movq (%rax), %rax
shlq %rax
subq -0x70(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rax
movq (%rax), %rax
cmpq -0x48(%rbp), %rax
jle 0x1812f
movq -0x28(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x80(%rbp)
jmp 0x18137
movq -0x48(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x80(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, (%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rax
cmpq -0x50(%rbp), %rax
jge 0x1815f
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x88(%rbp)
jmp 0x1816a
movq -0x50(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x20(%rbp), %rsi
movq -0x28(%rbp), %rax
movq (%rax), %rdx
movq -0x38(%rbp), %rax
movq (%rax), %rcx
leaq -0x58(%rbp), %r8
callq 0x17e20
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x181b9
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
subq (%rcx), %rax
cmpq -0x58(%rbp), %rax
je 0x18219
movq 0x27e18(%rip), %rax     # 0x3ffd8
movq (%rax), %rdi
movq -0x28(%rbp), %rax
movq (%rax), %rcx
movq -0x30(%rbp), %r8
movq -0x38(%rbp), %rax
movq (%rax), %r9
movq -0x58(%rbp), %r14
movq -0x68(%rbp), %rbx
movq -0x40(%rbp), %rax
movl (%rax), %r11d
movq -0x48(%rbp), %r10
movq -0x50(%rbp), %rax
leaq 0x220f4(%rip), %rsi     # 0x3a2e7
leaq 0x22145(%rip), %rdx     # 0x3a33f
movq %r14, (%rsp)
movq %rbx, 0x8(%rsp)
movl %r11d, 0x10(%rsp)
movq %r10, 0x18(%rsp)
movq %rax, 0x20(%rsp)
movb $0x0, %al
callq 0x34e0
cmpq $0x0, -0x68(%rbp)
je 0x18236
movq -0x38(%rbp), %rax
movq (%rax), %rax
movq -0x28(%rbp), %rcx
subq (%rcx), %rax
cmpq -0x58(%rbp), %rax
jne 0x18236
jmp 0x18255
leaq 0x22110(%rip), %rdi     # 0x3a34d
leaq 0x21ef4(%rip), %rsi     # 0x3a138
movl $0x200, %edx            # imm = 0x200
leaq 0x22037(%rip), %rcx     # 0x3a287
callq 0x3190
movq -0x68(%rbp), %rax
addq $0xa0, %rsp
popq %rbx
popq %r14
popq %rbp
retq
nopw %cs:(%rax,%rax)