// File: /workspace/github_c_makefile_star2_O3/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, %r15
movl $0x1, %edi
movl $0x28, %esi
callq 0x42f0
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movq $0x0, 0x50(%rsp)
testq %rax, %rax
je 0x9ba9f
movq %rax, %r14
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r14)
movups (%rbx), %xmm0
movups %xmm0, (%r14)
testl %ebp, %ebp
movl %ebp, 0x28(%rsp)
jle 0x9b7b9
movl $0x21, %eax
subl %ebp, %eax
cltq
imulq $0x55555556, %rax, %rbx # imm = 0x55555556
movq %rbx, %rax
shrq $0x3f, %rax
shrq $0x20, %rbx
addl %eax, %ebx
movl $0x0, 0x1c(%rsp)
movl %ebp, 0x4(%rsp)
jmp 0x9b7ce
movl $0x2, 0x1c(%rsp)
movl $0x5, %ebx
movl $0xe, 0x4(%rsp)
movb $0x1, %al
movl %eax, 0x34(%rsp)
movq $0x0, 0x20(%rsp)
leaq 0x40(%rsp), %r12
movq $0x0, 0x8(%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
movq %r14, 0x10(%rsp)
movq %r15, %rdi
movl $0xa, %esi
movq %r12, %rdx
callq 0x8d610
testl %eax, %eax
js 0x9ba25
movq %rbx, 0x38(%rsp)
movl 0x10(%r14), %r12d
movslq 0x14(%r14), %r14
movq %rbp, %rbx
cmpl $0x0, 0x28(%rsp)
jle 0x9b8af
movq 0x50(%rsp), %rbp
movb (%rbp), %al
movsbl %al, %ecx
cmpl %ecx, %r12d
jne 0x9b8af
movq 0x10(%rsp), %rcx
movl (%rcx), %ecx
cmpl $0x2, %ecx
je 0x9b897
cmpl $0x1, %ecx
jne 0x9b8af
cmpb $0x40, %al
jne 0x9b8af
cmpb $0x53, 0x1(%rbp)
jne 0x9b8af
cmpb $0x51, 0x2(%rbp)
jne 0x9b8af
addq $0x3, %rbp
movq %rbp, %rdi
leaq 0x1bd96(%rip), %rsi     # 0xb75fd
callq 0x40d0
testq %rax, %rax
je 0x9b8af
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 0x9b8af
movl $0x8, %edx
movq %rbp, %rdi
leaq 0x1bd5c(%rip), %rsi     # 0xb7602
callq 0x4200
testl %eax, %eax
je 0x9b8f7
leaq 0x1(%rbx), %rbp
cmpq %r14, %rbx
jl 0x9b8c5
movq 0x50(%rsp), %rax
movsbl (%rax), %eax
cmpl %eax, %r12d
jne 0x9b929
movq 0x18(%r15), %rax
shlq $0x10, %rax
movzwl 0x10(%r15), %r13d
orq %rax, %r13
movq %r15, %rdi
movl $0xa, %esi
leaq 0x40(%rsp), %rdx
callq 0x8d610
movq %rbp, %rbx
testl %eax, %eax
jns 0x9b81d
jmp 0x9ba1b
addq $0x8, %rbp
movq %rbp, %rdi
leaq 0xecd2(%rip), %rsi      # 0xaa5d7
callq 0x40d0
testq %rax, %rax
je 0x9b8af
addq $0x6, %rax
movzbl (%rax), %ecx
cmpl $0x3d, %ecx
je 0x9b924
cmpl $0x20, %ecx
jne 0x9b875
incq %rax
jmp 0x9b913
testb $0x1, 0x34(%rsp)
je 0x9b984
cmpl $0x0, 0x28(%rsp)
movq 0x10(%rsp), %r14
movq 0x38(%rsp), %rbx
leaq 0x40(%rsp), %r12
jle 0x9b995
movq 0x8(%rsp), %rdx
testq %rdx, %rdx
movabsq $0x1900000000, %rax     # imm = 0x1900000000
cmoveq %rax, %rdx
leal (%rbx,%rbx,2), %ecx
addl 0x4(%rsp), %ecx
movl $0x1, %eax
shlq %cl, %rax
movq %rdx, 0x8(%rsp)
leaq 0x100(%rdx), %rcx
cmpq %rax, %rcx
jle 0x9b995
incl %ebx
shlq $0x3, %rax
jmp 0x9b977
movq 0x10(%rsp), %r14
movq 0x38(%rsp), %rbx
leaq 0x40(%rsp), %r12
jmp 0x9b9b7
xorl %edi, %edi
movl 0x1c(%rsp), %esi
movq %r13, %rdx
movl 0x4(%rsp), %ecx
movl %ebx, %r8d
callq 0xb602
movq %rax, 0x18(%r14)
testq %rax, %rax
je 0x9ba8d
movq %r14, %rdi
movq %r12, %rsi
leaq 0x60(%rsp), %rdx
movl $0x1, %ecx
callq 0x9b58d
testl %eax, %eax
js 0x9ba8d
movq 0x18(%r14), %rdi
movl 0x80(%rsp), %esi
movq 0x60(%rsp), %rdx
movq 0x68(%rsp), %rcx
movq 0x18(%r15), %rax
shlq $0x10, %rax
movzwl 0x10(%r15), %r8d
orq %rax, %r8
movq %rdi, 0x20(%rsp)
movl $0x1, %r9d
callq 0xbfe2
movl $0x0, 0x34(%rsp)
testl %eax, %eax
jns 0x9b7f5
jmp 0x9ba8d
movq 0x10(%rsp), %r14
movq 0x38(%rsp), %rbx
cmpl $-0x1, %eax
jne 0x9ba8d
cmpq $0x0, 0x20(%rsp)
jne 0x9ba55
xorl %edi, %edi
movl 0x1c(%rsp), %esi
movq %r13, %rdx
movl 0x4(%rsp), %ecx
movl %ebx, %r8d
callq 0xb602
movq %rax, 0x18(%r14)
movq %rax, 0x20(%rsp)
testq %rax, %rax
je 0x9ba8d
movq 0x20(%r14), %r12
testq %r12, %r12
jne 0x9ba6f
callq 0x6408
movq %rax, %r12
movq %rax, 0x20(%r14)
testq %rax, %rax
je 0x9ba8d
movq 0x18(%r15), %rax
shlq $0x10, %rax
movzwl 0x10(%r15), %esi
orq %rax, %rsi
movq 0x20(%rsp), %rdi
callq 0xb6f6
testl %eax, %eax
je 0x9bab3
movq 0x50(%rsp), %rdi
callq 0x45c0
movq %r14, %rdi
callq 0x9bbe9
xorl %eax, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x4(%r12), %ebx
leaq (,%rbx,8), %rdi
callq 0x46a0
testq %rax, %rax
je 0x9ba8d
movq %rbx, 0x28(%rsp)
movq %rax, 0x8(%rsp)
movl (%r12), %r15d
testq %r15, %r15
je 0x9bb30
movq 0x10(%r12), %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 0x9bb23
movq 0x18(%r12), %rax
movq 0x20(%r12), %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, %r15
jne 0x9bae9
jmp 0x9bb32
xorl %ebx, %ebx
leal 0x1c(%rbx), %eax
movslq %eax, %rdi
callq 0x46a0
testq %rax, %rax
je 0x9bbd5
movq %rax, %r15
movq 0x10(%rsp), %rcx
movq 0x10(%rcx), %rax
movq %rax, 0x10(%r15)
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movl %ebx, 0x18(%r15)
cmpl $0x0, 0x28(%rsp)
movq 0x8(%rsp), %rbp
movl $0x1c, %ebx
jle 0x9bba8
xorl %r14d, %r14d
movq (%rbp,%r14,8), %r12
movq %r12, %rdi
callq 0x41c0
movq %rax, %r13
incl %eax
movslq %ebx, %rbx
leaq (%r15,%rbx), %rdi
movslq %eax, %rdx
movq %r12, %rsi
callq 0x43c0
addl %r13d, %ebx
incl %ebx
incq %r14
cmpq %r14, 0x28(%rsp)
jne 0x9bb75
movq %rbp, %rdi
callq 0x45c0
movq 0x20(%rsp), %rdi
movl %ebx, %esi
movq %r15, %rdx
xorl %ecx, %ecx
callq 0xcb48
movq 0x50(%rsp), %rdi
callq 0x45c0
movq 0x10(%rsp), %rax
jmp 0x9baa1
movq 0x8(%rsp), %rdi
callq 0x45c0
movq 0x10(%rsp), %r14
jmp 0x9ba8d