// File: /workspace/github_c_makefile_star2_O3/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 0x1795f
leaq 0x7e14c(%rip), %rax     # 0x958e0
movslq (%rax,%rsi,4), %rcx
addq %rax, %rcx
jmpq *%rcx
xorl %eax, %eax
jmp 0x17966
movslq 0x14(%rdi), %rdx
testq %rdx, %rdx
jle 0x17953
movq 0x28(%rdi), %rax
movq %rax, -0x8(%rsp)
movq %rdi, -0x10(%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 0x17844
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 0x1783a
testb $0x1, %r13b
jne 0x1782b
movq 0x18(%r10), %r13
movl %ebx, %edi
cmpl %r8d, (%r13,%rdi,4)
je 0x1783a
addl %r12d, %ebx
andl %ebp, %ebx
incl %r12d
cmpl %r14d, %ebx
jne 0x177fd
jmp 0x17862
shrl %cl, %esi
testb $0x3, %sil
cmovnel %r11d, %ebx
cmpl %r11d, %ebx
je 0x17862
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 0x177d0
jmp 0x17948
movslq 0x14(%rdi), %rdx
testq %rdx, %rdx
jle 0x17953
movq 0x28(%rdi), %rax
movq %rax, -0x8(%rsp)
movq %rdi, -0x10(%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 0x17912
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 0x17907
testb $0x1, %dil
jne 0x178f8
movq 0x18(%r10), %rdi
movl %ebx, %esi
cmpl %r8d, (%rdi,%rsi,4)
je 0x17907
addl %r12d, %ebx
andl %ebp, %ebx
incl %r12d
cmpl %r14d, %ebx
jne 0x178cc
jmp 0x1793c
shrl %cl, %r13d
testb $0x3, %r13b
cmovnel %r11d, %ebx
cmpl %r11d, %ebx
je 0x1793c
movq 0x20(%r10), %rcx
movl %ebx, %esi
leaq (%rsi,%rsi,2), %rsi
movq 0x10(%rcx,%rsi,8), %rcx
movq 0x8(%rcx), %rcx
cmpq $-0x1, %rax
je 0x17939
cmpq %rcx, %rax
cmovbeq %rcx, %rax
jmp 0x1793c
movq %rcx, %rax
incq %r9
cmpq %rdx, %r9
jne 0x1789f
cmpq $-0x1, %rax
movq -0x10(%rsp), %rdi
jne 0x17966
xorl %eax, %eax
cmpq $0x1, 0x20(%rdi)
sbbq %rax, %rax
jmp 0x17966
movq $-0x1, %rax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq