// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/synced_bcf_reader.c
// Function: reader_fill_buffer
static int _reader_fill_buffer(bcf_srs_t *files, bcf_sr_t *reader)
{
    // Return if the buffer is full: the coordinate of the last buffered record differs
    if ( reader->nbuffer && reader->buffer[reader->nbuffer]->pos != reader->buffer[1]->pos ) return 0;

    // No iterator (sequence not present in this file) and not streaming
    if ( !reader->itr && !files->streaming ) return 0;

    // Fill the buffer with records starting at the same position
    int i, ret = 0;
    while (1)
    {
        if ( reader->nbuffer+1 >= reader->mbuffer )
        {
            // Increase buffer size
            reader->mbuffer += 8;
            reader->buffer = (bcf1_t**) realloc(reader->buffer, sizeof(bcf1_t*)*reader->mbuffer);
            for (i=8; i>0; i--)     // initialize
            {
                reader->buffer[reader->mbuffer-i] = bcf_init1();
                reader->buffer[reader->mbuffer-i]->max_unpack = files->max_unpack;
                reader->buffer[reader->mbuffer-i]->pos = -1;    // for rare cases when VCF starts from 1
            }
        }
        if ( files->streaming )
        {
            if ( reader->file->format.format==vcf )
            {
                ret = hts_getline(reader->file, KS_SEP_LINE, &files->tmps);
                if ( ret < -1 ) files->errnum = bcf_read_error;
                if ( ret < 0 ) break; // no more lines or an error
                ret = vcf_parse1(&files->tmps, reader->header, reader->buffer[reader->nbuffer+1]);
                if ( ret<0 ) { files->errnum = vcf_parse_error; break; }
            }
            else if ( reader->file->format.format==bcf )
            {
                ret = bcf_read1(reader->file, reader->header, reader->buffer[reader->nbuffer+1]);
                if ( ret < -1 ) files->errnum = bcf_read_error;
                if ( ret < 0 ) break; // no more lines or an error
            }
            else
            {
                hts_log_error("Fixme: not ready for this");
                exit(1);
            }
        }
        else if ( reader->tbx_idx )
        {
            ret = tbx_itr_next(reader->file, reader->tbx_idx, reader->itr, &files->tmps);
            if ( ret < -1 ) files->errnum = bcf_read_error;
            if ( ret < 0 ) break; // no more lines or an error
            ret = vcf_parse1(&files->tmps, reader->header, reader->buffer[reader->nbuffer+1]);
            if ( ret<0 ) { files->errnum = vcf_parse_error; break; }
        }
        else
        {
            ret = bcf_itr_next(reader->file, reader->itr, reader->buffer[reader->nbuffer+1]);
            if ( ret < -1 ) files->errnum = bcf_read_error;
            if ( ret < 0 ) break; // no more lines or an error
            bcf_subset_format(reader->header,reader->buffer[reader->nbuffer+1]);
        }

        // Prevent creation of duplicates from records overlapping multiple regions
        // and recognize true variant overlaps vs record overlaps (e.g. TA>T vs A>-)
        if ( files->regions )
        {
            hts_pos_t beg, end;
            if ( BCF_SR_AUX(files)->regions_overlap==0 )
                beg = end = reader->buffer[reader->nbuffer+1]->pos;
            else if ( BCF_SR_AUX(files)->regions_overlap==1 )
            {
                beg = reader->buffer[reader->nbuffer+1]->pos;
                end = reader->buffer[reader->nbuffer+1]->pos + reader->buffer[reader->nbuffer+1]->rlen - 1;
            }
            else if ( BCF_SR_AUX(files)->regions_overlap==2 )
                _set_variant_boundaries(reader->buffer[reader->nbuffer+1], &beg,&end);
            else
            {
                hts_log_error("This should never happen, just to keep clang compiler happy: %d",BCF_SR_AUX(files)->targets_overlap);
                exit(1);
            }
            if ( beg <= files->regions->prev_end || end < files->regions->start || beg > files->regions->end ) continue;
        }

        // apply filter
        if ( !reader->nfilter_ids )
            bcf_unpack(reader->buffer[reader->nbuffer+1], BCF_UN_STR);
        else
        {
            bcf_unpack(reader->buffer[reader->nbuffer+1], BCF_UN_STR|BCF_UN_FLT);
            if ( !has_filter(reader, reader->buffer[reader->nbuffer+1]) ) continue;
        }
        reader->nbuffer++;

        if ( reader->buffer[reader->nbuffer]->rid != reader->buffer[1]->rid ) break;
        if ( reader->buffer[reader->nbuffer]->pos != reader->buffer[1]->pos ) break;    // the buffer is full
    }
    if ( ret<0 )
    {
        // done for this region
        tbx_itr_destroy(reader->itr);
        reader->itr = NULL;
    }
    if ( files->require_index==ALLOW_NO_IDX_ && reader->buffer[reader->nbuffer]->rid < reader->buffer[1]->rid )
    {
         hts_log_error("Sequences out of order, cannot stream multiple unindexed files: %s", reader->fname);
         exit(1);
    }
    return 0; // FIXME: Check for more errs in this function
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x38(%rax)
je 0x3c07e
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x38(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq 0x8(%rcx), %rcx
cmpq (%rcx), %rax
je 0x3c07e
movl $0x0, -0x4(%rbp)
jmp 0x3c697
movq -0x18(%rbp), %rax
cmpq $0x0, 0x20(%rax)
jne 0x3c09f
movq -0x10(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jne 0x3c09f
movl $0x0, -0x4(%rbp)
jmp 0x3c697
movl $0x0, -0x20(%rbp)
movq -0x18(%rbp), %rax
movl 0x38(%rax), %eax
addl $0x1, %eax
movq -0x18(%rbp), %rcx
cmpl 0x3c(%rcx), %eax
jl 0x3c16f
movq -0x18(%rbp), %rax
movl 0x3c(%rax), %ecx
addl $0x8, %ecx
movl %ecx, 0x3c(%rax)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rdi
movq -0x18(%rbp), %rax
movslq 0x3c(%rax), %rsi
shlq $0x3, %rsi
callq 0x4840
movq %rax, %rcx
movq -0x18(%rbp), %rax
movq %rcx, 0x30(%rax)
movl $0x8, -0x1c(%rbp)
cmpl $0x0, -0x1c(%rbp)
jle 0x3c16d
callq 0x490a0
movq %rax, %rdx
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x3c(%rcx), %ecx
subl -0x1c(%rbp), %ecx
movslq %ecx, %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rdx
movl 0x3c(%rdx), %edx
subl -0x1c(%rbp), %edx
movslq %edx, %rdx
movq (%rax,%rdx,8), %rax
movl %ecx, 0xb8(%rax)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x3c(%rcx), %ecx
subl -0x1c(%rbp), %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq $-0x1, (%rax)
movl -0x1c(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x3c0f5
jmp 0x3c16f
movq -0x10(%rbp), %rax
cmpl $0x0, 0x34(%rax)
je 0x3c298
movq -0x18(%rbp), %rax
movq (%rax), %rax
cmpl $0x8, 0x4c(%rax)
jne 0x3c212
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x10(%rbp), %rdx
addq $0x60, %rdx
movl $0x2, %esi
callq 0xd730
movl %eax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jge 0x3c1bb
movq -0x10(%rbp), %rax
movl $0x9, 0x20(%rax)
cmpl $0x0, -0x20(%rbp)
jge 0x3c1c6
jmp 0x3c613
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x38(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
callq 0x4da30
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x3c20d
movq -0x10(%rbp), %rax
movl $0x8, 0x20(%rax)
jmp 0x3c613
jmp 0x3c293
movq -0x18(%rbp), %rax
movq (%rax), %rax
cmpl $0x9, 0x4c(%rax)
jne 0x3c26d
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x38(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
callq 0x49a90
movl %eax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jge 0x3c260
movq -0x10(%rbp), %rax
movl $0x9, 0x20(%rax)
cmpl $0x0, -0x20(%rbp)
jge 0x3c26b
jmp 0x3c613
jmp 0x3c291
movl $0x1, %edi
leaq 0xd60d1(%rip), %rsi     # 0x11234a
leaq 0xd60de(%rip), %rdx     # 0x11235e
movb $0x0, %al
callq 0xa790
movl $0x1, %edi
callq 0x45d0
jmp 0x3c293
jmp 0x3c3af
movq -0x18(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x3c33b
movq -0x18(%rbp), %rax
movq (%rax), %rdi
callq 0xd310
movq %rax, %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x10(%rbp), %rdx
addq $0x60, %rdx
movq -0x18(%rbp), %rax
movq 0x8(%rax), %rcx
callq 0x13ab0
movl %eax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jge 0x3c2e7
movq -0x10(%rbp), %rax
movl $0x9, 0x20(%rax)
cmpl $0x0, -0x20(%rbp)
jge 0x3c2f2
jmp 0x3c613
movq -0x10(%rbp), %rdi
addq $0x60, %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x38(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
callq 0x4da30
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jge 0x3c339
movq -0x10(%rbp), %rax
movl $0x8, 0x20(%rax)
jmp 0x3c613
jmp 0x3c3ad
movq -0x18(%rbp), %rax
movq (%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rsi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x38(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
callq 0x3c900
movl %eax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jge 0x3c37c
movq -0x10(%rbp), %rax
movl $0x9, 0x20(%rax)
cmpl $0x0, -0x20(%rbp)
jge 0x3c387
jmp 0x3c613
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x38(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
callq 0x494c0
jmp 0x3c3af
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x3c52d
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
cmpl $0x0, 0x1d8(%rax)
jne 0x3c3fb
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x38(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movq %rax, -0x28(%rbp)
jmp 0x3c4e7
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
cmpl $0x1, 0x1d8(%rax)
jne 0x3c472
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x38(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x38(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq -0x18(%rbp), %rdx
movl 0x38(%rdx), %edx
addl $0x1, %edx
movslq %edx, %rdx
movq (%rcx,%rdx,8), %rcx
addq 0x8(%rcx), %rax
subq $0x1, %rax
movq %rax, -0x30(%rbp)
jmp 0x3c4e5
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
cmpl $0x2, 0x1d8(%rax)
jne 0x3c4ae
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x38(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x30(%rbp), %rdx
callq 0x3c6f0
jmp 0x3c4e3
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movl 0x1dc(%rax), %ecx
movl $0x1, %edi
leaq 0xd5e7f(%rip), %rsi     # 0x11234a
leaq 0xd5e38(%rip), %rdx     # 0x11230a
movb $0x0, %al
callq 0xa790
movl $0x1, %edi
callq 0x45d0
jmp 0x3c4e5
jmp 0x3c4e7
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
cmpq 0xc0(%rcx), %rax
jle 0x3c526
movq -0x30(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
cmpq 0xa0(%rcx), %rax
jl 0x3c526
movq -0x28(%rbp), %rax
movq -0x10(%rbp), %rcx
movq 0x48(%rcx), %rcx
cmpq 0xa8(%rcx), %rax
jle 0x3c52b
jmp 0x3c0a6
jmp 0x3c52d
movq -0x18(%rbp), %rax
cmpl $0x0, 0x40(%rax)
jne 0x3c55c
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x38(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
movl $0x1, %esi
callq 0x50600
jmp 0x3c5ad
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x38(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdi
movl $0x3, %esi
callq 0x50600
movq -0x18(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movl 0x38(%rcx), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
callq 0x3c980
cmpl $0x0, %eax
jne 0x3c5ab
jmp 0x3c0a6
jmp 0x3c5ad
movq -0x18(%rbp), %rax
movl 0x38(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x38(%rax)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x38(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movl 0x10(%rax), %eax
movq -0x18(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq 0x8(%rcx), %rcx
cmpl 0x10(%rcx), %eax
je 0x3c5e4
jmp 0x3c613
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x38(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movq (%rax), %rax
movq -0x18(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq 0x8(%rcx), %rcx
cmpq (%rcx), %rax
je 0x3c60e
jmp 0x3c613
jmp 0x3c0a6
cmpl $0x0, -0x20(%rbp)
jge 0x3c632
movq -0x18(%rbp), %rax
movq 0x20(%rax), %rdi
callq 0x11230
movq -0x18(%rbp), %rax
movq $0x0, 0x20(%rax)
movq -0x10(%rbp), %rax
cmpl $0x2, 0x10(%rax)
jne 0x3c690
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rax
movq -0x18(%rbp), %rcx
movslq 0x38(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movl 0x10(%rax), %eax
movq -0x18(%rbp), %rcx
movq 0x30(%rcx), %rcx
movq 0x8(%rcx), %rcx
cmpl 0x10(%rcx), %eax
jge 0x3c690
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rcx
movl $0x1, %edi
leaq 0xd5cd2(%rip), %rsi     # 0x11234a
leaq 0xd5cf9(%rip), %rdx     # 0x112378
movb $0x0, %al
callq 0xa790
movl $0x1, %edi
callq 0x45d0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x30, %rsp
popq %rbp
retq