// File: /workspace/github_c_makefile_star2_O1/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 0x210d3
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movl $0x1, %edi
movl $0x60, %esi
callq 0x4300
testq %rax, %rax
je 0x210be
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 0x2108c
movl %r14d, 0x38(%r15)
testq %r14, %r14
je 0x21042
movq %r14, %rdi
callq 0x4680
movq %rax, 0x40(%r15)
testq %rax, %rax
je 0x2108c
testq %rbx, %rbx
je 0x210c1
leaq 0x7a576(%rip), %rsi     # 0x9b5c4
movq %rbx, %rdi
callq 0x1447b
testq %rax, %rax
je 0x2108c
movq %rax, %r14
movq %rsp, %r12
movq %r14, %rdi
movl $0x2, %esi
movq %r12, %rdx
callq 0x15cc5
testl %eax, %eax
jle 0x211c3
movq 0x10(%rsp), %rsi
movq %r15, %rdi
callq 0x2042f
testl %eax, %eax
je 0x21061
jmp 0x2108f
xorl %r14d, %r14d
movq 0x10(%rsp), %rdi
callq 0x45c0
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
testq %r14, %r14
je 0x210b6
movq %r14, %rdi
callq 0x156e5
movq %r15, %rdi
callq 0x20e99
xorl %r15d, %r15d
movq %r15, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x41d(%rip), %rbp      # 0x20cbd
testq %rbx, %rbx
je 0x20fd9
movq %rbx, %rdi
callq 0x41d0
movq %rax, %r15
cmpl $0x7, %r15d
jl 0x21118
movl %r15d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rbx,%rax), %rsi
addq $-0x7, %rsi
leaq 0x752d8(%rip), %rdi     # 0x963e3
callq 0x4520
testl %eax, %eax
je 0x211b7
cmpl $0x8, %r15d
jl 0x2113e
movl %r15d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rbx,%rax), %rsi
addq $-0x8, %rsi
leaq 0x78d84(%rip), %rdi     # 0x99eb9
callq 0x4520
testl %eax, %eax
je 0x211b7
cmpl $0x4, %r15d
jl 0x2117e
movl %r15d, %eax
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
leaq (%rbx,%rax), %rsi
addq $-0x4, %rsi
leaq 0x75283(%rip), %rdi     # 0x963de
movq %rsi, 0x20(%rsp)
callq 0x4520
testl %eax, %eax
je 0x211b7
leaq 0x78204(%rip), %rdi     # 0x99374
movq 0x20(%rsp), %rsi
callq 0x4520
testl %eax, %eax
je 0x211ab
cmpl $0x7, %r15d
jl 0x20fd9
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
leaq (%rbx,%r15), %rsi
addq $-0x7, %rsi
leaq 0x781ce(%rip), %rdi     # 0x9936c
callq 0x4520
testl %eax, %eax
jne 0x20fd9
leaq 0x1d0(%rip), %rbp       # 0x21382
jmp 0x20fd9
leaq 0x5e(%rip), %rbp        # 0x2121c
jmp 0x20fd9
cmpl $-0x1, %eax
jl 0x2108f
movq %r14, %rdi
callq 0x156e5
testl %eax, %eax
je 0x211fd
leaq 0x78ce3(%rip), %rsi     # 0x99ec2
leaq 0x78ce8(%rip), %rdx     # 0x99ece
xorl %r14d, %r14d
movl $0x1, %edi
movq %rbx, %rcx
xorl %eax, %eax
callq 0x14378
jmp 0x2108f
movq 0x10(%rsp), %rdi
callq 0x45c0
xorps %xmm0, %xmm0
movaps %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
jmp 0x210c1