// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/synced_bcf_reader.c
// Function: bcf_sr_add_hreader
int bcf_sr_add_hreader(bcf_srs_t *files, htsFile *file_ptr, int autoclose, const char *idxname)
{
    aux_t *auxdata = NULL;
    if ( ! file_ptr ) {
        files->errnum = open_failed;
        return 0;
    }

    files->has_line = (int*) realloc(files->has_line, sizeof(int)*(files->nreaders+1));
    files->has_line[files->nreaders] = 0;
    files->readers  = (bcf_sr_t*) realloc(files->readers, sizeof(bcf_sr_t)*(files->nreaders+1));
    bcf_sr_t *reader = &files->readers[files->nreaders++];
    memset(reader,0,sizeof(bcf_sr_t));

    reader->file = file_ptr;

    files->errnum = 0;

    if ( reader->file->format.compression==bgzf )
    {
        BGZF *bgzf = hts_get_bgzfp(reader->file);
        if ( bgzf && bgzf_check_EOF(bgzf) == 0 ) {
            files->errnum = no_eof;
            hts_log_warning("No BGZF EOF marker; file '%s' may be truncated", file_ptr->fn);
        }
        if (files->p)
            bgzf_thread_pool(bgzf, files->p->pool, files->p->qsize);
    }

    if ( files->require_index==REQUIRE_IDX_ )
    {
        if ( reader->file->format.format==vcf )
        {
            if ( reader->file->format.compression!=bgzf )
            {
                files->errnum = not_bgzf;
                return 0;
            }

            reader->tbx_idx = tbx_index_load2(file_ptr->fn, idxname);
            if ( !reader->tbx_idx )
            {
                files->errnum = idx_load_failed;
                return 0;
            }

            reader->header = bcf_hdr_read(reader->file);
        }
        else if ( reader->file->format.format==bcf )
        {
            if ( reader->file->format.compression!=bgzf )
            {
                files->errnum = not_bgzf;
                return 0;
            }

            reader->header = bcf_hdr_read(reader->file);

            reader->bcf_idx = bcf_index_load2(file_ptr->fn, idxname);
            if ( !reader->bcf_idx )
            {
                files->errnum = idx_load_failed;
                return 0;
            }
        }
        else
        {
            files->errnum = file_type_error;
            return 0;
        }
    }
    else
    {
        if ( reader->file->format.format==bcf || reader->file->format.format==vcf )
        {
            reader->header = bcf_hdr_read(reader->file);
        }
        else
        {
            files->errnum = file_type_error;
            return 0;
        }
        files->streaming = 1;
    }
    if ( files->streaming && files->nreaders>1 )
    {
        static int no_index_warned = 0;
        if ( files->require_index==ALLOW_NO_IDX_ && !no_index_warned )
        {
            hts_log_warning("Using multiple unindexed files may produce errors, make sure chromosomes are in the same order!");
            no_index_warned = 1;
        }
        if ( files->require_index!=ALLOW_NO_IDX_ )
        {
            files->errnum = api_usage_error;
            hts_log_error("Must set require_index when the number of readers is greater than one");
            return 0;
        }
    }
    if ( files->streaming && files->regions )
    {
        files->errnum = api_usage_error;
        hts_log_error("Cannot tabix-jump in streaming mode");
        return 0;
    }
    if ( !reader->header )
    {
        files->errnum = header_error;
        return 0;
    }

    reader->fname = strdup(file_ptr->fn);
    if ( files->apply_filters )
        reader->filter_ids = init_filters(reader->header, files->apply_filters, &reader->nfilter_ids);

    // Update list of chromosomes
    if ( !files->explicit_regs && !files->streaming )
    {
        int n = 0, i;
        const char **names;

        if ( !files->regions )
        {
            files->regions = bcf_sr_regions_alloc();
            if ( !files->regions )
            {
                hts_log_error("Cannot allocate regions data structure");
                return 0;
            }
        }

        names = reader->tbx_idx ? tbx_seqnames(reader->tbx_idx, &n) : bcf_hdr_seqnames(reader->header, &n);
        for (i=0; i<n; i++)
        {
            _regions_add(files->regions, names[i], -1, -1);
        }
        free(names);
        _regions_sort_and_merge(files->regions);
    }

    if ( files->require_index==ALLOW_NO_IDX_ && files->nreaders > 1 )
    {
        bcf_hdr_t *hdr0 = files->readers[0].header;
        bcf_hdr_t *hdr1 = reader->header;
        if ( hdr0->n[BCF_DT_CTG]!=hdr1->n[BCF_DT_CTG] )
        {
            files->errnum = noidx_error;
            hts_log_error("Different number of sequences in the header, refusing to stream multiple unindexed files");
            return 0;
        }
        int i;
        for (i=0; i<hdr0->n[BCF_DT_CTG]; i++)
        {
            if ( strcmp(bcf_hdr_id2name(hdr0,i),bcf_hdr_id2name(hdr1,i)) )
            {
                files->errnum = noidx_error;
                hts_log_error("Sequences in the header appear in different order, refusing to stream multiple unindexed files");
                return 0;
            }
        }
    }

    if ((auxdata = BCF_SR_AUX(files))) {
        //store closure status for htsfile
        int *tmp = realloc(auxdata->closefile, sizeof(int) * files->nreaders);
        if (!tmp) {
            hts_log_error("Failed to allocate memory");
            return 0;
        }
        tmp[files->nreaders - 1] = autoclose;
        auxdata->closefile = tmp;
    }


    return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movq %rcx, -0x28(%rbp)
movq $0x0, -0x30(%rbp)
cmpq $0x0, -0x18(%rbp)
jne 0x389c0
movq -0x10(%rbp), %rax
movl $0x0, 0x20(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3905f
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
addl $0x1, %eax
movslq %eax, %rsi
shlq $0x2, %rsi
callq 0x4840
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x30(%rcx), %rcx
movl $0x0, (%rax,%rcx,4)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0x30(%rax), %eax
addl $0x1, %eax
cltq
imulq $0x60, %rax, %rsi
callq 0x4840
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq -0x10(%rbp), %rdx
movl 0x30(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x30(%rdx)
movslq %ecx, %rcx
imulq $0x60, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rdi
xorl %esi, %esi
movl $0x60, %edx
callq 0x4240
movq -0x18(%rbp), %rcx
movq -0x38(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movl $0x0, 0x20(%rax)
movq -0x38(%rbp), %rax
movq (%rax), %rax
cmpl $0x2, 0x54(%rax)
jne 0x38b0b
movq -0x38(%rbp), %rax
movq (%rax), %rdi
callq 0xd310
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
je 0x38ad6
movq -0x40(%rbp), %rdi
callq 0xe81d0
cmpl $0x0, %eax
jne 0x38ad6
movq -0x10(%rbp), %rax
movl $0x6, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rcx
movl $0x3, %edi
leaq 0xd9446(%rip), %rsi     # 0x111f0e
leaq 0xd9452(%rip), %rdx     # 0x111f21
movb $0x0, %al
callq 0xa790
movq -0x10(%rbp), %rax
cmpq $0x0, 0x80(%rax)
je 0x38b09
movq -0x40(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movq 0x80(%rax), %rax
movl 0x8(%rax), %edx
callq 0xe6610
jmp 0x38b0b
movq -0x10(%rbp), %rax
cmpl $0x1, 0x10(%rax)
jne 0x38c47
movq -0x38(%rbp), %rax
movq (%rax), %rax
cmpl $0x8, 0x4c(%rax)
jne 0x38ba4
movq -0x38(%rbp), %rax
movq (%rax), %rax
cmpl $0x2, 0x54(%rax)
je 0x38b4a
movq -0x10(%rbp), %rax
movl $0x1, 0x20(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3905f
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x3f3e0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0x38b88
movq -0x10(%rbp), %rax
movl $0x2, 0x20(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3905f
movq -0x38(%rbp), %rax
movq (%rax), %rdi
callq 0x484a0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0x38c45
movq -0x38(%rbp), %rax
movq (%rax), %rax
cmpl $0x9, 0x4c(%rax)
jne 0x38c2c
movq -0x38(%rbp), %rax
movq (%rax), %rax
cmpl $0x2, 0x54(%rax)
je 0x38bd5
movq -0x10(%rbp), %rax
movl $0x1, 0x20(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3905f
movq -0x38(%rbp), %rax
movq (%rax), %rdi
callq 0x484a0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
movq -0x28(%rbp), %rsi
callq 0x52f30
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
cmpq $0x0, 0x10(%rax)
jne 0x38c2a
movq -0x10(%rbp), %rax
movl $0x2, 0x20(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3905f
jmp 0x38c43
movq -0x10(%rbp), %rax
movl $0x3, 0x20(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3905f
jmp 0x38c45
jmp 0x38c9c
movq -0x38(%rbp), %rax
movq (%rax), %rax
cmpl $0x9, 0x4c(%rax)
je 0x38c61
movq -0x38(%rbp), %rax
movq (%rax), %rax
cmpl $0x8, 0x4c(%rax)
jne 0x38c7a
movq -0x38(%rbp), %rax
movq (%rax), %rdi
callq 0x484a0
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x18(%rax)
jmp 0x38c91
movq -0x10(%rbp), %rax
movl $0x3, 0x20(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3905f
movq -0x10(%rbp), %rax
movl $0x1, 0x34(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x34(%rax)
je 0x38d24
movq -0x10(%rbp), %rax
cmpl $0x1, 0x30(%rax)
jle 0x38d24
movq -0x10(%rbp), %rax
cmpl $0x2, 0x10(%rax)
jne 0x38ce7
cmpl $0x0, 0xfebff(%rip)     # 0x1378c0
jne 0x38ce7
movl $0x3, %edi
leaq 0xd923f(%rip), %rsi     # 0x111f0e
leaq 0xd927a(%rip), %rdx     # 0x111f50
movb $0x0, %al
callq 0xa790
movl $0x1, 0xfebd9(%rip)     # 0x1378c0
movq -0x10(%rbp), %rax
cmpl $0x2, 0x10(%rax)
je 0x38d22
movq -0x10(%rbp), %rax
movl $0x4, 0x20(%rax)
movl $0x1, %edi
leaq 0xd9206(%rip), %rsi     # 0x111f0e
leaq 0xd92a1(%rip), %rdx     # 0x111fb0
movb $0x0, %al
callq 0xa790
movl $0x0, -0x4(%rbp)
jmp 0x3905f
jmp 0x38d24
movq -0x10(%rbp), %rax
cmpl $0x0, 0x34(%rax)
je 0x38d6a
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
je 0x38d6a
movq -0x10(%rbp), %rax
movl $0x4, 0x20(%rax)
movl $0x1, %edi
leaq 0xd91be(%rip), %rsi     # 0x111f0e
leaq 0xd929f(%rip), %rdx     # 0x111ff6
movb $0x0, %al
callq 0xa790
movl $0x0, -0x4(%rbp)
jmp 0x3905f
movq -0x38(%rbp), %rax
cmpq $0x0, 0x18(%rax)
jne 0x38d8c
movq -0x10(%rbp), %rax
movl $0x5, 0x20(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x3905f
movq -0x18(%rbp), %rax
movq 0x28(%rax), %rdi
callq 0x4930
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x28(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x38dd7
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rsi
movq -0x38(%rbp), %rdx
addq $0x40, %rdx
callq 0x39070
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x38(%rax)
jne 0x38eda
movq -0x10(%rbp), %rax
cmpl $0x0, 0x34(%rax)
jne 0x38eda
movl $0x0, -0x44(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x38e48
callq 0x39200
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x48(%rax)
jne 0x38e46
movl $0x1, %edi
leaq 0xd90e2(%rip), %rsi     # 0x111f0e
leaq 0xd91e7(%rip), %rdx     # 0x11201a
movb $0x0, %al
callq 0xa790
movl $0x0, -0x4(%rbp)
jmp 0x3905f
jmp 0x38e48
movq -0x38(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x38e6a
movq -0x38(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x44(%rbp), %rsi
callq 0x3f440
movq %rax, -0x78(%rbp)
jmp 0x38e7f
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rdi
leaq -0x44(%rbp), %rsi
callq 0x4c430
movq %rax, -0x78(%rbp)
movq -0x78(%rbp), %rax
movq %rax, -0x50(%rbp)
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x44(%rbp), %eax
jge 0x38ec4
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x50(%rbp), %rax
movslq -0x48(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq $-0x1, %rcx
movq %rcx, %rdx
callq 0x39290
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x38e8e
movq -0x50(%rbp), %rdi
callq 0x45a0
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
callq 0x39510
movq -0x10(%rbp), %rax
cmpl $0x2, 0x10(%rax)
jne 0x38fd3
movq -0x10(%rbp), %rax
cmpl $0x1, 0x30(%rax)
jle 0x38fd3
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rax
movq 0x18(%rax), %rax
movq %rax, -0x58(%rbp)
movq -0x38(%rbp), %rax
movq 0x18(%rax), %rax
movq %rax, -0x60(%rbp)
movq -0x58(%rbp), %rax
movl 0x4(%rax), %eax
movq -0x60(%rbp), %rcx
cmpl 0x4(%rcx), %eax
je 0x38f53
movq -0x10(%rbp), %rax
movl $0xa, 0x20(%rax)
movl $0x1, %edi
leaq 0xd8fd5(%rip), %rsi     # 0x111f0e
leaq 0xd9101(%rip), %rdx     # 0x112041
movb $0x0, %al
callq 0xa790
movl $0x0, -0x4(%rbp)
jmp 0x3905f
movl $0x0, -0x64(%rbp)
movl -0x64(%rbp), %eax
movq -0x58(%rbp), %rcx
cmpl 0x4(%rcx), %eax
jge 0x38fd1
movq -0x58(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x395b0
movq %rax, -0x80(%rbp)
movq -0x60(%rbp), %rdi
movl -0x64(%rbp), %esi
callq 0x395b0
movq -0x80(%rbp), %rdi
movq %rax, %rsi
callq 0x46b0
cmpl $0x0, %eax
je 0x38fc4
movq -0x10(%rbp), %rax
movl $0xa, 0x20(%rax)
movl $0x1, %edi
leaq 0xd8f64(%rip), %rsi     # 0x111f0e
leaq 0xd90e9(%rip), %rdx     # 0x11209a
movb $0x0, %al
callq 0xa790
movl $0x0, -0x4(%rbp)
jmp 0x3905f
jmp 0x38fc6
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x38f5a
jmp 0x38fd3
movq -0x10(%rbp), %rax
movq 0x88(%rax), %rax
movq %rax, -0x30(%rbp)
cmpq $0x0, %rax
je 0x39058
movq -0x30(%rbp), %rax
movq 0x1e0(%rax), %rdi
movq -0x10(%rbp), %rax
movslq 0x30(%rax), %rsi
shlq $0x2, %rsi
callq 0x4840
movq %rax, -0x70(%rbp)
cmpq $0x0, -0x70(%rbp)
jne 0x39032
movl $0x1, %edi
leaq 0xd8ef3(%rip), %rsi     # 0x111f0e
leaq 0xd90d7(%rip), %rdx     # 0x1120f9
movb $0x0, %al
callq 0xa790
movl $0x0, -0x4(%rbp)
jmp 0x3905f
movl -0x1c(%rbp), %edx
movq -0x70(%rbp), %rax
movq -0x10(%rbp), %rcx
movl 0x30(%rcx), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x70(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x1e0(%rax)
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopl (%rax,%rax)