// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
movl $0x1, %edi
movl $0x28, %esi
callq 0x42f0
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
testq %rax, %rax
je 0x9e079
movq %rax, %r13
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r13)
movups (%rbx), %xmm0
movups %xmm0, (%r13)
testl %ebp, %ebp
movl %ebp, 0x30(%rsp)
jle 0x9de09
movl $0x21, %eax
subl %ebp, %eax
cltq
imulq $0x55555556, %rax, %r15 # imm = 0x55555556
movq %r15, %rax
shrq $0x3f, %rax
shrq $0x20, %r15
addl %eax, %r15d
movl $0x0, 0x24(%rsp)
movl %ebp, 0x14(%rsp)
jmp 0x9de1f
movl $0x2, 0x24(%rsp)
movl $0x5, %r15d
movl $0xe, 0x14(%rsp)
movb $0x1, %al
movl %eax, 0x3c(%rsp)
movq $0x0, 0x8(%rsp)
leaq 0x40(%rsp), %rbp
xorl %ebx, %ebx
xorl %r12d, %r12d
movq %r13, 0x18(%rsp)
movq %r14, %rdi
movl $0xa, %esi
movq %rbp, %rdx
callq 0x8f6b5
testl %eax, %eax
js 0x9e062
movq %r15, 0x28(%rsp)
movl 0x10(%r13), %r15d
movslq 0x14(%r13), %r13
movq %rbx, %rbp
cmpl $0x0, 0x30(%rsp)
jle 0x9defc
movq 0x50(%rsp), %rbx
movsbl (%rbx), %eax
cmpl %eax, %r15d
jne 0x9defc
movq 0x18(%rsp), %rax
movl (%rax), %eax
cmpl $0x2, %eax
je 0x9dee4
cmpl $0x1, %eax
jne 0x9defc
movl $0x3, %edx
movq %rbx, %rdi
leaq 0xef8c(%rip), %rsi      # 0xace29
callq 0x4200
testl %eax, %eax
jne 0x9defc
addq $0x3, %rbx
movq %rbx, %rdi
leaq 0x1bff9(%rip), %rsi     # 0xb9ead
callq 0x40d0
testq %rax, %rax
je 0x9defc
addq $0x4, %rax
movq %rax, %rdi
xorl %esi, %esi
movl $0xa, %edx
callq 0x40a0
movq 0x8(%rsp), %rcx
cmpq %rax, %rcx
cmovleq %rax, %rcx
movq %rcx, 0x8(%rsp)
jmp 0x9defc
movl $0x8, %edx
movq %rbx, %rdi
leaq 0x1bfbf(%rip), %rsi     # 0xb9eb2
callq 0x4200
testl %eax, %eax
je 0x9df44
leaq 0x1(%rbp), %rbx
cmpq %r13, %rbp
jl 0x9df12
movq 0x50(%rsp), %rax
movsbl (%rax), %eax
cmpl %eax, %r15d
jne 0x9df76
movq 0x18(%r14), %rax
shlq $0x10, %rax
movzwl 0x10(%r14), %r12d
orq %rax, %r12
movq %r14, %rdi
movl $0xa, %esi
leaq 0x40(%rsp), %rdx
callq 0x8f6b5
movq %rbx, %rbp
testl %eax, %eax
jns 0x9de65
jmp 0x9e058
addq $0x8, %rbx
movq %rbx, %rdi
leaq 0xf6d5(%rip), %rsi      # 0xad627
callq 0x40d0
testq %rax, %rax
je 0x9defc
addq $0x6, %rax
movzbl (%rax), %ecx
cmpl $0x3d, %ecx
je 0x9df71
cmpl $0x20, %ecx
jne 0x9dec2
incq %rax
jmp 0x9df60
testb $0x1, 0x3c(%rsp)
leaq 0x40(%rsp), %rbp
je 0x9dfd3
cmpl $0x0, 0x30(%rsp)
movq 0x18(%rsp), %r13
movq 0x28(%rsp), %r15
jle 0x9dfdf
movq 0x8(%rsp), %rdx
testq %rdx, %rdx
movabsq $0x1900000000, %rax     # imm = 0x1900000000
cmoveq %rax, %rdx
leal (%r15,%r15,2), %ecx
addl 0x14(%rsp), %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rdx, 0x8(%rsp)
leaq 0x100(%rdx), %rcx
cmpq %rax, %rcx
jle 0x9dfdf
incl %r15d
shlq $0x3, %rax
jmp 0x9dfc5
movq 0x18(%rsp), %r13
movq 0x28(%rsp), %r15
jmp 0x9dffd
xorl %edi, %edi
movl 0x24(%rsp), %esi
movq %r12, %rdx
movl 0x14(%rsp), %ecx
movl %r15d, %r8d
callq 0xb94c
movq %rax, 0x18(%r13)
testq %rax, %rax
je 0x9e067
movq %r13, %rdi
movq %rbp, %rsi
leaq 0x60(%rsp), %rdx
movl $0x1, %ecx
callq 0x9dbce
testl %eax, %eax
js 0x9e067
movq 0x18(%r13), %rdi
movl 0x80(%rsp), %esi
movq 0x60(%rsp), %rdx
movq 0x68(%rsp), %rcx
movq 0x18(%r14), %rax
shlq $0x10, %rax
movzwl 0x10(%r14), %r8d
orq %rax, %r8
movl $0x1, %r9d
callq 0xc2e9
movl $0x0, 0x3c(%rsp)
testl %eax, %eax
jns 0x9de3d
jmp 0x9e067
movq 0x18(%rsp), %r13
movq 0x28(%rsp), %r15
cmpl $-0x1, %eax
je 0x9e08d
movq 0x50(%rsp), %rdi
callq 0x45c0
movq %r13, %rdi
callq 0x9e22a
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpq $0x0, 0x18(%r13)
jne 0x9e0ad
xorl %edi, %edi
movl 0x24(%rsp), %esi
movq %r12, %rdx
movl 0x14(%rsp), %ecx
movl %r15d, %r8d
callq 0xb94c
movq %rax, 0x18(%r13)
movq 0x18(%r13), %rbx
testq %rbx, %rbx
je 0x9e067
cmpq $0x0, 0x20(%r13)
jne 0x9e0c6
callq 0x63f8
movq %rax, 0x20(%r13)
movq 0x20(%r13), %r15
testq %r15, %r15
je 0x9e067
movq 0x18(%r14), %rax
shlq $0x10, %rax
movzwl 0x10(%r14), %esi
orq %rax, %rsi
movq %rbx, %rdi
callq 0xba4b
testl %eax, %eax
jne 0x9e067
movl 0x4(%r15), %edi
shlq $0x3, %rdi
callq 0x46a0
testq %rax, %rax
je 0x9e067
movq %rbx, 0x28(%rsp)
movl (%r15), %r12d
testq %r12, %r12
movq %rax, 0x8(%rsp)
je 0x9e167
movq 0x10(%r15), %r13
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %ebx, %ebx
movl %r14d, %eax
shrl $0x4, %eax
movl (%r13,%rax,4), %eax
movl %ebp, %ecx
andb $0x1e, %cl
shrl %cl, %eax
testb $0x3, %al
jne 0x9e15a
movq 0x18(%r15), %rax
movq 0x20(%r15), %rcx
movq (%rax,%r14,8), %rdi
movq (%rcx,%r14,8), %rax
movq 0x8(%rsp), %rcx
movq %rdi, (%rcx,%rax,8)
callq 0x41c0
addl %eax, %ebx
incl %ebx
incq %r14
addl $0x2, %ebp
cmpq %r14, %r12
jne 0x9e122
jmp 0x9e169
xorl %ebx, %ebx
leal 0x1c(%rbx), %eax
movslq %eax, %rdi
callq 0x46a0
testq %rax, %rax
je 0x9e1e2
movq 0x18(%rsp), %rcx
movq 0x10(%rcx), %rdx
movq %rdx, 0x10(%rax)
movups (%rcx), %xmm0
movups %xmm0, (%rax)
movl %ebx, 0x18(%rax)
cmpl $0x0, 0x4(%r15)
movq %rax, 0x30(%rsp)
movl $0x1c, %ebx
jle 0x9e1f6
xorl %r14d, %r14d
movq 0x8(%rsp), %r12
movq (%r12,%r14,8), %r13
movq %r13, %rdi
callq 0x41c0
movq %rax, %rbp
incl %eax
movslq %ebx, %rbx
movq 0x30(%rsp), %rcx
leaq (%rcx,%rbx), %rdi
movslq %eax, %rdx
movq %r13, %rsi
callq 0x43c0
addl %ebp, %ebx
incl %ebx
incq %r14
movslq 0x4(%r15), %rax
cmpq %rax, %r14
jl 0x9e1a8
jmp 0x9e1fb
movq 0x8(%rsp), %rdi
callq 0x45c0
movq 0x18(%rsp), %r13
jmp 0x9e067
movq 0x8(%rsp), %r12
movq %r12, %rdi
callq 0x45c0
movq 0x28(%rsp), %rdi
movl %ebx, %esi
movq 0x30(%rsp), %rdx
xorl %ecx, %ecx
callq 0xce0e
movq 0x50(%rsp), %rdi
callq 0x45c0
movq 0x18(%rsp), %rax
jmp 0x9e07b