// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/hts.c
// Function: hts_itr_off
uint64_t hts_itr_off(const hts_idx_t* idx, int tid) {

    int i;
    bidx_t* bidx;
    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:
        /* No-coor reads sort after all of the mapped reads.  The position
           is not stored in the index itself, so need to find the end
           offset for the last mapped read.  A loop is needed here in
           case references at the end of the file have no mapped reads,
           or sequence ids are not ordered sequentially.
           See issue samtools#568 and commits b2aab8, 60c22d and cc207d. */
        for (i = 0; i < idx->n; i++) {
            bidx = idx->bidx[i];
            k = kh_get(bin, bidx, META_BIN(idx));
            if (k != kh_end(bidx)) {
                if (off0 == (uint64_t) -1 || off0 < kh_val(bidx, k).list[0].v) {
                    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:
        off0 = 0;
        break;
    }

    return off0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
addl $0x5, %esi
cmpl $0x3, %esi
ja 0x145d4
movq %rdi, %rbx
leaq 0x6338e(%rip), %rax     # 0x77890
movslq (%rax,%rsi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
xorl %r14d, %r14d
jmp 0x145d8
movl 0x14(%rbx), %r12d
xorl %r13d, %r13d
testl %r12d, %r12d
cmovlel %r13d, %r12d
pushq $-0x1
popq %r14
cmpq %r13, %r12
je 0x145c1
movq 0x28(%rbx), %rax
movq (%rax,%r13,8), %r15
movl 0xc(%rbx), %esi
incl %esi
movq %r15, %rdi
callq 0x14465
cmpl (%r15), %eax
je 0x14561
movq 0x20(%r15), %rcx
movl %eax, %eax
imulq $0x18, %rax, %rax
movq 0x10(%rcx,%rax), %rax
movq (%rax), %rax
cmpq %rax, %r14
cmovaeq %rax, %r14
incq %r13
jmp 0x14525
movl 0x14(%rbx), %r12d
xorl %r13d, %r13d
testl %r12d, %r12d
cmovlel %r13d, %r12d
pushq $-0x1
popq %r14
cmpq %r13, %r12
je 0x145c1
movq 0x28(%rbx), %rax
movq (%rax,%r13,8), %r15
movl 0xc(%rbx), %esi
incl %esi
movq %r15, %rdi
callq 0x14465
cmpl (%r15), %eax
je 0x145bc
movl %eax, %eax
imulq $0x18, %rax, %rax
movq 0x20(%r15), %rcx
movq 0x10(%rcx,%rax), %rax
movq 0x8(%rax), %rax
cmpq $-0x1, %r14
je 0x145b9
cmpq %rax, %r14
cmovbeq %rax, %r14
jmp 0x145bc
movq %rax, %r14
incq %r13
jmp 0x14578
cmpq $-0x1, %r14
jne 0x145d8
xorl %r14d, %r14d
cmpq $0x1, 0x20(%rbx)
sbbq %r14, %r14
jmp 0x145d8
pushq $-0x1
popq %r14
movq %r14, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq