// File: /workspace/github_c_makefile_star2_O2/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 $0x38, %rsp
movslq 0x9c(%rdi), %rcx
pushq $-0x1
popq %rax
testq %rcx, %rcx
js 0x2376f
movq %rdi, %rbx
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0xa0(%rdi)
andl $0x0, 0x60(%rdi)
leaq 0x9c(%rdi), %rbp
movq 0x80(%rdi), %rdx
testq %rdx, %rdx
je 0x2363a
movslq 0x98(%rbx), %rsi
addq $0xa0, %rbx
cmpq %rsi, %rcx
jge 0x237d7
imulq $0x18, %rcx, %r9
leaq (%rdx,%r9), %rdi
movslq 0x10(%rdx,%r9), %r8
movslq 0x8(%rdx,%r9), %r9
leal 0x1(%r8), %r10d
cmpl %r10d, %r9d
cmovgl %r9d, %r10d
movq %r8, %r11
shlq $0x4, %r11
addq $0x18, %r11
movq %r8, %r14
incq %r14
cmpq %r9, %r14
jge 0x23606
movq (%rdi), %r15
movq -0x8(%r15,%r11), %r12
incl %r8d
leaq 0x10(%r11), %r13
incq %r14
cmpq (%r15,%r11), %r12
movq %r13, %r11
jg 0x235e4
jmp 0x23612
movl %r10d, 0x10(%rdi)
incq %rcx
movl %ecx, (%rbp)
jmp 0x235ad
movl %r8d, 0x10(%rdi)
movslq %ecx, %rax
imulq $0x18, %rax, %rax
movq (%rdx,%rax), %rcx
movslq 0x10(%rdx,%rax), %rax
shlq $0x4, %rax
movdqu (%rcx,%rax), %xmm0
movdqu %xmm0, (%rbx)
xorl %eax, %eax
jmp 0x2376f
movq %rbp, 0x10(%rsp)
movq (%rbx), %rcx
xorl %eax, %eax
testq %rcx, %rcx
je 0x2366f
movl 0x4(%rcx), %ebp
decl %ebp
movl 0x8(%rcx), %r15d
decl %r15d
movl 0xc(%rcx), %edx
leal -0x1(%rdx), %r12d
testl %edx, %edx
cmovlel %r15d, %r12d
cmpl $0x10000, (%rcx)        # imm = 0x10000
setne 0xf(%rsp)
jmp 0x2367e
movb $0x1, 0xf(%rsp)
pushq $0x2
popq %r12
pushq $0x1
popq %r15
xorl %ebp, %ebp
leaq 0x10(%rbx), %r13
leaq 0x28(%rsp), %r14
testl %eax, %eax
jne 0x2377e
cmpq $0x0, 0x8(%rbx)
je 0x236b3
movq 0x28(%rbx), %rdi
callq 0x9d88
movq (%rbx), %rcx
movq 0x8(%rbx), %rsi
movq %rax, %rdi
movq %r13, %rdx
callq 0xdddd
jmp 0x236fb
cmpl $0x0, 0x38(%rbx)
movq 0x28(%rbx), %rax
je 0x236e8
movq %rax, %rdi
callq 0x99d1
movq 0x30(%rbx), %rdi
leaq 0x66cd5(%rip), %rsi     # 0x8a3a5
callq 0x87fb
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x237dd
andl $0x0, 0x38(%rbx)
jmp 0x236ed
testq %rax, %rax
je 0x23764
movq %rax, %rdi
pushq $0x2
popq %rsi
movq %r13, %rdx
callq 0x9f6c
testl %eax, %eax
js 0x23764
movq 0x20(%rbx), %rdi
movl %ebp, %esi
movl %r15d, %edx
movl %r12d, %ecx
leaq 0x30(%rsp), %r8
movq %r14, %r9
leaq 0x20(%rsp), %rax
pushq %rax
leaq 0x20(%rsp), %rax
pushq %rax
callq 0x2327f
addq $0x10, %rsp
testl %eax, %eax
jns 0x23687
movq 0x30(%rbx), %rcx
incl %ebp
incl %r15d
incl %r12d
subq $0x8, %rsp
leaq 0x678f1(%rip), %rsi     # 0x8b038
leaq 0x678fe(%rip), %rdx     # 0x8b04c
pushq $0x1
popq %rdi
movl %ebp, %r8d
movl %r15d, %r9d
xorl %eax, %eax
pushq %r12
callq 0x86fa
popq %rax
popq %rcx
jmp 0x2376c
movq 0x10(%rsp), %rax
orl $-0x1, (%rax)
pushq $-0x1
popq %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x0, 0xf(%rsp)
jne 0x2378a
incq 0x18(%rsp)
movq 0x28(%rsp), %r15
movb $0x0, (%r15)
movq 0x88(%rbx), %rdi
movq 0x30(%rsp), %r14
movq %r14, %rsi
movq 0x10(%rsp), %rdx
callq 0x22cd3
testl %eax, %eax
js 0x2380b
movb $0x9, (%r15)
movq 0x18(%rsp), %rax
decq %rax
movq %rax, 0xa0(%rbx)
movq 0x20(%rsp), %rax
decq %rax
movq %rax, 0xa8(%rbx)
jmp 0x23633
orl $-0x1, (%rbp)
jmp 0x2376f
movq 0x30(%rbx), %rcx
leaq 0x67850(%rip), %rsi     # 0x8b038
leaq 0x677df(%rip), %rdx     # 0x8afce
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x86fa
andq $0x0, 0x28(%rbx)
movq %rbx, %rdi
callq 0x20f62
jmp 0x2376c
movq 0x20(%rbx), %r8
leaq 0x67822(%rip), %rsi     # 0x8b038
leaq 0x67867(%rip), %rdx     # 0x8b084
pushq $0x1
popq %rbx
movl %ebx, %edi
movq %r14, %rcx
xorl %eax, %eax
callq 0x86fa
movl %ebx, %edi
callq 0x4600