// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/hts.c
// Function: hts_itr_multi_bam
int hts_itr_multi_bam(const hts_idx_t *idx, hts_itr_t *iter)
{
    int i, j, bin;
    khint_t k;
    bidx_t *bidx;
    uint64_t min_off, max_off, t_off = (uint64_t)-1;
    int tid;
    hts_pos_t beg, end, idx_maxpos;
    hts_reglist_t *curr_reg;
    uint32_t unmapped = 0, rel_off;

    if (!idx || !iter || !iter->multi)
        return -1;

    iter->i = -1;
    for (i=0; i<iter->n_reg; i++) {

        curr_reg = &iter->reg_list[i];
        tid = curr_reg->tid;

        if (tid < 0) {
            t_off = hts_itr_off(idx, tid);
            if (t_off != (uint64_t)-1) {
                switch (tid) {
                case HTS_IDX_NONE:
                    iter->finished = 1;
                    // fall through
                case HTS_IDX_START:
                case HTS_IDX_REST:
                    iter->curr_off = t_off;
                    iter->n_reg = 0;
                    iter->reg_list = NULL;
                    iter->read_rest = 1;
                    return 0;
                case HTS_IDX_NOCOOR:
                    iter->nocoor = 1;
                    iter->nocoor_off = t_off;
                }
            }
        } else {
            if (tid >= idx->n || (bidx = idx->bidx[tid]) == NULL || !kh_size(bidx))
                continue;

            k = kh_get(bin, bidx, META_BIN(idx));
            if (k != kh_end(bidx))
                unmapped = kh_val(bidx, k).list[1].v;
            else
                unmapped = 1;

            idx_maxpos = hts_idx_maxpos(idx);

            for(j=0; j<curr_reg->count; j++) {
                hts_pair32_t *curr_intv = &curr_reg->intervals[j];
                if (curr_intv->end < curr_intv->beg)
                    continue;

                beg = curr_intv->beg;
                end = curr_intv->end;
                if (beg >= idx_maxpos)
                    continue;
                rel_off = beg>>idx->min_shift;

                /* Compute 'min_off' by searching the lowest level bin containing 'beg'.
                       If the computed bin is not in the index, try the next bin to the
                       left, belonging to the same parent. If it is the first sibling bin,
                       try the parent bin. */
                bin = hts_bin_first(idx->n_lvls) + rel_off;
                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;
                // min_off can be calculated more accurately if the
                // linear index is available
                if (idx->lidx[tid].offset
                    && rel_off < idx->lidx[tid].n) {
                    if (min_off < idx->lidx[tid].offset[rel_off])
                        min_off = idx->lidx[tid].offset[rel_off];
                    if (unmapped) {
                        int tmp_off;
                        for (tmp_off = rel_off-1; tmp_off >= 0; tmp_off--) {
                            if (idx->lidx[tid].offset[tmp_off] < min_off) {
                                min_off = idx->lidx[tid].offset[tmp_off];
                                break;
                            }
                        }

                        if (k != kh_end(bidx) && (min_off < kh_val(bidx, k).loff || tmp_off < 0))
                            min_off = kh_val(bidx, k).loff;
                    }
                } else if (unmapped) { //CSI index
                    if (k != kh_end(bidx))
                        min_off = kh_val(bidx, k).loff;
                }

                // compute max_off: a virtual offset from a bin to the right of end
                // First check if end lies within the range of the index (it
                // won't if it's HTS_POS_MAX)
                if (end <= idx_maxpos) {
                    bin = hts_bin_first(idx->n_lvls) + ((end-1) >> idx->min_shift) + 1;
                    if (bin >= idx->n_bins) bin = 0;
                    while (1) {
                        // search for an extant bin by moving right, but moving up to the
                        // parent whenever we get to a first child (which also covers falling
                        // off the RHS, which wraps around and immediately goes up to bin 0)
                        while (bin % 8 == 1) bin = hts_bin_parent(bin);
                        if (bin == 0) { max_off = UINT64_MAX; break; }
                        k = kh_get(bin, bidx, bin);
                        if (k != kh_end(bidx) && kh_val(bidx, k).n > 0) {
                            max_off = kh_val(bidx, k).list[0].u;
                            break;
                        }
                        bin++;
                    }
                } else {
                    // Searching to end of reference
                    max_off = UINT64_MAX;
                }

                //convert coordinates to file offsets
                if (reg2intervals(iter, idx, tid, beg, end, j,
                                  min_off, max_off,
                                  idx->min_shift, idx->n_lvls) < 0) {
                    return -1;
                }
            }
        }
    }

    if (iter->n_off > 1)
        ks_introsort(_off_max, iter->n_off, iter->off);

    if(!iter->n_off && !iter->nocoor)
        iter->finished = 1;

    return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %rbx
subq $0xb8, %rsp
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movq $-0x1, -0x50(%rbp)
movl $0x0, -0x7c(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x22242
cmpq $0x0, -0x20(%rbp)
je 0x22242
movq -0x20(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x2224e
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x2287f
movq -0x20(%rbp), %rax
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
movl $0x0, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x20(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x22830
movq -0x20(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x24(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x54(%rbp)
cmpl $0x0, -0x54(%rbp)
jge 0x2234f
movq -0x18(%rbp), %rdi
movl -0x54(%rbp), %esi
callq 0x20c20
movq %rax, -0x50(%rbp)
cmpq $-0x1, -0x50(%rbp)
je 0x2234a
movl -0x54(%rbp), %eax
movl %eax, -0x94(%rbp)
subl $-0x5, %eax
je 0x222e3
jmp 0x222c6
movl -0x94(%rbp), %eax
addl $0x4, %eax
subl $0x2, %eax
jb 0x222f1
jmp 0x222d6
movl -0x94(%rbp), %eax
subl $-0x2, %eax
je 0x2232e
jmp 0x22348
movq -0x20(%rbp), %rax
movl (%rax), %ecx
andl $-0x3, %ecx
orl $0x2, %ecx
movl %ecx, (%rax)
movq -0x50(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x20(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x28(%rax)
movq -0x20(%rbp), %rax
movl (%rax), %ecx
andl $-0x2, %ecx
orl $0x1, %ecx
movl %ecx, (%rax)
movl $0x0, -0xc(%rbp)
jmp 0x2287f
movq -0x20(%rbp), %rax
movl (%rax), %ecx
andl $-0x9, %ecx
orl $0x8, %ecx
movl %ecx, (%rax)
movq -0x50(%rbp), %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x58(%rax)
jmp 0x2234a
jmp 0x22820
movl -0x54(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jge 0x2237f
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x54(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
je 0x2237f
movq -0x38(%rbp), %rax
cmpl $0x0, 0x4(%rax)
jne 0x22384
jmp 0x22822
movq -0x38(%rbp), %rdi
movq -0x18(%rbp), %rax
movl 0xc(%rax), %esi
addl $0x1, %esi
callq 0x20ab0
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
je 0x223c4
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x30(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq 0x18(%rax), %rax
movl %eax, -0x7c(%rbp)
jmp 0x223cb
movl $0x1, -0x7c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x1f8f0
movq %rax, -0x70(%rbp)
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x78(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jae 0x2281e
movq -0x78(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x28(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x88(%rbp), %rcx
cmpq (%rcx), %rax
jge 0x22425
jmp 0x22810
movq -0x88(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x68(%rbp)
movq -0x60(%rbp), %rax
cmpq -0x70(%rbp), %rax
jl 0x22451
jmp 0x22810
movq -0x60(%rbp), %rax
movq -0x18(%rbp), %rcx
movl 0x4(%rcx), %ecx
sarq %cl, %rax
movl %eax, -0x80(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
shll %ecx
movq -0x18(%rbp), %rax
addl 0x8(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl $0x7, %ecx
cltd
idivl %ecx
addl -0x80(%rbp), %eax
movl %eax, -0x2c(%rbp)
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x20ab0
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
je 0x224a6
jmp 0x224e5
movl -0x2c(%rbp), %eax
subl $0x1, %eax
sarl $0x3, %eax
shll $0x3, %eax
addl $0x1, %eax
movl %eax, -0x8c(%rbp)
movl -0x2c(%rbp), %eax
cmpl -0x8c(%rbp), %eax
jle 0x224d1
movl -0x2c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x224dd
movl -0x2c(%rbp), %eax
subl $0x1, %eax
sarl $0x3, %eax
movl %eax, -0x2c(%rbp)
jmp 0x224df
cmpl $0x0, -0x2c(%rbp)
jne 0x2248a
cmpl $0x0, -0x2c(%rbp)
jne 0x224fa
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x20ab0
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
je 0x22524
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x30(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0xa0(%rbp)
jmp 0x2252f
xorl %eax, %eax
movq %rax, -0xa0(%rbp)
jmp 0x2252f
movq -0xa0(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x54(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x10(%rax)
je 0x2268d
movl -0x80(%rbp), %eax
movq -0x18(%rbp), %rcx
movq 0x30(%rcx), %rcx
movslq -0x54(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpq (%rcx), %rax
jge 0x2268d
movq -0x40(%rbp), %rax
movq -0x18(%rbp), %rcx
movq 0x30(%rcx), %rcx
movslq -0x54(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
movq 0x10(%rcx), %rcx
movl -0x80(%rbp), %edx
cmpq (%rcx,%rdx,8), %rax
jae 0x225bd
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x54(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl -0x80(%rbp), %ecx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
cmpl $0x0, -0x7c(%rbp)
je 0x2268b
movl -0x80(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x90(%rbp)
cmpl $0x0, -0x90(%rbp)
jl 0x2263f
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x54(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movslq -0x90(%rbp), %rcx
movq (%rax,%rcx,8), %rax
cmpq -0x40(%rbp), %rax
jae 0x2262c
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x54(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movslq -0x90(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x40(%rbp)
jmp 0x2263f
jmp 0x2262e
movl -0x90(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x90(%rbp)
jmp 0x225d3
movl -0x30(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
je 0x22689
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movq 0x20(%rcx), %rcx
movl -0x30(%rbp), %edx
imulq $0x18, %rdx, %rdx
addq %rdx, %rcx
cmpq 0x8(%rcx), %rax
jb 0x2266f
cmpl $0x0, -0x90(%rbp)
jge 0x22689
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x30(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x2268b
jmp 0x226bc
cmpl $0x0, -0x7c(%rbp)
je 0x226ba
movl -0x30(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
je 0x226b8
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x30(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x226ba
jmp 0x226bc
movq -0x68(%rbp), %rax
cmpq -0x70(%rbp), %rax
jg 0x227b3
movq -0x18(%rbp), %rax
movl 0x8(%rax), %ecx
shll %ecx
movq -0x18(%rbp), %rax
addl 0x8(%rax), %ecx
movl $0x1, %eax
shll %cl, %eax
subl $0x1, %eax
movl $0x7, %ecx
cltd
idivl %ecx
cltq
movq -0x68(%rbp), %rdx
subq $0x1, %rdx
movq -0x18(%rbp), %rcx
movl 0x4(%rcx), %ecx
sarq %cl, %rdx
movq %rdx, %rcx
addq %rcx, %rax
addq $0x1, %rax
movl %eax, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jl 0x22720
movl $0x0, -0x2c(%rbp)
jmp 0x22722
jmp 0x22724
movl -0x2c(%rbp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
cmpl $0x1, %edx
jne 0x22742
movl -0x2c(%rbp), %eax
subl $0x1, %eax
sarl $0x3, %eax
movl %eax, -0x2c(%rbp)
jmp 0x22724
cmpl $0x0, -0x2c(%rbp)
jne 0x22752
movq $-0x1, -0x48(%rbp)
jmp 0x227b1
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %esi
callq 0x20ab0
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
je 0x227a3
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x30(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x4(%rax)
jle 0x227a3
movq -0x38(%rbp), %rax
movq 0x20(%rax), %rax
movl -0x30(%rbp), %ecx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movq (%rax), %rax
movq %rax, -0x48(%rbp)
jmp 0x227b1
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x22722
jmp 0x227bb
movq $-0x1, -0x48(%rbp)
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x54(%rbp), %edx
movq -0x60(%rbp), %rcx
movq -0x68(%rbp), %r8
movl -0x28(%rbp), %r9d
movq -0x40(%rbp), %rbx
movq -0x48(%rbp), %r11
movq -0x18(%rbp), %rax
movl 0x4(%rax), %r10d
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq %rbx, (%rsp)
movq %r11, 0x8(%rsp)
movl %r10d, 0x10(%rsp)
movl %eax, 0x18(%rsp)
callq 0x22890
cmpl $0x0, %eax
jge 0x2280e
movl $0xffffffff, -0xc(%rbp) # imm = 0xFFFFFFFF
jmp 0x2287f
jmp 0x22810
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x223df
jmp 0x22820
jmp 0x22822
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x22260
movq -0x20(%rbp), %rax
cmpl $0x1, 0x8(%rax)
jle 0x2284f
movq -0x20(%rbp), %rax
movslq 0x8(%rax), %rdi
movq -0x20(%rbp), %rax
movq 0x60(%rax), %rsi
callq 0x21b50
movq -0x20(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jne 0x22878
movq -0x20(%rbp), %rax
movl (%rax), %eax
shrl $0x3, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x22878
movq -0x20(%rbp), %rax
movl (%rax), %ecx
andl $-0x3, %ecx
orl $0x2, %ecx
movl %ecx, (%rax)
movl $0x0, -0xc(%rbp)
movl -0xc(%rbp), %eax
addq $0xb8, %rsp
popq %rbx
popq %rbp
retq
nopl (%rax)