// File: /workspace/github_c_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
addl $0x5, %esi
cmpl $0x3, %esi
ja 0x17e69
leaq 0x80b8a(%rip), %rax     # 0x98830
movslq (%rax,%rsi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
xorl %eax, %eax
jmp 0x17e8e
movslq 0x14(%rdi), %rdx
testq %rdx, %rdx
movq %rdi, -0x10(%rsp)
jle 0x17e72
movq 0x28(%rdi), %rax
movq %rax, -0x8(%rsp)
movl 0xc(%rdi), %r8d
incl %r8d
movq $-0x1, %rax
xorl %r9d, %r9d
movq -0x8(%rsp), %rcx
movq (%rcx,%r9,8), %r10
movl (%r10), %r11d
movl $0x0, %ebx
testl %r11d, %r11d
je 0x17d59
leal -0x1(%r11), %ebp
movl %ebp, %r14d
andl %r8d, %r14d
movq 0x10(%r10), %r15
movl $0x1, %r12d
movl %r14d, %ebx
movl %ebx, %ecx
shrl $0x4, %ecx
movl (%r15,%rcx,4), %esi
leal (%rbx,%rbx), %ecx
andl $0x1e, %ecx
movl %esi, %r13d
shrl %cl, %r13d
testb $0x2, %r13b
jne 0x17d4f
testb $0x1, %r13b
jne 0x17d3d
movq 0x18(%r10), %r13
movl %ebx, %edi
cmpl %r8d, (%r13,%rdi,4)
je 0x17d4f
addl %r12d, %ebx
andl %ebp, %ebx
incl %r12d
cmpl %r14d, %ebx
jne 0x17d0f
movl %r11d, %ebx
jmp 0x17d59
shrl %cl, %esi
testb $0x3, %sil
cmovnel %r11d, %ebx
cmpl %r11d, %ebx
je 0x17d77
movq 0x20(%r10), %rcx
movl %ebx, %esi
leaq (%rsi,%rsi,2), %rsi
movq 0x10(%rcx,%rsi,8), %rcx
movq (%rcx), %rcx
cmpq %rcx, %rax
cmovaeq %rcx, %rax
incq %r9
cmpq %rdx, %r9
jne 0x17ce2
jmp 0x17e79
movslq 0x14(%rdi), %rdx
testq %rdx, %rdx
movq %rdi, -0x10(%rsp)
jle 0x17e72
movq 0x28(%rdi), %rax
movq %rax, -0x8(%rsp)
movl 0xc(%rdi), %r8d
incl %r8d
movq $-0x1, %rax
xorl %r9d, %r9d
movq -0x8(%rsp), %rcx
movq (%rcx,%r9,8), %r10
movl (%r10), %r11d
movl $0x0, %ebx
testl %r11d, %r11d
je 0x17e2a
leal -0x1(%r11), %ebp
movl %ebp, %r14d
andl %r8d, %r14d
movq 0x10(%r10), %r15
movl $0x1, %r12d
movl %r14d, %ebx
movl %ebx, %ecx
shrl $0x4, %ecx
movl (%r15,%rcx,4), %r13d
leal (%rbx,%rbx), %ecx
andl $0x1e, %ecx
movl %r13d, %edi
shrl %cl, %edi
testb $0x2, %dil
jne 0x17e1f
testb $0x1, %dil
jne 0x17e0d
movq 0x18(%r10), %rdi
movl %ebx, %esi
cmpl %r8d, (%rdi,%rsi,4)
je 0x17e1f
addl %r12d, %ebx
andl %ebp, %ebx
incl %r12d
cmpl %r14d, %ebx
jne 0x17de1
movl %r11d, %ebx
jmp 0x17e2a
shrl %cl, %r13d
testb $0x3, %r13b
cmovnel %r11d, %ebx
cmpl %r11d, %ebx
je 0x17e5b
movl %ebx, %ecx
cmpq $-0x1, %rax
je 0x17e4a
movq 0x20(%r10), %rsi
leaq (%rcx,%rcx,2), %rdi
movq 0x10(%rsi,%rdi,8), %rsi
cmpq 0x8(%rsi), %rax
jae 0x17e5b
movq 0x20(%r10), %rax
leaq (%rcx,%rcx,2), %rcx
movq 0x10(%rax,%rcx,8), %rax
movq 0x8(%rax), %rax
incq %r9
cmpq %rdx, %r9
jne 0x17db4
jmp 0x17e79
movq $-0x1, %rax
jmp 0x17e8e
movq $-0x1, %rax
cmpq $-0x1, %rax
jne 0x17e8e
xorl %eax, %eax
movq -0x10(%rsp), %rcx
cmpq $0x1, 0x20(%rcx)
sbbq %rax, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq