// File: /workspace/github_c_makefile_star2_O0/icebert[P]pblat/htslib/hts.c
// Function: hts_itr_query
hts_itr_t *hts_itr_query(const hts_idx_t *idx, int tid, int beg, int end, hts_readrec_func *readrec)
{
    int i, n_off, l, bin;
    hts_pair64_t *off;
    khint_t k;
    bidx_t *bidx;
    uint64_t min_off;
    hts_itr_t *iter = 0;
    if (tid < 0) {
        int finished0 = 0;
        uint64_t off0 = (uint64_t)-1;
        khint_t k;
        switch (tid) {
        case HTS_IDX_START:
            // Find the smallest offset, note that sequence ids may not be ordered sequentially
            for (i=0; i<idx->n; i++)
            {
                bidx = idx->bidx[i];
                k = kh_get(bin, bidx, META_BIN(idx));
                if (k == kh_end(bidx)) continue;
                if ( off0 > kh_val(bidx, k).list[0].u ) off0 = kh_val(bidx, k).list[0].u;
            }
            if ( off0==(uint64_t)-1 && idx->n_no_coor ) off0 = 0; // only no-coor reads in this bam
            break;

        case HTS_IDX_NOCOOR:
            if ( idx->n>0 )
            {
                bidx = idx->bidx[idx->n - 1];
                k = kh_get(bin, bidx, META_BIN(idx));
                if (k != kh_end(bidx)) off0 = kh_val(bidx, k).list[0].v;
            }
            if ( off0==(uint64_t)-1 && idx->n_no_coor ) off0 = 0; // only no-coor reads in this bam
            break;

        case HTS_IDX_REST:
            off0 = 0;
            break;

        case HTS_IDX_NONE:
            finished0 = 1;
            off0 = 0;
            break;

        default:
            return 0;
        }
        if (off0 != (uint64_t)-1) {
            iter = (hts_itr_t*)calloc(1, sizeof(hts_itr_t));
            iter->read_rest = 1;
            iter->finished = finished0;
            iter->curr_off = off0;
            iter->readrec = readrec;
            return iter;
        } else return 0;
    }

    if (beg < 0) beg = 0;
    if (end < beg) return 0;
    if (tid >= idx->n || (bidx = idx->bidx[tid]) == NULL) return 0;

    iter = (hts_itr_t*)calloc(1, sizeof(hts_itr_t));
    iter->tid = tid, iter->beg = beg, iter->end = end; iter->i = -1;
    iter->readrec = readrec;

    // compute min_off
    bin = hts_bin_first(idx->n_lvls) + (beg>>idx->min_shift);
    do {
        int first;
        k = kh_get(bin, bidx, bin);
        if (k != kh_end(bidx)) break;
        first = (hts_bin_parent(bin)<<3) + 1;
        if (bin > first) --bin;
        else bin = hts_bin_parent(bin);
    } while (bin);
    if (bin == 0) k = kh_get(bin, bidx, bin);
    min_off = k != kh_end(bidx)? kh_val(bidx, k).loff : 0;
    // retrieve bins
    reg2bins(beg, end, iter, idx->min_shift, idx->n_lvls);
    for (i = n_off = 0; i < iter->bins.n; ++i)
        if ((k = kh_get(bin, bidx, iter->bins.a[i])) != kh_end(bidx))
            n_off += kh_value(bidx, k).n;
    if (n_off == 0) return iter;
    off = (hts_pair64_t*)calloc(n_off, sizeof(hts_pair64_t));
    for (i = n_off = 0; i < iter->bins.n; ++i) {
        if ((k = kh_get(bin, bidx, iter->bins.a[i])) != kh_end(bidx)) {
            int j;
            bins_t *p = &kh_value(bidx, k);
            for (j = 0; j < p->n; ++j)
                if (p->list[j].v > min_off) off[n_off++] = p->list[j];
        }
    }
    if (n_off == 0) {
        free(off); return iter;
    }
    ks_introsort(_off, n_off, off);
    // resolve completely contained adjacent blocks
    for (i = 1, l = 0; i < n_off; ++i)
        if (off[l].v < off[i].v) off[++l] = off[i];
    n_off = l + 1;
    // resolve overlaps between adjacent blocks; this may happen due to the merge in indexing
    for (i = 1; i < n_off; ++i)
        if (off[i-1].v >= off[i].u) off[i-1].v = off[i].u;
    // merge adjacent blocks
    for (i = 1, l = 0; i < n_off; ++i) {
        if (off[l].v>>16 == off[i].u>>16) off[l].v = off[i].v;
        else off[++l] = off[i];
    }
    n_off = l + 1;
    iter->n_off = n_off; iter->off = off;
    return iter;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movq $0x0, -0x60(%rbp)
cmpl $0x0, -0x14(%rbp)
jge 0x76440
movl $0x0, -0x64(%rbp)
movq $-0x1, -0x70(%rbp)
movl -0x14(%rbp), %eax
addl $0x5, %eax
movl %eax, %ecx
movq %rcx, -0x90(%rbp)
subl $0x3, %eax
ja 0x763c4
movq -0x90(%rbp), %rax
leaq 0x6be71(%rip), %rcx     # 0xe20d4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x76306
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %esi
addl $0x1, %esi
callq 0x760a0
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpl (%rcx), %eax
jne 0x762ba
jmp 0x762f8
movq -0x70(%rbp), %rax
movq -0x50(%rbp), %rcx
movq 0x20(%rcx), %rcx
movl -0x74(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
cmpq (%rcx), %rax
jbe 0x762f6
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x74(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq %rax, -0x70(%rbp)
jmp 0x762f8
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x76273
cmpq $-0x1, -0x70(%rbp)
jne 0x76320
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x76320
movq $0x0, -0x70(%rbp)
jmp 0x763d1
movq -0x10(%rbp), %rax
cmpl $0x0, 0x14(%rax)
jle 0x7638d
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rcx
movl 0x14(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %esi
addl $0x1, %esi
callq 0x760a0
movl %eax, -0x74(%rbp)
movl -0x74(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpl (%rcx), %eax
je 0x7638b
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x74(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq 0x8(%rax), %rax
movq %rax, -0x70(%rbp)
jmp 0x7638d
cmpq $-0x1, -0x70(%rbp)
jne 0x763a7
movq -0x10(%rbp), %rax
cmpq $0x0, 0x20(%rax)
je 0x763a7
movq $0x0, -0x70(%rbp)
jmp 0x763d1
movq $0x0, -0x70(%rbp)
jmp 0x763d1
movl $0x1, -0x64(%rbp)
movq $0x0, -0x70(%rbp)
jmp 0x763d1
movq $0x0, -0x8(%rbp)
jmp 0x76958
cmpq $-0x1, -0x70(%rbp)
je 0x76433
movl $0x1, %edi
movl $0x50, %esi
callq 0x6460
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movl (%rax), %ecx
andl $-0x2, %ecx
orl $0x1, %ecx
movl %ecx, (%rax)
movl -0x64(%rbp), %edx
movq -0x60(%rbp), %rax
movl (%rax), %ecx
andl $0x1, %edx
shll %edx
andl $-0x3, %ecx
orl %edx, %ecx
movl %ecx, (%rax)
movq -0x70(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x28(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x76958
movq $0x0, -0x8(%rbp)
jmp 0x76958
cmpl $0x0, -0x18(%rbp)
jge 0x7644d
movl $0x0, -0x18(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x76462
movq $0x0, -0x8(%rbp)
jmp 0x76958
movl -0x14(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x76488
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x50(%rbp)
cmpq $0x0, %rax
jne 0x76495
movq $0x0, -0x8(%rbp)
jmp 0x76958
movl $0x1, %edi
movl $0x50, %esi
callq 0x6460
movq %rax, -0x60(%rbp)
movl -0x14(%rbp), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x4(%rax)
movl -0x18(%rbp), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x1c(%rbp), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x60(%rbp), %rax
movl $0xffffffff, 0x14(%rax) # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x38(%rax)
movq -0x10(%rbp), %rax
movl 0x8(%rax), %ecx
shll %ecx
movq -0x10(%rbp), %rax
addl 0x8(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl $0x7, %ecx
cltd
idivl %ecx
movl -0x18(%rbp), %edx
movq -0x10(%rbp), %rcx
movl 0x4(%rcx), %ecx
sarl %cl, %edx
movl %edx, %ecx
addl %ecx, %eax
movl %eax, -0x38(%rbp)
movq -0x50(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x760a0
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpl (%rcx), %eax
je 0x7652e
jmp 0x76567
movl -0x38(%rbp), %eax
subl $0x1, %eax
sarl $0x3, %eax
shll $0x3, %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x78(%rbp), %eax
jle 0x76553
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x7655f
movl -0x38(%rbp), %eax
subl $0x1, %eax
sarl $0x3, %eax
movl %eax, -0x38(%rbp)
jmp 0x76561
cmpl $0x0, -0x38(%rbp)
jne 0x76512
cmpl $0x0, -0x38(%rbp)
jne 0x7657c
movq -0x50(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0x760a0
movl %eax, -0x44(%rbp)
movl -0x44(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpl (%rcx), %eax
je 0x765a6
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x44(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x98(%rbp)
jmp 0x765b1
xorl %eax, %eax
movq %rax, -0x98(%rbp)
jmp 0x765b1
movq -0x98(%rbp), %rax
movq %rax, -0x58(%rbp)
movslq -0x18(%rbp), %rdi
movslq -0x1c(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x10(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %r8d
callq 0x76970
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x60(%rbp), %rcx
cmpl 0x40(%rcx), %eax
jge 0x76641
movq -0x50(%rbp), %rdi
movq -0x60(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0x760a0
movl %eax, -0x44(%rbp)
movq -0x50(%rbp), %rcx
cmpl (%rcx), %eax
je 0x76634
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x44(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x4(%rax), %eax
addl -0x30(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x76636
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x765ea
cmpl $0x0, -0x30(%rbp)
jne 0x76654
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x76958
movslq -0x30(%rbp), %rdi
movl $0x10, %esi
callq 0x6460
movq %rax, -0x40(%rbp)
movl $0x0, -0x30(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x60(%rbp), %rcx
cmpl 0x40(%rcx), %eax
jge 0x76756
movq -0x50(%rbp), %rdi
movq -0x60(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x2c(%rbp), %rcx
movl (%rax,%rcx,4), %esi
callq 0x760a0
movl %eax, -0x44(%rbp)
movq -0x50(%rbp), %rcx
cmpl (%rcx), %eax
je 0x76746
movq -0x50(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x44(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
movq -0x88(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x76744
movq -0x88(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x7c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
cmpq -0x58(%rbp), %rax
jbe 0x76737
movq -0x40(%rbp), %rax
movl -0x30(%rbp), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, -0x30(%rbp)
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x88(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x7c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0x76739
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x766cb
jmp 0x76746
jmp 0x76748
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x76674
cmpl $0x0, -0x30(%rbp)
jne 0x76772
movq -0x40(%rbp), %rdi
callq 0x6880
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x76958
movslq -0x30(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x73950
movl $0x1, -0x2c(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x767fe
movq -0x40(%rbp), %rax
movslq -0x34(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x40(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
jae 0x767f1
movq -0x40(%rbp), %rax
movl -0x34(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x34(%rbp)
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x40(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0x767f3
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x7678d
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl $0x1, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x76879
movq -0x40(%rbp), %rax
movl -0x2c(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq -0x40(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jb 0x7686c
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq (%rax), %rcx
movq -0x40(%rbp), %rax
movl -0x2c(%rbp), %edx
subl $0x1, %edx
movslq %edx, %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0x7686e
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x7680e
movl $0x1, -0x2c(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x30(%rbp), %eax
jge 0x76931
movq -0x40(%rbp), %rax
movslq -0x34(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
shrq $0x10, %rax
movq -0x40(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rcx
shrq $0x10, %rcx
cmpq %rcx, %rax
jne 0x768ed
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rcx
movq -0x40(%rbp), %rax
movslq -0x34(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0x76921
movq -0x40(%rbp), %rax
movl -0x34(%rbp), %ecx
addl $0x1, %ecx
movl %ecx, -0x34(%rbp)
movslq %ecx, %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq -0x40(%rbp), %rcx
movslq -0x2c(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0x76923
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x76887
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x40(%rbp), %rcx
movq -0x60(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x60(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)