// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/hts.c
// Function: hts_itr_next
int hts_itr_next(BGZF *fp, hts_itr_t *iter, void *r, void *data)
{
    int ret, tid;
    hts_pos_t 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) {
                hts_log_error("Failed to seek to offset %"PRIu64"%s%s",
                              iter->curr_off,
                              errno ? ": " : "", strerror(errno));
                return -2;
            }
            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;
    }
    // A NULL iter->off should always be accompanied by iter->finished.
    assert(iter->off != NULL);
    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) {
                    hts_log_error("Failed to seek to offset %"PRIu64"%s%s",
                                  iter->off[iter->i+1].u,
                                  errno ? ": " : "", strerror(errno));
                    return -2;
                }
                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, %eax       # imm = 0xFFFFFFFF
testq %rsi, %rsi
je 0x1adc4
movq %rcx, %r15
movq %rsi, %rbx
movl (%rsi), %ecx
testb $0x2, %cl
jne 0x1adc4
movq %rdx, %r14
movq %rdi, %r12
testb $0x1, %cl
jne 0x1acf8
cmpq $0x0, 0x60(%rbx)
je 0x1add3
leaq 0x10(%rsp), %rbp
leaq 0x8(%rsp), %r13
movq 0x50(%rbx), %rax
testq %rax, %rax
je 0x1ac27
movq 0x60(%rbx), %rcx
movslq 0xc(%rbx), %rdx
leaq (%rdx,%rdx,2), %rdx
cmpq 0x8(%rcx,%rdx,8), %rax
jb 0x1ac8a
movl 0x8(%rbx), %ecx
movl 0xc(%rbx), %eax
decl %ecx
cmpl %ecx, %eax
je 0x1ad5f
testl %eax, %eax
js 0x1ac4f
movq 0x60(%rbx), %rcx
leaq (%rax,%rax,2), %rdx
movq 0x8(%rcx,%rdx,8), %rsi
cmpq 0x18(%rcx,%rdx,8), %rsi
je 0x1ac87
movq 0x60(%rbx), %rcx
cltq
leaq (%rax,%rax,2), %rax
movq 0x18(%rcx,%rax,8), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0xd9a9
testq %rax, %rax
js 0x1ad6b
movq 0x18(%r12), %rax
shlq $0x10, %rax
movzwl 0x10(%r12), %ecx
orq %rax, %rcx
movq %rcx, 0x50(%rbx)
incl 0xc(%rbx)
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
leaq 0x4(%rsp), %rcx
movq %rbp, %r8
movq %r13, %r9
callq *0x68(%rbx)
testl %eax, %eax
js 0x1ad5b
movq 0x18(%r12), %rcx
shlq $0x10, %rcx
movzwl 0x10(%r12), %edx
orq %rcx, %rdx
movq %rdx, 0x50(%rbx)
movl 0x4(%rsp), %edx
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
cmpl 0x4(%rbx), %edx
jne 0x1ad64
movq 0x10(%rsp), %rsi
cmpq 0x20(%rbx), %rsi
jge 0x1ad64
movq 0x8(%rsp), %rcx
cmpq 0x18(%rbx), %rcx
jle 0x1ac0b
movl %edx, 0x30(%rbx)
movq %rsi, 0x40(%rbx)
jmp 0x1ad4f
movq 0x50(%rbx), %rsi
testq %rsi, %rsi
je 0x1ad18
movq %r12, %rdi
xorl %edx, %edx
callq 0xd9a9
testq %rax, %rax
js 0x1ad55
movq $0x0, 0x50(%rbx)
leaq 0x4(%rsp), %rcx
leaq 0x10(%rsp), %r8
leaq 0x8(%rsp), %r9
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
callq *0x68(%rbx)
testl %eax, %eax
jns 0x1ad3a
orb $0x2, (%rbx)
movl 0x4(%rsp), %ecx
movl %ecx, 0x30(%rbx)
movq 0x10(%rsp), %rcx
movq %rcx, 0x40(%rbx)
movq 0x8(%rsp), %rcx
movq %rcx, 0x48(%rbx)
jmp 0x1adc4
movq 0x50(%rbx), %rbx
jmp 0x1ad7c
movl %eax, %ecx
jmp 0x1ad64
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
orb $0x2, (%rbx)
movl %ecx, %eax
jmp 0x1adc4
movq 0x60(%rbx), %rax
movslq 0xc(%rbx), %rcx
leaq (%rcx,%rcx,2), %rcx
movq 0x18(%rax,%rcx,8), %rbx
callq 0x4050
movl (%rax), %edi
testl %edi, %edi
leaq 0x7df41(%rip), %rax     # 0x98ccd
leaq 0x7e0e3(%rip), %r14     # 0x98e76
cmoveq %rax, %r14
callq 0x4150
leaq 0x7ea08(%rip), %rsi     # 0x997ab
leaq 0x7ea0e(%rip), %rdx     # 0x997b8
movl $0x1, %edi
movq %rbx, %rcx
movq %r14, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x14378
movl $0xfffffffe, %eax       # imm = 0xFFFFFFFE
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x7e9ff(%rip), %rdi     # 0x997d9
leaq 0x7e51f(%rip), %rsi     # 0x99300
leaq 0x7ea03(%rip), %rcx     # 0x997eb
movl $0x1094, %edx           # imm = 0x1094
callq 0x42f0