// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/synced_bcf_reader.c
// Function: bcf_sr_regions_next
int bcf_sr_regions_next(bcf_sr_regions_t *reg)
{
    if ( reg->iseq<0 ) return -1;
    reg->start = reg->end = -1;
    reg->nals = 0;

    // using in-memory regions
    if ( reg->regs )
    {
        while ( reg->iseq < reg->nseqs )
        {
            if ( advance_creg(&reg->regs[reg->iseq])==0 ) break;    // a valid record was found
            reg->iseq++;
        }
        if ( reg->iseq >= reg->nseqs ) { reg->iseq = -1; return -1; } // no more regions left
        region1_t *creg = &reg->regs[reg->iseq].regs[reg->regs[reg->iseq].creg];
        reg->start = creg->start;
        reg->end   = creg->end;
        return 0;
    }

    // reading from tabix
    char *chr, *chr_end;
    int ichr = 0, ifrom = 1, ito = 2, is_bed = 0;
    hts_pos_t from, to;
    if ( reg->tbx )
    {
        ichr   = reg->tbx->conf.sc-1;
        ifrom  = reg->tbx->conf.bc-1;
        ito    = reg->tbx->conf.ec-1;
        if ( ito<0 ) ito = ifrom;
        is_bed = reg->tbx->conf.preset==TBX_UCSC ? 1 : 0;
    }

    int ret = 0;
    while ( !ret )
    {
        if ( reg->itr )
        {
            // tabix index present, reading a chromosome block
            ret = tbx_itr_next(reg->file, reg->tbx, reg->itr, &reg->line);
            if ( ret<0 ) { reg->iseq = -1; return -1; }
        }
        else
        {
            if ( reg->is_bin )
            {
                // Waited for seek which never came. Reopen in text mode and stream
                // through the regions, otherwise hts_getline would fail
                hts_close(reg->file);
                reg->file = hts_open(reg->fname, "r");
                if ( !reg->file )
                {
                    hts_log_error("Could not open file: %s", reg->fname);
                    reg->file = NULL;
                    bcf_sr_regions_destroy(reg);
                    return -1;
                }
                reg->is_bin = 0;
            }

            // tabix index absent, reading the whole file
            ret = reg->file ? hts_getline(reg->file, KS_SEP_LINE, &reg->line) : -1;
            if ( ret<0 ) { reg->iseq = -1; return -1; }
        }
        ret = _regions_parse_line(reg->line.s, ichr,ifrom,ito, &chr,&chr_end,&from,&to);
        if ( ret<0 )
        {
            hts_log_error("Could not parse the file %s, using the columns %d,%d,%d",
                reg->fname,ichr+1,ifrom+1,ito+1);
            return -1;
        }
    }
    if ( is_bed ) from++;

    *chr_end = 0;
    if ( khash_str2int_get(reg->seq_hash, chr, &reg->iseq)<0 )
    {
        hts_log_error("Broken tabix index? The sequence \"%s\" not in dictionary [%s]",
            chr, reg->line.s);
        exit(1);
    }
    *chr_end = '\t';

    reg->start = from - 1;
    reg->end   = to - 1;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmpl $0x0, 0x9c(%rdi)
js 0x2cfd0
movq %rdi, %rbx
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0xa0(%rdi)
movl $0x0, 0x60(%rdi)
movq 0x80(%rdi), %rax
testq %rax, %rax
je 0x2cfdf
movslq 0x98(%rbx), %rsi
movslq 0x9c(%rbx), %rdx
cmpl %esi, %edx
setl %dil
jge 0x2cfc1
leaq (%rdx,%rdx,2), %r8
leaq (%rax,%r8,8), %r8
movslq 0x10(%r8), %r9
movslq 0x8(%r8), %r10
leal 0x1(%r9), %r11d
cmpl %r11d, %r10d
cmovgl %r10d, %r11d
movq %r9, %r14
shlq $0x4, %r14
addq $0x18, %r14
movq %r9, %r12
incq %r12
cmpq %r10, %r12
jge 0x2cfab
movq %r12, %r15
movq (%r8), %r13
movq -0x8(%r13,%r14), %rbp
incl %r9d
leaq 0x10(%r14), %rcx
incq %r12
cmpq (%r13,%r14), %rbp
movq %rcx, %r14
jg 0x2cf79
movl %r9d, 0x10(%r8)
cmpq %r10, %r15
jge 0x2cfaf
jmp 0x2d17d
movl %r11d, 0x10(%r8)
incq %rdx
movl %edx, 0x9c(%rbx)
cmpq %rsi, %rdx
setl %dil
jne 0x2cf4d
movl $0xffffffff, 0x9c(%rbx) # imm = 0xFFFFFFFF
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rcx
xorl %eax, %eax
testq %rcx, %rcx
je 0x2d00f
movl 0x4(%rcx), %ebp
decl %ebp
movl 0x8(%rcx), %r14d
decl %r14d
movl 0xc(%rcx), %edx
leal -0x1(%rdx), %r15d
testl %edx, %edx
cmovlel %r14d, %r15d
cmpl $0x10000, (%rcx)        # imm = 0x10000
setne 0x8(%rsp)
jmp 0x2d022
movb $0x1, 0x8(%rsp)
movl $0x2, %r15d
movl $0x1, %r14d
xorl %ebp, %ebp
leaq 0x10(%rbx), %r12
leaq 0x48(%rsp), %r13
testl %eax, %eax
jne 0x2d118
cmpq $0x0, 0x8(%rbx)
je 0x2d057
movq 0x28(%rbx), %rdi
callq 0xb57d
movq (%rbx), %rcx
movq 0x8(%rbx), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0x10676
jmp 0x2d0a4
cmpl $0x0, 0x38(%rbx)
je 0x2d08a
movq 0x28(%rbx), %rdi
callq 0xb1a1
movq 0x30(%rbx), %rdi
leaq 0x873ae(%rip), %rsi     # 0xb441f
callq 0x9f37
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x2d297
movl $0x0, 0x38(%rbx)
movq 0x28(%rbx), %rdi
testq %rdi, %rdi
je 0x2cfc1
movl $0x2, %esi
movq %r12, %rdx
callq 0xb781
testl %eax, %eax
js 0x2cfc1
movq 0x20(%rbx), %rdi
movl %ebp, %esi
movl %r14d, %edx
movl %r15d, %ecx
leaq 0x50(%rsp), %r8
movq %r13, %r9
leaq 0x40(%rsp), %rax
pushq %rax
leaq 0x30(%rsp), %rax
pushq %rax
callq 0x2cb1d
addq $0x10, %rsp
testl %eax, %eax
jns 0x2d02b
movq 0x30(%rbx), %rcx
incl %ebp
incl %r14d
incl %r15d
subq $0x8, %rsp
leaq 0x87fb4(%rip), %rsi     # 0xb50a8
leaq 0x87fc1(%rip), %rdx     # 0xb50bc
movl $0x1, %edi
movl %ebp, %r8d
movl %r14d, %r9d
xorl %eax, %eax
pushq %r15
callq 0x9e34
addq $0x10, %rsp
jmp 0x2cfcb
cmpb $0x0, 0x8(%rsp)
jne 0x2d124
incq 0x28(%rsp)
movq 0x48(%rsp), %rdx
movb $0x0, (%rdx)
movq 0x88(%rbx), %rsi
movq 0x50(%rsp), %r9
testq %rsi, %rsi
je 0x2d2ca
movl (%rsi), %eax
testl %eax, %eax
je 0x2d1b0
leal -0x1(%rax), %edi
movb (%r9), %cl
testb %cl, %cl
movq %rdx, 0x20(%rsp)
movq %rax, 0x18(%rsp)
je 0x2d1b8
leaq 0x1(%r9), %rax
movl $0x811c9dc5, %r13d      # imm = 0x811C9DC5
movzbl %cl, %ecx
xorl %r13d, %ecx
imull $0x1000193, %ecx, %r13d # imm = 0x1000193
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x2d165
jmp 0x2d1be
testb $0x1, %dil
je 0x2cfc1
movslq %edx, %rcx
leaq (%rcx,%rcx,2), %rcx
movq (%rax,%rcx,8), %rdx
movslq 0x10(%rax,%rcx,8), %rax
shlq $0x4, %rax
movq (%rdx,%rax), %rcx
movq %rcx, 0xa0(%rbx)
movq 0x8(%rdx,%rax), %rax
jmp 0x2d289
xorl %r14d, %r14d
jmp 0x2d25a
movl $0x811c9dc5, %r13d      # imm = 0x811C9DC5
andl %edi, %r13d
movq 0x10(%rsi), %rdx
movl $0x1, %r15d
movl %r13d, %r14d
movq %r9, 0x8(%rsp)
movq %rsi, 0x38(%rsp)
movl %edi, 0x14(%rsp)
movq %rdx, 0x30(%rsp)
movl %r14d, %eax
shrl $0x4, %eax
movl (%rdx,%rax,4), %r12d
leal (%r14,%r14), %ebp
andl $0x1e, %ebp
movl %r12d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x2d243
testb $0x1, %al
jne 0x2d22b
movq 0x18(%rsi), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r9, %rsi
callq 0x46f0
movq 0x30(%rsp), %rdx
movl 0x14(%rsp), %edi
movq 0x38(%rsp), %rsi
movq 0x8(%rsp), %r9
testl %eax, %eax
je 0x2d243
addl %r15d, %r14d
andl %edi, %r14d
incl %r15d
cmpl %r13d, %r14d
jne 0x2d1e1
movq 0x18(%rsp), %rax
movl %eax, %r14d
jmp 0x2d255
movl %ebp, %ecx
shrl %cl, %r12d
testb $0x3, %r12b
movq 0x18(%rsp), %rax
cmovnel %eax, %r14d
movq 0x20(%rsp), %rdx
cmpl %eax, %r14d
je 0x2d2ca
movq 0x20(%rsi), %rax
movl %r14d, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, 0x9c(%rbx)
movb $0x9, (%rdx)
movq 0x28(%rsp), %rax
decq %rax
movq %rax, 0xa0(%rbx)
movq 0x40(%rsp), %rax
decq %rax
movq %rax, 0xa8(%rbx)
xorl %eax, %eax
jmp 0x2cfd0
movq 0x30(%rbx), %rcx
leaq 0x87e06(%rip), %rsi     # 0xb50a8
leaq 0x87d95(%rip), %rdx     # 0xb503e
movl $0x1, %edi
xorl %eax, %eax
callq 0x9e34
movq $0x0, 0x28(%rbx)
movq %rbx, %rdi
callq 0x29e6c
jmp 0x2cfcb
movq 0x20(%rbx), %r8
leaq 0x87dd3(%rip), %rsi     # 0xb50a8
leaq 0x87e18(%rip), %rdx     # 0xb50f4
movl $0x1, %edi
movq %r9, %rcx
xorl %eax, %eax
callq 0x9e34
movl $0x1, %edi
callq 0x4600