// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/tbx.c
// Function: index_load
static tbx_t *index_load(const char *fn, const char *fnidx, int flags)
{
    tbx_t *tbx;
    uint8_t *meta;
    char *nm, *p;
    uint32_t l_meta, l_nm;
    tbx = (tbx_t*)calloc(1, sizeof(tbx_t));
    if (!tbx)
        return NULL;
    tbx->idx = hts_idx_load3(fn, fnidx, HTS_FMT_TBI, flags);
    if ( !tbx->idx )
    {
        free(tbx);
        return NULL;
    }
    meta = hts_idx_get_meta(tbx->idx, &l_meta);
    if ( !meta || l_meta < 28) goto invalid;

    tbx->conf.preset = le_to_i32(&meta[0]);
    tbx->conf.sc = le_to_i32(&meta[4]);
    tbx->conf.bc = le_to_i32(&meta[8]);
    tbx->conf.ec = le_to_i32(&meta[12]);
    tbx->conf.meta_char = le_to_i32(&meta[16]);
    tbx->conf.line_skip = le_to_i32(&meta[20]);
    l_nm = le_to_u32(&meta[24]);
    if (l_nm > l_meta - 28) goto invalid;

    p = nm = (char*)meta + 28;
    // This assumes meta is NUL-terminated, so we can merrily strlen away.
    // hts_idx_load_local() assures this for us by adding a NUL on the end
    // of whatever it reads.
    for (; p - nm < l_nm; p += strlen(p) + 1) {
        if (get_tid(tbx, p, 1) < 0) {
            hts_log_error("%s", strerror(errno));
            goto fail;
        }
    }
    return tbx;

 invalid:
    hts_log_error("Invalid index header for %s", fnidx ? fnidx : fn);

 fail:
    tbx_destroy(tbx);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %r15
movl $0x1, %edi
movl $0x28, %esi
callq 0x42f0
testq %rax, %rax
je 0x9bdf9
movq %rax, %rbx
movq %r15, %rdi
movq %r12, %rsi
movl $0x2, %edx
movl %ebp, %ecx
callq 0x10a91
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x9bdf1
leaq 0x14(%rsp), %r13
movq %rax, %rdi
movq %r13, %rsi
callq 0xcbad
movq %rax, %r14
testq %rax, %rax
sete %cl
movl (%r13), %eax
cmpl $0x1c, %eax
setb %dl
orb %cl, %dl
jne 0x9bdc3
movdqu (%r14), %xmm0
movdqu %xmm0, (%rbx)
movq 0x10(%r14), %rcx
movq %rcx, 0x10(%rbx)
movl 0x18(%r14), %ebp
addl $-0x1c, %eax
cmpl %eax, %ebp
jbe 0x9be0d
testq %r12, %r12
cmovneq %r12, %r15
leaq 0x19aae(%rip), %rsi     # 0xb587f
leaq 0x1b833(%rip), %rdx     # 0xb760b
movl $0x1, %edi
movq %r15, %rcx
xorl %eax, %eax
callq 0x942d
movq %rbx, %rdi
callq 0x9bbe9
jmp 0x9bdf9
movq %rbx, %rdi
callq 0x45c0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testq %rbp, %rbp
je 0x9bdfb
addq $0x1c, %r14
movd %xmm0, %eax
movzwl %ax, %r12d
xorl %r15d, %r15d
movq %r14, %r13
movl %r12d, (%rsp)
movq %r14, 0x8(%rsp)
cmpl $0x3, %r12d
je 0x9beb2
testq %r15, %r15
jne 0x9be4d
callq 0x6408
movq %rax, %r15
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x9bede
movq %rbp, %r14
movq %r15, %rdi
movq %r13, %rsi
leaq 0x4(%rsp), %rdx
callq 0x680c
cmpl $0x0, 0x4(%rsp)
js 0x9bede
movl %eax, %ebp
movl %eax, %edx
je 0x9be96
movq %rdx, %r12
movq %r13, %rdi
callq 0x4930
testq %rax, %rax
je 0x9bed4
movq 0x18(%r15), %rcx
movq %r12, %rdx
movq %rax, (%rcx,%r12,8)
movl 0x4(%r15), %eax
decl %eax
movq 0x20(%r15), %rcx
movq %rax, (%rcx,%r12,8)
cmpl (%r15), %ebp
movq %r14, %rbp
movq 0x8(%rsp), %r14
movl (%rsp), %r12d
je 0x9bede
movq 0x20(%r15), %rax
testb $-0x80, 0x3(%rax,%rdx,8)
jne 0x9bede
movq %r13, %rdi
callq 0x41c0
addq %rax, %r13
incq %r13
movq %r13, %rax
subq %r14, %rax
cmpq %rbp, %rax
jl 0x9be2d
jmp 0x9bdfb
movq %r15, %rdi
movl %ebp, %esi
callq 0x6a1e
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0x1998e(%rip), %rsi     # 0xb587f
leaq 0xf678(%rip), %rdx      # 0xab570
movl $0x1, %edi
movq %rax, %rcx
jmp 0x9bde0