// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/hts.c
// Function: idx_read
static hts_idx_t *idx_read(const char *fn)
{
    uint8_t magic[4];
    int i, is_be;
    hts_idx_t *idx = NULL;
    uint8_t *meta = NULL;
    BGZF *fp = bgzf_open(fn, "r");
    if (fp == NULL) return NULL;
    is_be = ed_is_big();
    if (bgzf_read(fp, magic, 4) != 4) goto fail;

    if (memcmp(magic, "CSI\1", 4) == 0) {
        uint32_t x[3], n;
        if (bgzf_read(fp, x, 12) != 12) goto fail;
        if (is_be) for (i = 0; i < 3; ++i) ed_swap_4p(&x[i]);
        if (x[2]) {
            if (SIZE_MAX - x[2] < 1) goto fail; // Prevent possible overflow
            if ((meta = (uint8_t*)malloc((size_t) x[2] + 1)) == NULL) goto fail;
            if (bgzf_read(fp, meta, x[2]) != x[2]) goto fail;
            // Prevent possible strlen past the end in tbx_index_load2
            meta[x[2]] = '\0';
        }
        if (bgzf_read(fp, &n, 4) != 4) goto fail;
        if (is_be) ed_swap_4p(&n);
        if (n > INT32_MAX) goto fail;
        if ((idx = hts_idx_init(n, HTS_FMT_CSI, 0, x[0], x[1])) == NULL) goto fail;
        idx->l_meta = x[2];
        idx->meta = meta;
        meta = NULL;
        if (idx_read_core(idx, fp, HTS_FMT_CSI) < 0) goto fail;
    }
    else if (memcmp(magic, "TBI\1", 4) == 0) {
        uint8_t x[8 * 4];
        uint32_t n;
        // Read file header
        if (bgzf_read(fp, x, sizeof(x)) != sizeof(x)) goto fail;
        n = le_to_u32(&x[0]); // location of n_ref
        if (n > INT32_MAX) goto fail;
        if ((idx = hts_idx_init(n, HTS_FMT_TBI, 0, 14, 5)) == NULL) goto fail;
        n = le_to_u32(&x[7*4]); // location of l_nm
        if (n > UINT32_MAX - 29) goto fail; // Prevent possible overflow
        idx->l_meta = 28 + n;
        if ((idx->meta = (uint8_t*)malloc(idx->l_meta + 1)) == NULL) goto fail;
        // copy format, col_seq, col_beg, col_end, meta, skip, l_nm
        // N.B. left in little-endian byte order.
        memcpy(idx->meta, &x[1*4], 28);
        // Read in sequence names.
        if (bgzf_read(fp, idx->meta + 28, n) != n) goto fail;
        // Prevent possible strlen past the end in tbx_index_load2
        idx->meta[idx->l_meta] = '\0';
        if (idx_read_core(idx, fp, HTS_FMT_TBI) < 0) goto fail;
    }
    else if (memcmp(magic, "BAI\1", 4) == 0) {
        uint32_t n;
        if (bgzf_read(fp, &n, 4) != 4) goto fail;
        if (is_be) ed_swap_4p(&n);
        if (n > INT32_MAX) goto fail;
        if ((idx = hts_idx_init(n, HTS_FMT_BAI, 0, 14, 5)) == NULL) goto fail;
        if (idx_read_core(idx, fp, HTS_FMT_BAI) < 0) goto fail;
    }
    else { errno = EINVAL; goto fail; }

    bgzf_close(fp);
    return idx;

fail:
    bgzf_close(fp);
    hts_idx_destroy(idx);
    free(meta);
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
movq -0x10(%rbp), %rdi
leaq 0xcc4b7(%rip), %rsi     # 0xf2af1
callq 0xc090
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jne 0x26657
movq $0x0, -0x8(%rbp)
jmp 0x26a09
callq 0x1cf00
movl %eax, -0x1c(%rbp)
movq -0x38(%rbp), %rdi
leaq -0x14(%rbp), %rsi
movl $0x4, %edx
callq 0xe620
cmpq $0x4, %rax
je 0x2667c
jmp 0x269e6
leaq -0x14(%rbp), %rax
movl (%rax), %eax
subl $0x1495343, %eax        # imm = 0x1495343
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x267e8
movq -0x38(%rbp), %rdi
leaq -0x44(%rbp), %rsi
movl $0xc, %edx
callq 0xe620
cmpq $0xc, %rax
je 0x266b3
jmp 0x269e6
cmpl $0x0, -0x1c(%rbp)
je 0x266e7
movl $0x0, -0x18(%rbp)
cmpl $0x3, -0x18(%rbp)
jge 0x266e5
movslq -0x18(%rbp), %rax
leaq -0x44(%rbp), %rdi
shlq $0x2, %rax
addq %rax, %rdi
callq 0x29330
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x18(%rbp)
jmp 0x266c0
jmp 0x266e7
cmpl $0x0, -0x3c(%rbp)
je 0x2674e
movl -0x3c(%rbp), %eax
movl %eax, %ecx
movq $-0x1, %rax
subq %rcx, %rax
cmpq $0x1, %rax
jae 0x26707
jmp 0x269e6
movl -0x3c(%rbp), %eax
movl %eax, %edi
addq $0x1, %rdi
callq 0x4650
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
jne 0x26724
jmp 0x269e6
movq -0x38(%rbp), %rdi
movq -0x30(%rbp), %rsi
movl -0x3c(%rbp), %eax
movl %eax, %edx
callq 0xe620
movl -0x3c(%rbp), %ecx
cmpq %rcx, %rax
je 0x26743
jmp 0x269e6
movq -0x30(%rbp), %rax
movl -0x3c(%rbp), %ecx
movb $0x0, (%rax,%rcx)
movq -0x38(%rbp), %rdi
leaq -0x48(%rbp), %rsi
movl $0x4, %edx
callq 0xe620
cmpq $0x4, %rax
je 0x2676b
jmp 0x269e6
cmpl $0x0, -0x1c(%rbp)
je 0x2677a
leaq -0x48(%rbp), %rdi
callq 0x29330
cmpl $0x7fffffff, -0x48(%rbp) # imm = 0x7FFFFFFF
jbe 0x26788
jmp 0x269e6
movl -0x48(%rbp), %edi
movl -0x44(%rbp), %ecx
movl -0x40(%rbp), %r8d
xorl %esi, %esi
xorl %eax, %eax
movl %eax, %edx
callq 0x1ecb0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x267ac
jmp 0x269e6
movl -0x3c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x30(%rbp), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x38(%rax)
movq $0x0, -0x30(%rbp)
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
xorl %edx, %edx
callq 0x29360
cmpl $0x0, %eax
jge 0x267e3
jmp 0x269e6
jmp 0x269d3
leaq -0x14(%rbp), %rax
movl (%rax), %eax
subl $0x1494254, %eax        # imm = 0x1494254
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x26932
movq -0x38(%rbp), %rdi
leaq -0x70(%rbp), %rsi
movl $0x20, %edx
callq 0xe620
cmpq $0x20, %rax
je 0x2681f
jmp 0x269e6
leaq -0x70(%rbp), %rdi
callq 0x202b0
movl %eax, -0x74(%rbp)
cmpl $0x7fffffff, -0x74(%rbp) # imm = 0x7FFFFFFF
jbe 0x26839
jmp 0x269e6
movl -0x74(%rbp), %edi
movl $0x2, %esi
xorl %eax, %eax
movl %eax, %edx
movl $0xe, %ecx
movl $0x5, %r8d
callq 0x1ecb0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x26864
jmp 0x269e6
leaq -0x70(%rbp), %rdi
addq $0x1c, %rdi
callq 0x202b0
movl %eax, -0x74(%rbp)
cmpl $-0x1e, -0x74(%rbp)
jbe 0x2687f
jmp 0x269e6
movl -0x74(%rbp), %ecx
addl $0x1c, %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x10(%rax)
movq -0x28(%rbp), %rax
movl 0x10(%rax), %eax
addl $0x1, %eax
movl %eax, %eax
movl %eax, %edi
callq 0x4650
movq -0x28(%rbp), %rcx
movq %rax, 0x38(%rcx)
cmpq $0x0, %rax
jne 0x268b2
jmp 0x269e6
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x6c(%rbp), %rcx
movq %rcx, (%rax)
movq -0x64(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x5c(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl -0x54(%rbp), %ecx
movl %ecx, 0x18(%rax)
movq -0x38(%rbp), %rdi
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rsi
addq $0x1c, %rsi
movl -0x74(%rbp), %eax
movl %eax, %edx
callq 0xe620
movl -0x74(%rbp), %ecx
cmpq %rcx, %rax
je 0x268fe
jmp 0x269e6
movq -0x28(%rbp), %rax
movq 0x38(%rax), %rax
movq -0x28(%rbp), %rcx
movl 0x10(%rcx), %ecx
movb $0x0, (%rax,%rcx)
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x2, %edx
callq 0x29360
cmpl $0x0, %eax
jge 0x2692d
jmp 0x269e6
jmp 0x269d1
leaq -0x14(%rbp), %rax
movl (%rax), %eax
subl $0x1494142, %eax        # imm = 0x1494142
setne %al
movzbl %al, %eax
cmpl $0x0, %eax
jne 0x269c2
movq -0x38(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl $0x4, %edx
callq 0xe620
cmpq $0x4, %rax
je 0x26965
jmp 0x269e6
cmpl $0x0, -0x1c(%rbp)
je 0x26974
leaq -0x78(%rbp), %rdi
callq 0x29330
cmpl $0x7fffffff, -0x78(%rbp) # imm = 0x7FFFFFFF
jbe 0x2697f
jmp 0x269e6
movl -0x78(%rbp), %edi
movl $0x1, %esi
xorl %eax, %eax
movl %eax, %edx
movl $0xe, %ecx
movl $0x5, %r8d
callq 0x1ecb0
movq %rax, -0x28(%rbp)
cmpq $0x0, %rax
jne 0x269a7
jmp 0x269e6
movq -0x28(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x1, %edx
callq 0x29360
cmpl $0x0, %eax
jge 0x269c0
jmp 0x269e6
jmp 0x269cf
callq 0x4050
movl $0x16, (%rax)
jmp 0x269e6
jmp 0x269d1
jmp 0x269d3
movq -0x38(%rbp), %rdi
callq 0x103d0
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x26a09
movq -0x38(%rbp), %rdi
callq 0x103d0
movq -0x28(%rbp), %rdi
callq 0x1d560
movq -0x30(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)