// File: /workspace/github_cpp_makefile_star2_O1/karel-brinda[P]ococo/ext/htslib/hts.c
// Function: hts_itr_next
int hts_itr_next(BGZF *fp, hts_itr_t *iter, void *r, void *data)
{
    int ret, tid, beg, end;
    if (iter == NULL || iter->finished) return -1;
    if (iter->read_rest) {
        if (iter->curr_off) { // seek to the start
            if (bgzf_seek(fp, iter->curr_off, SEEK_SET) < 0) return -1;
            iter->curr_off = 0; // only seek once
        }
        ret = iter->readrec(fp, data, r, &tid, &beg, &end);
        if (ret < 0) iter->finished = 1;
        iter->curr_tid = tid;
        iter->curr_beg = beg;
        iter->curr_end = end;
        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
                if (bgzf_seek(fp, iter->off[iter->i+1].u, SEEK_SET) < 0) return -1;
                iter->curr_off = bgzf_tell(fp);
            }
            ++iter->i;
        }
        if ((ret = iter->readrec(fp, data, 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) {
                iter->curr_tid = tid;
                iter->curr_beg = beg;
                iter->curr_end = end;
                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
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rsi, %rsi
je 0x132a9
movq %rsi, %rbx
movl (%rsi), %eax
testb $0x2, %al
jne 0x132a9
movq %rcx, %r15
movq %rdx, %r14
movq %rdi, %r12
testb $0x1, %al
jne 0x13240
cmpq $0x0, 0x30(%rbx)
je 0x132a9
leaq 0xc(%rsp), %r13
movq 0x28(%rbx), %rax
testq %rax, %rax
je 0x13171
movq 0x30(%rbx), %rcx
movslq 0x14(%rbx), %rdx
shlq $0x4, %rdx
cmpq 0x8(%rcx,%rdx), %rax
jb 0x131d7
movl 0x10(%rbx), %ecx
movl 0x14(%rbx), %eax
decl %ecx
cmpl %ecx, %eax
je 0x1329f
testl %eax, %eax
js 0x1319c
movq 0x30(%rbx), %rcx
movq %rax, %rdx
shlq $0x4, %rdx
movq 0x8(%rcx,%rdx), %rsi
cmpq 0x10(%rcx,%rdx), %rsi
je 0x131d4
movq 0x30(%rbx), %rcx
cltq
shlq $0x4, %rax
movq 0x10(%rcx,%rax), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x455a9
testq %rax, %rax
js 0x132ba
movq 0x10(%r12), %rax
shlq $0x10, %rax
movzwl 0xc(%r12), %ecx
orq %rax, %rcx
movq %rcx, 0x28(%rbx)
incl 0x14(%rbx)
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
leaq 0x14(%rsp), %rcx
leaq 0x10(%rsp), %r8
movq %r13, %r9
callq *0x38(%rbx)
movl %eax, %ebp
testl %eax, %eax
js 0x1329b
movq 0x10(%r12), %rax
shlq $0x10, %rax
movzwl 0xc(%r12), %ecx
orq %rax, %rcx
movq %rcx, 0x28(%rbx)
movl 0x14(%rsp), %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl 0x4(%rbx), %ecx
jne 0x132a4
movl 0x10(%rsp), %edx
cmpl 0xc(%rbx), %edx
jge 0x132a4
movl 0xc(%rsp), %eax
cmpl 0x8(%rbx), %eax
jle 0x13155
movl %ecx, 0x18(%rbx)
movl %edx, 0x1c(%rbx)
jmp 0x13296
movq 0x28(%rbx), %rsi
testq %rsi, %rsi
je 0x13260
movq %r12, %rdi
xorl %edx, %edx
callq 0x455a9
testq %rax, %rax
js 0x132a9
movq $0x0, 0x28(%rbx)
leaq 0x14(%rsp), %rcx
leaq 0x10(%rsp), %r8
leaq 0xc(%rsp), %r9
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq *0x38(%rbx)
movl %eax, %ebp
testl %eax, %eax
jns 0x13284
orb $0x2, (%rbx)
movl 0x14(%rsp), %eax
movl %eax, 0x18(%rbx)
movl 0x10(%rsp), %eax
movl %eax, 0x1c(%rbx)
movl 0xc(%rsp), %eax
movl %eax, 0x20(%rbx)
jmp 0x132a9
movl %ebp, %eax
jmp 0x132a4
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
orb $0x2, (%rbx)
movl %eax, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x132a9