// File: /workspace/github_c_makefile_star2_O0/zhou-lab[P]tbmate/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
                parser = regidx_parse_tab;
        }
    }

    regidx_t *idx = (regidx_t*) calloc(1,sizeof(regidx_t));
    idx->free  = free_f;
    idx->parse = parser;
    idx->usr   = usr_dat;
    idx->seq2regs = khash_str2int_init();
    idx->rid_prev   = -1;
    idx->start_prev = -1;
    idx->end_prev   = -1;
    idx->payload_size = payload_size;
    if ( payload_size ) idx->payload = malloc(payload_size);

    if ( !fname ) return idx;
    
    kstring_t str = {0,0,0};

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

    while ( hts_getline(fp, KS_SEP_LINE, &str) > 0 )
    {
        if ( regidx_insert(idx, str.s) ) goto error;
    }
    regidx_insert(idx, NULL);
    
    free(str.s);
    hts_close(fp);
    return idx;

error:
    free(str.s);
    if ( fp ) hts_close(fp);
    regidx_destroy(idx);
    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x16d66
cmpq $0x0, -0x10(%rbp)
jne 0x16cae
leaq 0x22b(%rip), %rax       # 0x16ed0
movq %rax, -0x18(%rbp)
jmp 0x16d64
movq -0x10(%rbp), %rdi
callq 0x3380
movl %eax, -0x34(%rbp)
cmpl $0x7, -0x34(%rbp)
jl 0x16ced
movq -0x10(%rbp), %rsi
movslq -0x34(%rbp), %rax
addq %rax, %rsi
addq $-0x7, %rsi
leaq 0x5fe64(%rip), %rdi     # 0x76b3a
callq 0x31d0
cmpl $0x0, %eax
jne 0x16ced
leaq 0x409(%rip), %rax       # 0x170f0
movq %rax, -0x18(%rbp)
jmp 0x16d62
cmpl $0x8, -0x34(%rbp)
jl 0x16d20
movq -0x10(%rbp), %rsi
movslq -0x34(%rbp), %rax
addq %rax, %rsi
addq $-0x8, %rsi
leaq 0x5fe39(%rip), %rdi     # 0x76b42
callq 0x31d0
cmpl $0x0, %eax
jne 0x16d20
leaq 0x3d6(%rip), %rax       # 0x170f0
movq %rax, -0x18(%rbp)
jmp 0x16d60
cmpl $0x4, -0x34(%rbp)
jl 0x16d53
movq -0x10(%rbp), %rsi
movslq -0x34(%rbp), %rax
addq %rax, %rsi
addq $-0x4, %rsi
leaq 0x5fe0f(%rip), %rdi     # 0x76b4b
callq 0x31d0
cmpl $0x0, %eax
jne 0x16d53
leaq 0x3a3(%rip), %rax       # 0x170f0
movq %rax, -0x18(%rbp)
jmp 0x16d5e
leaq 0x176(%rip), %rax       # 0x16ed0
movq %rax, -0x18(%rbp)
jmp 0x16d60
jmp 0x16d62
jmp 0x16d64
jmp 0x16d66
movl $0x1, %edi
movl $0x68, %esi
callq 0x36b0
movq %rax, -0x40(%rbp)
movq -0x20(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x30(%rbp), %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x30(%rax)
callq 0x172f0
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x40(%rbp), %rax
movl $0xffffffff, 0x50(%rax) # imm = 0xFFFFFFFF
movq -0x40(%rbp), %rax
movl $0xffffffff, 0x54(%rax) # imm = 0xFFFFFFFF
movq -0x40(%rbp), %rax
movl $0xffffffff, 0x58(%rax) # imm = 0xFFFFFFFF
movq -0x28(%rbp), %rax
movl %eax, %ecx
movq -0x40(%rbp), %rax
movl %ecx, 0x5c(%rax)
cmpq $0x0, -0x28(%rbp)
je 0x16df6
movq -0x28(%rbp), %rdi
callq 0x3250
movq %rax, %rcx
movq -0x40(%rbp), %rax
movq %rcx, 0x60(%rax)
cmpq $0x0, -0x10(%rbp)
jne 0x16e0a
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x16eb9
leaq -0x58(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x3090
movq -0x10(%rbp), %rdi
leaq 0x625fe(%rip), %rsi     # 0x79423
callq 0xeba0
movq %rax, -0x60(%rbp)
cmpq $0x0, -0x60(%rbp)
jne 0x16e37
jmp 0x16e8f
jmp 0x16e39
movq -0x60(%rbp), %rdi
movl $0x2, %esi
leaq -0x58(%rbp), %rdx
callq 0xfe70
cmpl $0x0, %eax
jle 0x16e66
movq -0x40(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x16550
cmpl $0x0, %eax
je 0x16e64
jmp 0x16e8f
jmp 0x16e39
movq -0x40(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x16550
movq -0x48(%rbp), %rdi
callq 0x3370
movq -0x60(%rbp), %rdi
callq 0xf950
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x16eb9
movq -0x48(%rbp), %rdi
callq 0x3370
cmpq $0x0, -0x60(%rbp)
je 0x16ea8
movq -0x60(%rbp), %rdi
callq 0xf950
movq -0x40(%rbp), %rdi
callq 0x17300
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)