// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/synced_bcf_reader.c
// Function: bcf_sr_regions_init
bcf_sr_regions_t *bcf_sr_regions_init(const char *regions, int is_file, int ichr, int ifrom, int ito)
{
    bcf_sr_regions_t *reg;
    if ( !is_file )
    {
        reg = _regions_init_string(regions);
        _regions_sort_and_merge(reg);
        return reg;
    }

    reg = bcf_sr_regions_alloc();
    if ( !reg ) return NULL;

    reg->file = hts_open(regions, "rb");
    if ( !reg->file )
    {
        hts_log_error("Could not open file: %s", regions);
        free(reg);
        return NULL;
    }

    reg->tbx = tbx_index_load3(regions, NULL, HTS_IDX_SAVE_REMOTE|HTS_IDX_SILENT_FAIL);
    if ( !reg->tbx )
    {
        size_t iline = 0;
        int len = strlen(regions);
        int is_bed  = strcasecmp(".bed",regions+len-4) ? 0 : 1;
        if ( !is_bed && !strcasecmp(".bed.gz",regions+len-7) ) is_bed = 1;

        if ( reg->file->format.format==vcf ) ito = 1;

        // read the whole file, tabix index is not present
        while ( hts_getline(reg->file, KS_SEP_LINE, &reg->line) > 0 )
        {
            iline++;
            char *chr, *chr_end;
            hts_pos_t from, to;
            int ret;
            ret = _regions_parse_line(reg->line.s, ichr,ifrom,abs(ito), &chr,&chr_end,&from,&to);
            if ( ret < 0 )
            {
                if ( ito<0 )
                    ret = _regions_parse_line(reg->line.s, ichr,ifrom,ifrom, &chr,&chr_end,&from,&to);
                if ( ret<0 )
                {
                    hts_log_error("Could not parse %zu-th line of file %s, using the columns %d,%d[,%d]",
                        iline, regions,ichr+1,ifrom+1,ito+1);
                    hts_close(reg->file); reg->file = NULL; free(reg);
                    return NULL;
                }
                ito = ifrom;
            }
            else if ( ito<0 )
                ito = abs(ito);
            if ( !ret ) continue;
            if ( is_bed ) from++;
            *chr_end = 0;
            _regions_add(reg, chr, from, to);
            *chr_end = '\t';
        }
        hts_close(reg->file); reg->file = NULL;
        if ( !reg->nseqs ) { free(reg); return NULL; }
        _regions_sort_and_merge(reg);
        return reg;
    }

    reg->seq_names = (char**) tbx_seqnames(reg->tbx, &reg->nseqs);
    if ( !reg->seq_hash )
        reg->seq_hash = khash_str2int_init();
    int i;
    for (i=0; i<reg->nseqs; i++)
    {
        khash_str2int_set(reg->seq_hash,reg->seq_names[i],i);
    }
    reg->fname  = strdup(regions);
    reg->is_bin = 1;
    return reg;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r8d, %r13d
movq %rcx, 0x28(%rsp)
movl %edx, 0x14(%rsp)
movl %esi, %ebp
movq %rdi, %r14
callq 0x21c97
movq %rax, %r15
movq %rax, %rbx
testl %ebp, %ebp
je 0x21104
testq %r15, %r15
je 0x2152e
leaq 0x69f44(%rip), %rsi     # 0x8afb7
movq %r14, %rdi
callq 0x87fb
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x2134e
movq %rax, %rbp
pushq $0x3
popq %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x24f6d
movq %rax, (%rbx)
testq %rax, %rax
je 0x2137d
movq %r14, %r12
addq $0x98, %r15
movq %rax, %rdi
movq %r15, %rsi
callq 0x250ac
movq %rax, 0x90(%rbx)
cmpq $0x0, 0x88(%rbx)
jne 0x210d6
callq 0x23246
movq %rax, 0x88(%rbx)
xorl %r14d, %r14d
movslq (%r15), %rax
cmpq %rax, %r14
jge 0x21336
movq 0x88(%rbx), %rdi
movq 0x90(%rbx), %rax
movq (%rax,%r14,8), %rsi
movl %r14d, %edx
callq 0x2347b
incq %r14
jmp 0x210d9
testq %r15, %r15
je 0x2136e
xorps %xmm0, %xmm0
leaq 0x38(%rsp), %r13
movups %xmm0, 0x8(%r13)
leaq 0x8(%rsp), %rax
movq %r14, (%rax)
pushq $0x1
popq %r15
pushq $-0x1
popq %r12
movabsq $0x400100000000001, %rcx # imm = 0x400100000000001
movq %r14, 0x18(%rsp)
andq $0x0, 0x38(%rsp)
movb (%r14), %al
cmpb $0x7b, %al
jne 0x2116d
movb $0x7b, %al
movq %r15, %rsi
testb %al, %al
je 0x212fd
movzbl %al, %eax
cmpl $0x7d, %eax
je 0x21194
leaq (%r14,%rsi), %rax
movq %rax, 0x8(%rsp)
movb (%r14,%rsi), %al
incq %rsi
jmp 0x2114b
movq %r15, %rsi
cmpb $0x3a, %al
ja 0x2117d
movzbl %al, %eax
btq %rax, %rcx
jb 0x2118f
leaq (%r14,%rsi), %rax
movq %rax, 0x8(%rsp)
movb (%r14,%rsi), %al
incq %rsi
jmp 0x21170
decq %rsi
jmp 0x211a4
leaq (%r14,%rsi), %rax
movq %rax, 0x8(%rsp)
incq %r14
addq $-0x2, %rsi
movq %r14, %rdi
movq %r13, %rdx
callq 0x2386c
movq 0x8(%rsp), %r14
movzbl (%r14), %eax
testl %eax, %eax
je 0x21243
cmpl $0x2c, %eax
je 0x21243
cmpl $0x3a, %eax
jne 0x21542
movq %r15, %r12
movq %r13, %r15
incq %r14
movq %r14, %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
callq 0xd23e
movq 0x8(%rsp), %rbp
cmpq %rbp, %r14
je 0x21542
movq %rax, %r13
movzbl (%rbp), %eax
testl %eax, %eax
movq 0x18(%rsp), %r14
je 0x21212
cmpl $0x2d, %eax
je 0x21285
cmpl $0x2c, %eax
jne 0x21547
movq 0x48(%rsp), %rsi
movq %rbx, %rdi
movq %r13, %rdx
movq %r13, %rcx
callq 0x21cc7
movq 0x8(%rsp), %r14
movq %r15, %r13
movq %r12, %r15
pushq $-0x1
popq %r12
movabsq $0x400100000000001, %rcx # imm = 0x400100000000001
jmp 0x21139
cmpq $0x0, 0x38(%rsp)
je 0x21266
movq 0x48(%rsp), %rsi
movq %rbx, %rdi
movq %r12, %rdx
movq %r12, %rcx
callq 0x21cc7
movq 0x8(%rsp), %r14
movb (%r14), %al
movabsq $0x400100000000001, %rcx # imm = 0x400100000000001
testb %al, %al
je 0x21553
incq %r14
movq %r14, 0x8(%rsp)
jmp 0x21139
incq %rbp
movq %rbp, 0x8(%rsp)
movq %rbp, %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
callq 0xd23e
movq 0x8(%rsp), %rcx
movzbl (%rcx), %edx
cmpl $0x2c, %edx
je 0x212b1
testl %edx, %edx
jne 0x21547
cmpq %rcx, %rbp
movabsq $0xffffffffffe, %rcx    # imm = 0xFFFFFFFFFFE
cmoveq %rcx, %rax
movq 0x48(%rsp), %rbp
movq %rbx, %rdi
movq %rbp, %rsi
movq %r13, %rdx
movq %rax, %rcx
callq 0x21cc7
movq 0x8(%rsp), %r14
cmpb $0x0, (%r14)
movq %r15, %r13
movq %r12, %r15
pushq $-0x1
popq %r12
movabsq $0x400100000000001, %rcx # imm = 0x400100000000001
jne 0x21139
jmp 0x2132c
leaq 0x69f52(%rip), %rdx     # 0x8b256
movq 0x18(%rsp), %r14
leaq 0x69f31(%rip), %rsi     # 0x8b241
pushq $0x1
popq %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x86fa
movq %rbx, %rdi
callq 0x20f62
movq 0x48(%rsp), %rbp
xorl %ebx, %ebx
movq %rbp, %rdi
callq 0x45d0
jmp 0x21370
movq %r12, %rdi
callq 0x4950
movq %rax, 0x30(%rbx)
movl $0x1, 0x38(%rbx)
jmp 0x21530
leaq 0x69c65(%rip), %rsi     # 0x8afba
leaq 0x69c72(%rip), %rdx     # 0x8afce
pushq $0x1
popq %rdi
movq %r14, %rcx
xorl %eax, %eax
callq 0x86fa
jmp 0x21526
xorl %ebx, %ebx
movq %rbx, %rdi
callq 0x21e55
jmp 0x21530
movq %r14, %rdi
callq 0x41c0
movq %r14, %r12
movslq %eax, %r14
leaq (%r12,%r14), %rsi
addq $-0x4, %rsi
leaq 0x69c4c(%rip), %rdi     # 0x8afe6
callq 0x4520
testl %eax, %eax
movq %r12, 0x18(%rsp)
je 0x213c9
addq %r12, %r14
addq $-0x7, %r14
leaq 0x69c35(%rip), %rdi     # 0x8afeb
movq %r14, %rsi
callq 0x4520
testl %eax, %eax
setne %al
movl %eax, 0x24(%rsp)
jmp 0x213d1
movl $0x0, 0x24(%rsp)
cmpl $0x8, 0x4c(%rbp)
pushq $0x1
popq %rax
cmovel %eax, %r13d
addq $0x10, %r15
pushq $0x1
popq %r14
movq %rbp, %rdi
pushq $0x2
popq %rsi
movq %r15, %rdx
callq 0x9f6c
testl %eax, %eax
jle 0x214c7
movq 0x20(%rbx), %rdi
movl %r13d, %r12d
negl %r12d
cmovsl %r13d, %r12d
movl 0x14(%rsp), %esi
movq 0x28(%rsp), %rdx
movl %r12d, %ecx
leaq 0x38(%rsp), %r8
leaq 0x8(%rsp), %r9
leaq 0x50(%rsp), %rax
pushq %rax
leaq 0x38(%rsp), %rax
pushq %rax
callq 0x2327f
addq $0x10, %rsp
testl %eax, %eax
js 0x21440
testl %r13d, %r13d
cmovnsl %r13d, %r12d
jmp 0x2147f
testl %r13d, %r13d
jns 0x214e4
movq 0x20(%rbx), %rdi
movl 0x14(%rsp), %esi
movq 0x28(%rsp), %r12
movl %r12d, %edx
movl %r12d, %ecx
leaq 0x38(%rsp), %r8
leaq 0x8(%rsp), %r9
leaq 0x50(%rsp), %rax
pushq %rax
leaq 0x38(%rsp), %rax
pushq %rax
callq 0x2327f
addq $0x10, %rsp
testl %eax, %eax
js 0x214e4
testl %eax, %eax
je 0x214b8
movq 0x30(%rsp), %rdx
cmpb $0x0, 0x24(%rsp)
jne 0x21497
incq %rdx
movq %rdx, 0x30(%rsp)
movq 0x8(%rsp), %r13
movb $0x0, (%r13)
movq 0x38(%rsp), %rsi
movq 0x50(%rsp), %rcx
movq %rbx, %rdi
callq 0x21cc7
movb $0x9, (%r13)
movq 0x28(%rbx), %rbp
incq %r14
movl %r12d, %r13d
jmp 0x213e4
movq 0x28(%rbx), %rdi
callq 0x99d1
andq $0x0, 0x28(%rbx)
cmpl $0x0, 0x98(%rbx)
jne 0x21370
jmp 0x21526
movl 0x14(%rsp), %r9d
incl %r9d
movq 0x28(%rsp), %r10
incl %r10d
incl %r13d
leaq 0x69abc(%rip), %rsi     # 0x8afba
leaq 0x69aee(%rip), %rdx     # 0x8aff3
pushq $0x1
popq %rdi
movq %r14, %rcx
movq 0x18(%rsp), %r8
xorl %eax, %eax
pushq %r13
pushq %r10
callq 0x86fa
popq %rax
popq %rcx
movq 0x28(%rbx), %rdi
callq 0x99d1
movq %rbx, %rdi
callq 0x45d0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rsp), %r14
leaq 0x69d40(%rip), %rdx     # 0x8b28e
jmp 0x21309
movq 0x48(%rsp), %rbp
jmp 0x2132c