// File: /workspace/github_c_makefile_star2_O3/DReichLab[P]adna/hts.c
// Function: hts_itr_next
int hts_itr_next(BGZF *fp, hts_itr_t *iter, void *r, hts_readrec_f readrec, void *hdr)
{
	int ret, tid, beg, end;
	if (iter && iter->finished) return -1;
	if (iter->read_rest) {
		if (iter->curr_off) { // seek to the start
			bgzf_seek(fp, iter->curr_off, SEEK_SET);
			iter->curr_off = 0; // only seek once
		}
		ret = readrec(fp, hdr, r, &tid, &beg, &end);
		if (ret < 0) iter->finished = 1;
		return ret;
	}
	if (iter->off == 0) return -1;
	for (;;) {
		if (iter->curr_off == 0 || iter->curr_off >= iter->off[iter->i].v) { // then jump to the next chunk
			if (iter->i == iter->n_off - 1) { ret = -1; break; } // no more chunks
			if (iter->i < 0 || iter->off[iter->i].v != iter->off[iter->i+1].u) { // not adjacent chunks; then seek
				bgzf_seek(fp, iter->off[iter->i+1].u, SEEK_SET);
				iter->curr_off = bgzf_tell(fp);
			}
			++iter->i;
		}
		if ((ret = readrec(fp, hdr, r, &tid, &beg, &end)) >= 0) {
			iter->curr_off = bgzf_tell(fp);
			if (tid != iter->tid || beg >= iter->end) { // no need to proceed
				ret = -1; break;
			} else if (end > iter->beg && iter->end > beg) return ret;
		} else break; // end of file or error
	}
	iter->finished = 1;
	return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rcx, %r14
movl (%rsi), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb $0x2, %cl
jne 0x8545
movq %r8, %r15
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r13
testb $0x1, %cl
jne 0x84f9
cmpq $0x0, 0x20(%rbx)
je 0x8545
movq 0x18(%rbx), %rdx
leaq 0xc(%rsp), %rbp
movl 0x14(%rbx), %eax
movslq %eax, %rcx
testq %rdx, %rdx
je 0x8449
movq 0x20(%rbx), %rsi
movq %rcx, %rdi
shlq $0x4, %rdi
cmpq 0x8(%rsi,%rdi), %rdx
jb 0x84a2
movl 0x10(%rbx), %edx
decl %edx
cmpl %edx, %eax
je 0x853b
movq 0x20(%rbx), %rdx
testl %eax, %eax
js 0x8473
movq %rax, %rcx
shlq $0x4, %rcx
movq 0x10(%rdx,%rcx), %rsi
cmpq %rsi, 0x8(%rdx,%rcx)
jne 0x847c
jmp 0x849d
shlq $0x4, %rcx
movq 0x10(%rdx,%rcx), %rsi
movq %r13, %rdi
xorl %edx, %edx
callq 0x4719
movq 0x10(%r13), %rax
shlq $0x10, %rax
movzwl 0xc(%r13), %ecx
orq %rax, %rcx
movq %rcx, 0x18(%rbx)
movl 0x14(%rbx), %eax
incl %eax
movl %eax, 0x14(%rbx)
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
leaq 0x14(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %rbp, %r9
callq *%r14
testl %eax, %eax
js 0x8537
movq 0x10(%r13), %rcx
shlq $0x10, %rcx
movzwl 0xc(%r13), %edx
orq %rcx, %rdx
movq %rdx, 0x18(%rbx)
movl 0x14(%rsp), %esi
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl 0x4(%rbx), %esi
jne 0x8540
movl 0x10(%rsp), %esi
cmpl 0xc(%rbx), %esi
jge 0x8540
movl 0xc(%rsp), %ecx
cmpl 0x8(%rbx), %ecx
jle 0x842c
jmp 0x8545
movq 0x18(%rbx), %rsi
testq %rsi, %rsi
je 0x8514
movq %r13, %rdi
xorl %edx, %edx
callq 0x4719
movq $0x0, 0x18(%rbx)
leaq 0x14(%rsp), %rcx
leaq 0x10(%rsp), %r8
leaq 0xc(%rsp), %r9
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq *%r14
movl %eax, %ecx
testl %eax, %eax
jns 0x8545
jmp 0x8540
movl %eax, %ecx
jmp 0x8540
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
orb $0x2, (%rbx)
movl %ecx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq