// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/hts.c
// Function: hts_itr_multi_cram
int hts_itr_multi_cram(const hts_idx_t *idx, hts_itr_t *iter)
{
    const hts_cram_idx_t *cidx = (const hts_cram_idx_t *) idx;
    int tid, i, n_off = 0;
    uint32_t j;
    hts_pos_t beg, end;
    hts_reglist_t *curr_reg;
    hts_pair32_t *curr_intv;
    hts_pair64_max_t *off = NULL, *tmp;
    cram_index *e = NULL;

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

    iter->is_cram = 1;
    iter->read_rest = 0;
    iter->off = NULL;
    iter->n_off = 0;
    iter->curr_off = 0;
    iter->i = -1;

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

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

        if (tid >= 0) {
            tmp = realloc(off, (n_off + curr_reg->count) * sizeof(*off));
            if (!tmp)
                goto err;
            off = tmp;

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

                beg = curr_intv->beg;
                end = curr_intv->end;

/* First, fetch the container overlapping 'beg' and assign its file offset to u, then
 * find the container overlapping 'end' and assign the relative end of the slice to v.
 * The cram_ptell function will adjust with the container offset, which is not stored
 * in the index.
 */
                e = cram_index_query(cidx->cram, tid, beg+1, NULL);
                if (e) {
                    off[n_off].u = e->offset;
                    // hts_pair64_max_t::max is now used to link
                    // file offsets to region list entries.
                    // The iterator can use this to decide if it
                    // can skip some file regions.
                    off[n_off].max = ((uint64_t) tid << 32) | j;

                    if (end >= HTS_POS_MAX) {
                       e = cram_index_last(cidx->cram, tid, NULL);
                    } else {
                       e = cram_index_query_last(cidx->cram, tid, end+1);
                    }

                    if (e) {
                        off[n_off++].v = e->e_next
                            ? e->e_next->offset
                            : e->offset + e->slice + e->len;
                    } else {
                        hts_log_warning("Could not set offset end for region %d:%"PRIhts_pos"-%"PRIhts_pos". Skipping", tid, beg, end);
                    }
                }
            }
        } else {
            switch (tid) {
                case HTS_IDX_NOCOOR:
                    e = cram_index_query(cidx->cram, tid, 1, NULL);
                    if (e) {
                        iter->nocoor = 1;
                        iter->nocoor_off = e->offset;
                    } else {
                        hts_log_warning("No index entry for NOCOOR region");
                    }
                    break;
                case HTS_IDX_START:
                    e = cram_index_query(cidx->cram, tid, 1, NULL);
                    if (e) {
                        iter->read_rest = 1;
                        tmp = realloc(off, sizeof(*off));
                        if (!tmp)
                            goto err;
                        off = tmp;
                        off[0].u = e->offset;
                        off[0].v = 0;
                        n_off=1;
                    } else {
                        hts_log_warning("No index entries");
                    }
                    break;
                case HTS_IDX_REST:
                    break;
                case HTS_IDX_NONE:
                    iter->finished = 1;
                    break;
                default:
                    hts_log_error("Query with tid=%d not implemented for CRAM files", tid);
            }
        }
    }

    if (n_off) {
        ks_introsort(_off_max, n_off, off);
        iter->n_off = n_off; iter->off = off;
    }

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

    return 0;

 err:
    free(off);
    return -1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movl $0x0, -0x2c(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x68(%rbp)
cmpq $0x0, -0x20(%rbp)
je 0x22c21
cmpq $0x0, -0x18(%rbp)
je 0x22c21
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x22c2d
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x23061
movq -0x18(%rbp), %rax
movl (%rax), %ecx
andl $-0x5, %ecx
orl $0x4, %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movl (%rax), %ecx
andl $-0x2, %ecx
orl $0x0, %ecx
movl %ecx, (%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x60(%rax)
movq -0x18(%rbp), %rax
movl $0x0, 0x8(%rax)
movq -0x18(%rbp), %rax
movq $0x0, 0x50(%rax)
movq -0x18(%rbp), %rax
movl $0xffffffff, 0xc(%rax)  # imm = 0xFFFFFFFF
movl $0x0, -0x28(%rbp)
movl -0x28(%rbp), %eax
movq -0x18(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jge 0x22ffa
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x28(%rbp), %rcx
imulq $0x28, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rax
movl 0x10(%rax), %eax
movl %eax, -0x24(%rbp)
cmpl $0x0, -0x24(%rbp)
jl 0x22e95
movq -0x58(%rbp), %rdi
movl -0x2c(%rbp), %eax
movq -0x48(%rbp), %rcx
addl 0x14(%rcx), %eax
movl %eax, %eax
imulq $0x18, %rax, %rsi
callq 0x4820
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x22ce2
jmp 0x23051
movq -0x60(%rbp), %rax
movq %rax, -0x58(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movq -0x48(%rbp), %rcx
cmpl 0x14(%rcx), %eax
jae 0x22e90
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movl -0x30(%rbp), %ecx
shlq $0x4, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq -0x50(%rbp), %rcx
cmpq (%rcx), %rax
jge 0x22d2d
jmp 0x22e82
movq -0x50(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x50(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x24(%rbp), %esi
movq -0x38(%rbp), %rdx
addq $0x1, %rdx
xorl %eax, %eax
movl %eax, %ecx
callq 0x6b0d0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x22e80
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x58(%rbp), %rax
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, (%rax)
movslq -0x24(%rbp), %rcx
shlq $0x20, %rcx
movl -0x30(%rbp), %eax
orq %rax, %rcx
movq -0x58(%rbp), %rax
movslq -0x2c(%rbp), %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x10(%rax)
movabsq $0x7fffffff7fffffff, %rax # imm = 0x7FFFFFFF7FFFFFFF
cmpq %rax, -0x40(%rbp)
jl 0x22dd4
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x24(%rbp), %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x6b4d0
movq %rax, -0x68(%rbp)
jmp 0x22df0
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x24(%rbp), %esi
movq -0x40(%rbp), %rdx
addq $0x1, %rdx
callq 0x6b5b0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x22e59
movq -0x68(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x22e14
movq -0x68(%rbp), %rax
movq 0x30(%rax), %rax
movq 0x28(%rax), %rax
movq %rax, -0x70(%rbp)
jmp 0x22e36
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x68(%rbp), %rcx
movslq 0x20(%rcx), %rcx
addq %rcx, %rax
movq -0x68(%rbp), %rcx
movslq 0x24(%rcx), %rcx
addq %rcx, %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rcx
movq -0x58(%rbp), %rax
movl -0x2c(%rbp), %edx
movl %edx, %esi
addl $0x1, %esi
movl %esi, -0x2c(%rbp)
movslq %edx, %rdx
imulq $0x18, %rdx, %rdx
addq %rdx, %rax
movq %rcx, 0x8(%rax)
jmp 0x22e7e
movl -0x24(%rbp), %ecx
movq -0x38(%rbp), %r8
movq -0x40(%rbp), %r9
movl $0x3, %edi
leaq 0xcd98c(%rip), %rsi     # 0xf07fc
leaq 0xcd998(%rip), %rdx     # 0xf080f
movb $0x0, %al
callq 0x1b030
jmp 0x22e80
jmp 0x22e82
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x22cf1
jmp 0x22fea
movl -0x24(%rbp), %eax
addl $0x5, %eax
movl %eax, %ecx
movq %rcx, -0x78(%rbp)
subl $0x3, %eax
ja 0x22fcb
movq -0x78(%rbp), %rax
leaq 0xccba7(%rip), %rcx     # 0xefa5c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x24(%rbp), %esi
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x6b0d0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x22f02
movq -0x18(%rbp), %rax
movl (%rax), %ecx
andl $-0x9, %ecx
orl $0x8, %ecx
movl %ecx, (%rax)
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x58(%rax)
jmp 0x22f1c
movl $0x3, %edi
leaq 0xcd8ee(%rip), %rsi     # 0xf07fc
leaq 0xcd933(%rip), %rdx     # 0xf0848
movb $0x0, %al
callq 0x1b030
jmp 0x22fe8
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
movl -0x24(%rbp), %esi
movl $0x1, %edx
xorl %eax, %eax
movl %eax, %ecx
callq 0x6b0d0
movq %rax, -0x68(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x22f9d
movq -0x18(%rbp), %rax
movl (%rax), %ecx
andl $-0x2, %ecx
orl $0x1, %ecx
movl %ecx, (%rax)
movq -0x58(%rbp), %rdi
movl $0x18, %esi
callq 0x4820
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x22f71
jmp 0x23051
movq -0x60(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x68(%rbp), %rax
movq 0x28(%rax), %rcx
movq -0x58(%rbp), %rax
movq %rcx, (%rax)
movq -0x58(%rbp), %rax
movq $0x0, 0x8(%rax)
movl $0x1, -0x2c(%rbp)
jmp 0x22fb7
movl $0x3, %edi
leaq 0xcd853(%rip), %rsi     # 0xf07fc
leaq 0xcd8b9(%rip), %rdx     # 0xf0869
movb $0x0, %al
callq 0x1b030
jmp 0x22fe8
jmp 0x22fe8
movq -0x18(%rbp), %rax
movl (%rax), %ecx
andl $-0x3, %ecx
orl $0x2, %ecx
movl %ecx, (%rax)
jmp 0x22fe8
movl -0x24(%rbp), %ecx
movl $0x1, %edi
leaq 0xcd822(%rip), %rsi     # 0xf07fc
leaq 0xcd899(%rip), %rdx     # 0xf087a
movb $0x0, %al
callq 0x1b030
jmp 0x22fea
jmp 0x22fec
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0x22c7e
cmpl $0x0, -0x2c(%rbp)
je 0x23023
movslq -0x2c(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x21b50
movl -0x2c(%rbp), %ecx
movq -0x18(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x58(%rbp), %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x60(%rax)
cmpl $0x0, -0x2c(%rbp)
jne 0x23048
movq -0x18(%rbp), %rax
movl (%rax), %eax
shrl $0x3, %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0x23048
movq -0x18(%rbp), %rax
movl (%rax), %ecx
andl $-0x3, %ecx
orl $0x2, %ecx
movl %ecx, (%rax)
movl $0x0, -0x4(%rbp)
jmp 0x23061
movq -0x58(%rbp), %rdi
callq 0x45a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax)