// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/tbx.c
// Function: tbx_index
tbx_t *tbx_index(BGZF *fp, int min_shift, const tbx_conf_t *conf)
{
    tbx_t *tbx;
    kstring_t str;
    int ret, first = 0, n_lvls, fmt;
    int64_t lineno = 0;
    uint64_t last_off = 0;
    tbx_intv_t intv;
    int64_t max_ref_len = 0;

    str.s = 0; str.l = str.m = 0;
    tbx = (tbx_t*)calloc(1, sizeof(tbx_t));
    if (!tbx) return NULL;
    tbx->conf = *conf;
    if (min_shift > 0) n_lvls = (TBX_MAX_SHIFT - min_shift + 2) / 3, fmt = HTS_FMT_CSI;
    else min_shift = 14, n_lvls = 5, fmt = HTS_FMT_TBI;
    while ((ret = bgzf_getline(fp, '\n', &str)) >= 0) {
        ++lineno;
        if (str.s[0] == tbx->conf.meta_char && fmt == HTS_FMT_CSI) {
            switch (tbx->conf.preset) {
                case TBX_SAM:
                    adjust_max_ref_len_sam(str.s, &max_ref_len); break;
                case TBX_VCF:
                    adjust_max_ref_len_vcf(str.s, &max_ref_len); break;
                default:
                    break;
            }
        }
        if (lineno <= tbx->conf.line_skip || str.s[0] == tbx->conf.meta_char) {
            last_off = bgzf_tell(fp);
            continue;
        }
        if (first == 0) {
            if (fmt == HTS_FMT_CSI) {
                if (!max_ref_len)
                    max_ref_len = (int64_t)100*1024*1024*1024; // 100G default
                n_lvls = adjust_n_lvls(min_shift, n_lvls, max_ref_len);
            }
            tbx->idx = hts_idx_init(0, fmt, last_off, min_shift, n_lvls);
            if (!tbx->idx) goto fail;
            first = 1;
        }
        ret = get_intv(tbx, &str, &intv, 1);
        if (ret < 0) goto fail;  // Out of memory or unparsable lines
        if (hts_idx_push(tbx->idx, intv.tid, intv.beg, intv.end,
                         bgzf_tell(fp), 1) < 0) {
            goto fail;
        }
    }
    if (ret < -1) goto fail;
    if ( !tbx->idx ) tbx->idx = hts_idx_init(0, fmt, last_off, min_shift, n_lvls);   // empty file
    if (!tbx->idx) goto fail;
    if ( !tbx->dict ) tbx->dict = kh_init(s2i);
    if (!tbx->dict) goto fail;
    if (hts_idx_finish(tbx->idx, bgzf_tell(fp)) != 0) goto fail;
    if (tbx_set_meta(tbx) != 0) goto fail;
    free(str.s);
    return tbx;

 fail:
    free(str.s);
    tbx_destroy(tbx);
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movl $0x0, -0x48(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movq $0x0, -0x90(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x0, -0x38(%rbp)
movq $0x0, -0x40(%rbp)
movl $0x1, %edi
movl $0x28, %esi
callq 0x42e0
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xf1957
movq $0x0, -0x8(%rbp)
jmp 0xf1c42
movq -0x28(%rbp), %rax
movq -0x20(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movq 0x10(%rcx), %rcx
movq %rcx, 0x10(%rax)
cmpl $0x0, -0x14(%rbp)
jle 0xf199a
movl $0x1f, %eax
subl -0x14(%rbp), %eax
addl $0x2, %eax
movl $0x3, %ecx
cltd
idivl %ecx
movl %eax, -0x4c(%rbp)
movl $0x0, -0x50(%rbp)
jmp 0xf19af
movl $0xe, -0x14(%rbp)
movl $0x5, -0x4c(%rbp)
movl $0x2, -0x50(%rbp)
jmp 0xf19b1
movq -0x10(%rbp), %rdi
movl $0xa, %esi
leaq -0x40(%rbp), %rdx
callq 0xdc1e0
movl %eax, -0x44(%rbp)
cmpl $0x0, %eax
jl 0xf1b69
movq -0x58(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x58(%rbp)
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jne 0xf1a39
cmpl $0x0, -0x50(%rbp)
jne 0xf1a39
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x94(%rbp)
subl $0x1, %eax
je 0xf1a11
jmp 0xf1a04
movl -0x94(%rbp), %eax
subl $0x2, %eax
je 0xf1a23
jmp 0xf1a35
movq -0x30(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xf1c50
jmp 0xf1a37
movq -0x30(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0xf1ce0
jmp 0xf1a37
jmp 0xf1a37
jmp 0xf1a39
movq -0x58(%rbp), %rax
movq -0x28(%rbp), %rcx
movslq 0x14(%rcx), %rcx
cmpq %rcx, %rax
jle 0xf1a5a
movq -0x30(%rbp), %rax
movsbl (%rax), %eax
movq -0x28(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jne 0xf1a82
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
shlq $0x10, %rax
movq -0x10(%rbp), %rcx
movl 0x10(%rcx), %ecx
andl $0xffff, %ecx           # imm = 0xFFFF
movslq %ecx, %rcx
orq %rcx, %rax
movq %rax, -0x60(%rbp)
jmp 0xf19b1
cmpl $0x0, -0x48(%rbp)
jne 0xf1af5
cmpl $0x0, -0x50(%rbp)
jne 0xf1abe
cmpq $0x0, -0x90(%rbp)
jne 0xf1aa9
movabsq $0x1900000000, %rax     # imm = 0x1900000000
movq %rax, -0x90(%rbp)
movl -0x14(%rbp), %edi
movl -0x4c(%rbp), %esi
movq -0x90(%rbp), %rdx
callq 0xf1db0
movl %eax, -0x4c(%rbp)
movl -0x50(%rbp), %esi
movq -0x60(%rbp), %rdx
movl -0x14(%rbp), %ecx
movl -0x4c(%rbp), %r8d
xorl %edi, %edi
callq 0xda10
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0xf1aee
jmp 0xf1c28
movl $0x1, -0x48(%rbp)
movq -0x28(%rbp), %rdi
leaq -0x40(%rbp), %rsi
leaq -0x88(%rbp), %rdx
movl $0x1, %ecx
callq 0xf1710
movl %eax, -0x44(%rbp)
cmpl $0x0, -0x44(%rbp)
jge 0xf1b1c
jmp 0xf1c28
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
movl -0x68(%rbp), %esi
movq -0x88(%rbp), %rdx
movq -0x80(%rbp), %rcx
movq -0x10(%rbp), %rax
movq 0x18(%rax), %r8
shlq $0x10, %r8
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cltq
orq %rax, %r8
movl $0x1, %r9d
callq 0xe6f0
cmpl $0x0, %eax
jge 0xf1b64
jmp 0xf1c28
jmp 0xf19b1
cmpl $-0x1, -0x44(%rbp)
jge 0xf1b74
jmp 0xf1c28
movq -0x28(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0xf1b9f
movl -0x50(%rbp), %esi
movq -0x60(%rbp), %rdx
movl -0x14(%rbp), %ecx
movl -0x4c(%rbp), %r8d
xorl %edi, %edi
callq 0xda10
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0xf1bac
jmp 0xf1c28
movq -0x28(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0xf1bc7
callq 0x60f0
movq %rax, %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0xf1bd4
jmp 0xf1c28
movq -0x28(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rsi
shlq $0x10, %rsi
movq -0x10(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cltq
orq %rax, %rsi
callq 0xdbc0
cmpl $0x0, %eax
je 0xf1c05
jmp 0xf1c28
movq -0x28(%rbp), %rdi
callq 0xf1e10
cmpl $0x0, %eax
je 0xf1c15
jmp 0xf1c28
movq -0x30(%rbp), %rdi
callq 0x45a0
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xf1c42
movq -0x30(%rbp), %rdi
callq 0x45a0
movq -0x28(%rbp), %rdi
callq 0xf2040
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nop