// File: /workspace/github_c_makefile_star2_O1/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 %r8, %r15
movq %rcx, %r14
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, %r13
testq %rsi, %rsi
je 0x81f1
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testb $0x2, (%rbx)
jne 0x832b
testb $0x1, (%rbx)
jne 0x82d8
cmpq $0x0, 0x20(%rbx)
je 0x8316
leaq 0xc(%rsp), %rbp
movq 0x18(%rbx), %rax
testq %rax, %rax
je 0x8226
movq 0x20(%rbx), %rcx
movslq 0x14(%rbx), %rdx
shlq $0x4, %rdx
cmpq 0x8(%rcx,%rdx), %rax
jb 0x8281
movl 0x10(%rbx), %ecx
movl 0x14(%rbx), %eax
decl %ecx
cmpl %ecx, %eax
je 0x8321
testl %eax, %eax
js 0x8251
movq 0x20(%rbx), %rcx
movq %rax, %rdx
shlq $0x4, %rdx
movq 0x8(%rcx,%rdx), %rsi
cmpq 0x10(%rcx,%rdx), %rsi
je 0x827e
movq 0x20(%rbx), %rcx
cltq
shlq $0x4, %rax
movq 0x10(%rcx,%rax), %rsi
movq %r13, %rdi
xorl %edx, %edx
callq 0x4669
movq 0x10(%r13), %rax
shlq $0x10, %rax
movzwl 0xc(%r13), %ecx
orq %rax, %rcx
movq %rcx, 0x18(%rbx)
incl 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 0x831d
movq 0x10(%r13), %rcx
shlq $0x10, %rcx
movzwl 0xc(%r13), %edx
orq %rcx, %rdx
movq %rdx, 0x18(%rbx)
movl 0x14(%rsp), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl 0x4(%rbx), %edx
jne 0x8326
movl 0x10(%rsp), %edx
cmpl 0xc(%rbx), %edx
jge 0x8326
movl 0xc(%rsp), %ecx
cmpl 0x8(%rbx), %ecx
jle 0x820a
jmp 0x832b
movq 0x18(%rbx), %rsi
testq %rsi, %rsi
je 0x82f3
movq %r13, %rdi
xorl %edx, %edx
callq 0x4669
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 0x832b
jmp 0x8326
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x832b
movl %eax, %ecx
jmp 0x8326
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