// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0xb79f
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xb79f
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb9d2
movq -0x18(%rbp), %rax
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xb817
movq -0x18(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0xb7d7
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
xorl %edx, %edx
callq 0x5db0
movq -0x18(%rbp), %rax
movq $0x0, 0x18(%rax)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x38(%rbp), %rcx
leaq -0x3c(%rbp), %r8
leaq -0x40(%rbp), %r9
callq *%rax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jge 0xb80c
movq -0x18(%rbp), %rax
movl (%rax), %ecx
andl $-0x3, %ecx
orl $0x2, %ecx
movl %ecx, (%rax)
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xb9d2
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0xb82e
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xb9d2
jmp 0xb830
movq -0x18(%rbp), %rax
cmpq $0x0, 0x18(%rax)
je 0xb864
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x18(%rbp), %rdx
movslq 0x14(%rdx), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
jb 0xb927
movq -0x18(%rbp), %rax
movl 0x14(%rax), %eax
movq -0x18(%rbp), %rcx
movl 0x10(%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jne 0xb885
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
jmp 0xb9be
movq -0x18(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jl 0xb8cb
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x14(%rcx), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x20(%rcx), %rcx
movq -0x18(%rbp), %rdx
movl 0x14(%rdx), %edx
addl $0x1, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
je 0xb91a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x14(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rsi
xorl %edx, %edx
callq 0x5db0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
shlq $0x10, %rcx
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cltq
orq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x38(%rbp), %rcx
leaq -0x3c(%rbp), %r8
leaq -0x40(%rbp), %r9
callq *%rax
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
jl 0xb9b7
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
shlq $0x10, %rcx
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cltq
orq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x38(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jne 0xb98a
movl -0x3c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jl 0xb993
movl $0xffffffff, -0x34(%rbp) # imm = 0xFFFFFFFF
jmp 0xb9be
movl -0x40(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x8(%rcx), %eax
jle 0xb9b3
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
cmpl -0x3c(%rbp), %eax
jle 0xb9b3
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0xb9d2
jmp 0xb9b5
jmp 0xb9b9
jmp 0xb9be
jmp 0xb830
movq -0x18(%rbp), %rax
movl (%rax), %ecx
andl $-0x3, %ecx
orl $0x2, %ecx
movl %ecx, (%rax)
movl -0x34(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax,%rax)