// File: /workspace/github_c_makefile_star2_O2/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, %r14
movl %esi, %ebp
movq %rdi, %r15
pushq $0x1
popq %rdi
pushq $0x28
popq %rsi
callq 0x42f0
andq $0x0, 0x50(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
testq %rax, %rax
je 0x77fac
movq %rax, %rbx
movq 0x10(%r14), %rax
movq %rax, 0x10(%rbx)
movups (%r14), %xmm0
movups %xmm0, (%rbx)
testl %ebp, %ebp
movl %ebp, 0x18(%rsp)
jle 0x77d1a
pushq $0x21
popq %rax
subl %ebp, %eax
pushq $0x3
popq %rcx
cltd
idivl %ecx
movq %rax, 0x28(%rsp)
movl $0x0, 0x24(%rsp)
movl %ebp, 0xc(%rsp)
jmp 0x77d30
pushq $0x2
popq %rax
movl %eax, 0x24(%rsp)
pushq $0x5
popq %rax
movq %rax, 0x28(%rsp)
pushq $0xe
popq %rax
movl %eax, 0xc(%rsp)
movb $0x1, %cl
movq $0x0, 0x30(%rsp)
movq $0x0, 0x10(%rsp)
xorl %r14d, %r14d
xorl %r13d, %r13d
movl %ecx, 0x38(%rsp)
movq %r14, %r12
movq %r15, %rdi
pushq $0xa
popq %rsi
leaq 0x40(%rsp), %rdx
callq 0x6c67b
testl %eax, %eax
js 0x77f30
movl 0x10(%rbx), %ebp
cmpl $0x0, 0x18(%rsp)
jle 0x77df2
movq 0x50(%rsp), %r14
movb (%r14), %al
movsbl %al, %ecx
cmpl %ecx, %ebp
jne 0x77df2
movl (%rbx), %ecx
cmpl $0x2, %ecx
je 0x77ddc
cmpl $0x1, %ecx
jne 0x77df2
cmpb $0x40, %al
jne 0x77df2
cmpb $0x53, 0x1(%r14)
jne 0x77df2
cmpb $0x51, 0x2(%r14)
jne 0x77df2
addq $0x3, %r14
movq %r14, %rdi
leaq 0xc796(%rip), %rsi      # 0x84544
callq 0x40d0
testq %rax, %rax
je 0x77df2
addq $0x4, %rax
movq %rax, %rdi
xorl %esi, %esi
pushq $0xa
popq %rdx
callq 0x40a0
movq 0x10(%rsp), %rcx
cmpq %rax, %rcx
cmovleq %rax, %rcx
movq %rcx, 0x10(%rsp)
jmp 0x77df2
movq %r14, %rdi
leaq 0x19e97(%rip), %rsi     # 0x91c7d
pushq $0x8
popq %rdx
callq 0x4200
testl %eax, %eax
je 0x77e21
leaq 0x1(%r12), %r14
movslq 0x14(%rbx), %rax
cmpq %rax, %r12
jl 0x77e0c
movq 0x50(%rsp), %rax
movsbl (%rax), %eax
cmpl %eax, %ebp
jne 0x77e53
movq 0x18(%r15), %rax
shlq $0x10, %rax
movzwl 0x10(%r15), %r13d
orq %rax, %r13
jmp 0x77d4e
addq $0x8, %r14
movq %r14, %rdi
leaq 0xd778(%rip), %rsi      # 0x855a7
callq 0x40d0
testq %rax, %rax
je 0x77df2
addq $0x6, %rax
movzbl (%rax), %ecx
cmpl $0x3d, %ecx
je 0x77e4e
cmpl $0x20, %ecx
jne 0x77dbc
incq %rax
jmp 0x77e3d
testb $0x1, 0x38(%rsp)
je 0x77ea8
movl 0x18(%rsp), %eax
testl %eax, %eax
pushq $0x1
popq %rbp
jle 0x77ead
movq 0x10(%rsp), %rdx
testq %rdx, %rdx
movabsq $0x1900000000, %rax     # imm = 0x1900000000
cmoveq %rax, %rdx
movq 0x28(%rsp), %r8
leal (%r8,%r8,2), %ecx
addl 0xc(%rsp), %ecx
pushq $0x1
popq %rax
shlq %cl, %rax
movq %rdx, 0x10(%rsp)
leaq 0x100(%rdx), %rcx
cmpq %rax, %rcx
jle 0x77eb2
incl %r8d
shlq $0x3, %rax
jmp 0x77e9a
pushq $0x1
popq %rbp
jmp 0x77ed6
movq 0x28(%rsp), %r8
xorl %edi, %edi
movl 0x24(%rsp), %esi
movq %r13, %rdx
movl 0xc(%rsp), %ecx
movq %r8, 0x28(%rsp)
callq 0xa1f3
movq %rax, 0x18(%rbx)
testq %rax, %rax
je 0x77f9a
movq %rbx, %rdi
leaq 0x40(%rsp), %rsi
leaq 0x60(%rsp), %rdx
movl %ebp, %ecx
callq 0x77bc2
testl %eax, %eax
js 0x77f9a
movq 0x18(%rbx), %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, 0x30(%rsp)
movl %ebp, %r9d
callq 0xa97b
xorl %ecx, %ecx
testl %eax, %eax
jns 0x77d4a
jmp 0x77f9a
cmpl $-0x1, %eax
jne 0x77f9a
cmpq $0x0, 0x30(%rsp)
jne 0x77f62
xorl %edi, %edi
movl 0x24(%rsp), %esi
movq %r13, %rdx
movl 0xc(%rsp), %ecx
movq 0x28(%rsp), %r8
callq 0xa1f3
movq %rax, 0x18(%rbx)
movq %rax, 0x30(%rsp)
testq %rax, %rax
je 0x77f9a
movq 0x20(%rbx), %r12
testq %r12, %r12
jne 0x77f7c
callq 0x5fec
movq %rax, %r12
movq %rax, 0x20(%rbx)
testq %rax, %rax
je 0x77f9a
movq 0x18(%r15), %rax
shlq $0x10, %rax
movzwl 0x10(%r15), %esi
orq %rax, %rsi
movq 0x30(%rsp), %rdi
callq 0xa2d1
testl %eax, %eax
je 0x77fc3
movq 0x50(%rsp), %rdi
callq 0x45c0
movq %rbx, %rdi
callq 0x780f1
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0x4(%r12), %eax
movq %rax, 0x38(%rsp)
leaq (,%rax,8), %rdi
callq 0x46a0
movq %rax, 0x18(%rsp)
testq %rax, %rax
je 0x77f9a
movl (%r12), %r15d
xorl %ebp, %ebp
xorl %r14d, %r14d
xorl %r13d, %r13d
cmpq %r14, %r15
je 0x7803c
movq 0x10(%r12), %rax
movl %r14d, %ecx
shrl $0x4, %ecx
movl (%rax,%rcx,4), %eax
movl %ebp, %ecx
andb $0x1e, %cl
shrl %cl, %eax
testb $0x3, %al
jne 0x78034
movq 0x18(%r12), %rax
movq 0x20(%r12), %rcx
movq (%rax,%r14,8), %rdi
movq (%rcx,%r14,8), %rax
movq 0x18(%rsp), %rcx
movq %rdi, (%rcx,%rax,8)
callq 0x41c0
addl %eax, %r13d
incl %r13d
incq %r14
addl $0x2, %ebp
jmp 0x77ff0
leal 0x1c(%r13), %eax
movslq %eax, %rdi
callq 0x46a0
testq %rax, %rax
je 0x780e2
movq 0x10(%rbx), %rcx
movq %rcx, 0x10(%rax)
movups (%rbx), %xmm0
movups %xmm0, (%rax)
movq %rax, 0x10(%rsp)
movl %r13d, 0x18(%rax)
xorl %r14d, %r14d
movq 0x38(%rsp), %r15
testl %r15d, %r15d
cmovlel %r14d, %r15d
pushq $0x1c
popq %rbp
cmpq %r14, %r15
je 0x780b6
movq 0x18(%rsp), %rax
movq (%rax,%r14,8), %r12
movq %r12, %rdi
callq 0x41c0
movq %rax, %r13
incl %eax
movslq %ebp, %rbp
movq 0x10(%rsp), %rcx
leaq (%rcx,%rbp), %rdi
movslq %eax, %rdx
movq %r12, %rsi
callq 0x43c0
addl %r13d, %ebp
incl %ebp
incq %r14
jmp 0x7807a
movq 0x18(%rsp), %rdi
callq 0x45c0
movq 0x30(%rsp), %rdi
movl %ebp, %esi
movq 0x10(%rsp), %rdx
xorl %ecx, %ecx
callq 0xb35e
movq 0x50(%rsp), %rdi
callq 0x45c0
jmp 0x77fae
movq 0x18(%rsp), %rdi
callq 0x45c0
jmp 0x77f9a