// File: /workspace/github_c_makefile_star2_O3/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
movslq 0x9c(%rdi), %rcx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %rcx, %rcx
js 0x2c55a
movq %rdi, %rbx
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0xa0(%rdi)
movl $0x0, 0x60(%rdi)
movq 0x80(%rdi), %rdx
testq %rdx, %rdx
je 0x2c277
movl 0x98(%rbx), %edi
cmpl %edi, %ecx
jge 0x2c268
leaq 0xa0(%rbx), %rsi
leaq (%rcx,%rcx,2), %r8
leaq (%rdx,%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, %r15
incq %r15
cmpq %r10, %r15
jge 0x2c256
movq (%r8), %r12
movq -0x8(%r12,%r14), %r13
incl %r9d
leaq 0x10(%r14), %rbp
incq %r15
cmpq (%r12,%r14), %r13
movq %rbp, %r14
jg 0x2c234
jmp 0x2c2a7
movl %r11d, 0x10(%r8)
incq %rcx
movl %ecx, 0x9c(%rbx)
cmpq %rdi, %rcx
jne 0x2c208
movl $0xffffffff, 0x9c(%rbx) # imm = 0xFFFFFFFF
jmp 0x2c55a
movq (%rbx), %rcx
xorl %eax, %eax
testq %rcx, %rcx
je 0x2c2cd
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 0x2c2e0
movl %r9d, 0x10(%r8)
movslq %ecx, %rax
leaq (%rax,%rax,2), %rax
movq (%rdx,%rax,8), %rcx
movslq 0x10(%rdx,%rax,8), %rax
shlq $0x4, %rax
movdqu (%rcx,%rax), %xmm0
movdqu %xmm0, (%rsi)
jmp 0x2c558
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 0x2c3e3
cmpq $0x0, 0x8(%rbx)
je 0x2c315
movq 0x28(%rbx), %rdi
callq 0xb277
movq (%rbx), %rcx
movq 0x8(%rbx), %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0x1037e
jmp 0x2c362
cmpl $0x0, 0x38(%rbx)
movq 0x28(%rbx), %rax
je 0x2c34d
movq %rax, %rdi
callq 0xae96
movq 0x30(%rbx), %rdi
leaq 0x86098(%rip), %rsi     # 0xb23ca
callq 0x9c34
movq %rax, 0x28(%rbx)
testq %rax, %rax
je 0x2c569
movl $0x0, 0x38(%rbx)
jmp 0x2c352
testq %rax, %rax
je 0x2c3cf
movq %rax, %rdi
movl $0x2, %esi
movq %r12, %rdx
callq 0xb47e
testl %eax, %eax
js 0x2c3cf
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 0x20(%rsp), %rax
pushq %rax
callq 0x2bde0
addq $0x10, %rsp
testl %eax, %eax
jns 0x2c2e9
movq 0x30(%rbx), %rcx
incl %ebp
incl %r14d
incl %r15d
subq $0x8, %rsp
leaq 0x86cea(%rip), %rsi     # 0xb3098
leaq 0x86cf7(%rip), %rdx     # 0xb30ac
movl $0x1, %edi
movl %ebp, %r8d
movl %r14d, %r9d
xorl %eax, %eax
pushq %r15
callq 0x9b31
addq $0x10, %rsp
jmp 0x2c3d9
movl $0xffffffff, 0x9c(%rbx) # imm = 0xFFFFFFFF
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x2c55a
cmpb $0x0, 0x8(%rsp)
jne 0x2c3ef
incq 0x18(%rsp)
movq 0x48(%rsp), %rax
movq %rax, 0x28(%rsp)
movb $0x0, (%rax)
movq 0x88(%rbx), %rax
movq 0x50(%rsp), %r9
movq %rax, 0x8(%rsp)
testq %rax, %rax
je 0x2c4db
movq 0x8(%rsp), %rax
movl (%rax), %eax
testl %eax, %eax
je 0x2c452
movq %rax, 0x20(%rsp)
leal -0x1(%rax), %edx
movb (%r9), %cl
testb %cl, %cl
je 0x2c45a
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 0x2c43a
jmp 0x2c460
xorl %r14d, %r14d
jmp 0x2c518
movl $0x811c9dc5, %r13d      # imm = 0x811C9DC5
andl %edx, %r13d
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rsi
movl $0x1, %r15d
movl %r13d, %r14d
movq %r9, 0x38(%rsp)
movl %edx, 0x14(%rsp)
movq %rsi, 0x30(%rsp)
movl %r14d, %eax
shrl $0x4, %eax
movl (%rsi,%rax,4), %r12d
leal (%r14,%r14), %ebp
andl $0x1e, %ebp
movl %r12d, %eax
movl %ebp, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x2c506
testb $0x1, %al
jne 0x2c4cd
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r9, %rsi
callq 0x46f0
movq 0x30(%rsp), %rsi
movl 0x14(%rsp), %edx
movq 0x38(%rsp), %r9
testl %eax, %eax
je 0x2c506
addl %r15d, %r14d
andl %edx, %r14d
incl %r15d
cmpl %r13d, %r14d
jne 0x2c483
movq 0x20(%rbx), %r8
leaq 0x86bb2(%rip), %rsi     # 0xb3098
leaq 0x86bf7(%rip), %rdx     # 0xb30e4
movl $0x1, %edi
movq %r9, %rcx
xorl %eax, %eax
callq 0x9b31
movl $0x1, %edi
callq 0x4600
movl %ebp, %ecx
shrl %cl, %r12d
testb $0x3, %r12b
movq 0x20(%rsp), %rax
cmovnel %eax, %r14d
cmpl %eax, %r14d
je 0x2c4db
movq 0x8(%rsp), %rax
movq 0x20(%rax), %rax
movl %r14d, %ecx
movl (%rax,%rcx,4), %eax
movl %eax, 0x9c(%rbx)
movq 0x28(%rsp), %rax
movb $0x9, (%rax)
movq 0x18(%rsp), %rax
decq %rax
movq %rax, 0xa0(%rbx)
movq 0x40(%rsp), %rax
decq %rax
movq %rax, 0xa8(%rbx)
xorl %eax, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x30(%rbx), %rcx
leaq 0x86b24(%rip), %rsi     # 0xb3098
leaq 0x86ab3(%rip), %rdx     # 0xb302e
movl $0x1, %edi
xorl %eax, %eax
callq 0x9b31
movq $0x0, 0x28(%rbx)
movq %rbx, %rdi
callq 0x28f39
jmp 0x2c3d9