// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/regidx.c
// Function: regidx_init
regidx_t *regidx_init(const char *fname, regidx_parse_f parser, regidx_free_f free_f, size_t payload_size, void *usr_dat)
{
    if ( !parser )
    {
        if ( !fname ) parser = regidx_parse_tab;
        else
        {
            int len = strlen(fname);
            if ( len>=7 && !strcasecmp(".bed.gz",fname+len-7) )
                parser = regidx_parse_bed;
            else if ( len>=8 && !strcasecmp(".bed.bgz",fname+len-8) )
                parser = regidx_parse_bed;
            else if ( len>=4 && !strcasecmp(".bed",fname+len-4) )
                parser = regidx_parse_bed;
            else if ( len>=4 && !strcasecmp(".vcf",fname+len-4) )
                parser = regidx_parse_vcf;
            else if ( len>=7 && !strcasecmp(".vcf.gz",fname+len-7) )
                parser = regidx_parse_vcf;
            else
                parser = regidx_parse_tab;
        }
    }

    kstring_t str = KS_INITIALIZE;
    htsFile *fp = NULL;
    int ret;
    regidx_t *idx = (regidx_t*) calloc(1,sizeof(regidx_t));
    if (!idx) return NULL;
    idx->free  = free_f;
    idx->parse = parser;
    idx->usr   = usr_dat;
    idx->seq2regs = khash_str2int_init();
    if (!idx->seq2regs) goto error;
    idx->payload_size = payload_size;
    if ( payload_size ) {
        idx->payload = malloc(payload_size);
        if (!idx->payload) goto error;
    }

    if ( !fname ) return idx;

    fp = hts_open(fname,"r");
    if ( !fp ) goto error;

    while ((ret = hts_getline(fp, KS_SEP_LINE, &str)) > 0 ) {
        if ( regidx_insert(idx, str.s) ) goto error;
    }
    if (ret < -1) goto error;

    ret = hts_close(fp);
    fp = NULL;
    if ( ret != 0 ) {
        hts_log_error("Close failed .. %s", fname);
        goto error;
    }
    ks_free(&str);
    return idx;

error:
    ks_free(&str);
    if ( fp ) hts_close(fp);
    regidx_destroy(idx);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, %r12
movq %rcx, %r14
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, %rbx
testq %rsi, %rsi
je 0x2078f
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movl $0x1, %edi
movl $0x60, %esi
callq 0x4300
testq %rax, %rax
je 0x2077a
movq %rax, %r15
movq %r13, 0x20(%rax)
movq %rbp, 0x28(%rax)
movq %r12, 0x30(%rax)
movl $0x1, %edi
movl $0x28, %esi
callq 0x4300
movq %rax, 0x10(%r15)
testq %rax, %rax
je 0x20747
movl %r14d, 0x38(%r15)
testq %r14, %r14
je 0x206fb
movq %r14, %rdi
callq 0x4680
movq %rax, 0x40(%r15)
testq %rax, %rax
je 0x20747
testq %rbx, %rbx
je 0x2077d
leaq 0x77ec4(%rip), %rsi     # 0x985cb
movq %rbx, %rdi
callq 0x13ee8
testq %rax, %rax
je 0x20747
movq %rax, %r14
leaq 0x10(%rsp), %r12
movq %r14, %rdi
movl $0x2, %esi
movq %r12, %rdx
callq 0x15732
testl %eax, %eax
jle 0x20882
movq 0x20(%rsp), %rsi
movq %r15, %rdi
callq 0x1fb65
testl %eax, %eax
je 0x2071c
jmp 0x2074a
xorl %r14d, %r14d
movq 0x20(%rsp), %rdi
callq 0x45c0
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
testq %r14, %r14
je 0x20772
movq %r14, %rdi
callq 0x1514a
movq %r15, %rdi
callq 0x2054c
xorl %r15d, %r15d
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x3e6(%rip), %rbp      # 0x203b0
testq %rbx, %rbx
je 0x20691
movq %rbx, %rdi
callq 0x41d0
cmpl $0x7, %eax
movq %rax, 0x8(%rsp)
jl 0x20805
movl %eax, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
leaq (%rbx,%r15), %rsi
addq $-0x7, %rsi
leaq 0x72c19(%rip), %rdi     # 0x933e3
callq 0x4520
leaq 0x101(%rip), %rbp       # 0x208d7
testl %eax, %eax
je 0x20691
movq 0x8(%rsp), %rax
cmpl $0x7, %eax
je 0x20814
leaq (%rbx,%r15), %rsi
addq $-0x8, %rsi
leaq 0x7678b(%rip), %rdi     # 0x96f82
callq 0x4520
testl %eax, %eax
jne 0x20814
jmp 0x20691
cmpl $0x4, %eax
jl 0x20876
movl %eax, %r15d
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
leaq (%rbx,%r15), %rbp
addq $-0x4, %rbp
leaq 0x72bbb(%rip), %rdi     # 0x933de
movq %rbp, %rsi
callq 0x4520
testl %eax, %eax
je 0x208bc
leaq 0x75bda(%rip), %rdi     # 0x96414
movq %rbp, %rsi
callq 0x4520
leaq 0x1c6(%rip), %rbp       # 0x20a0f
testl %eax, %eax
je 0x20691
cmpl $0x7, 0x8(%rsp)
jl 0x20876
addq %rbx, %r15
addq $-0x7, %r15
leaq 0x75ba6(%rip), %rdi     # 0x9640c
movq %r15, %rsi
callq 0x4520
testl %eax, %eax
je 0x20691
leaq -0x4cd(%rip), %rbp      # 0x203b0
jmp 0x20691
cmpl $-0x1, %eax
jl 0x2074a
movq %r14, %rdi
callq 0x1514a
testl %eax, %eax
je 0x208c8
leaq 0x766ed(%rip), %rsi     # 0x96f8b
leaq 0x766f2(%rip), %rdx     # 0x96f97
xorl %r14d, %r14d
movl $0x1, %edi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x13de5
jmp 0x2074a
leaq 0x14(%rip), %rbp        # 0x208d7
jmp 0x20691
movq 0x20(%rsp), %rdi
callq 0x45c0
jmp 0x2077d