// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
testq %rsi, %rsi
je 0x2a964
movq %rcx, %r15
movq %rsi, %r14
movl %edx, 0x2c(%rsp)
movq 0x18(%rbx), %rdi
movslq 0x30(%rbx), %rax
leaq 0x4(,%rax,4), %rsi
callq 0x4870
movq %rax, 0x18(%rbx)
movslq 0x30(%rbx), %rcx
xorl %ebp, %ebp
movl %ebp, (%rax,%rcx,4)
movq 0x28(%rbx), %rdi
leaq (%rcx,%rcx,2), %rsi
shlq $0x5, %rsi
addq $0x60, %rsi
callq 0x4870
movq %rax, 0x28(%rbx)
movslq 0x30(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x30(%rbx)
leaq (%rcx,%rcx,2), %rcx
shlq $0x5, %rcx
leaq (%rax,%rcx), %r13
pxor %xmm0, %xmm0
movdqu %xmm0, (%rax,%rcx)
movdqu %xmm0, 0x10(%rax,%rcx)
movdqu %xmm0, 0x20(%rax,%rcx)
movdqu %xmm0, 0x30(%rax,%rcx)
movdqu %xmm0, 0x40(%rax,%rcx)
movdqu %xmm0, 0x50(%rax,%rcx)
movq %r14, (%rax,%rcx)
movl %ebp, 0x20(%rbx)
cmpl $0x2, 0x54(%r14)
jne 0x2a913
movq %r14, %rdi
callq 0xb57d
movq %rax, %r12
testq %rax, %rax
je 0x2a8f9
movq %r12, %rdi
callq 0x97a9a
testl %eax, %eax
jne 0x2a8f9
movl $0x6, 0x20(%rbx)
movq 0x28(%r14), %rcx
leaq 0x8a478(%rip), %rsi     # 0xb4d5e
leaq 0x8a484(%rip), %rdx     # 0xb4d71
movl $0x3, %edi
xorl %eax, %eax
callq 0x9e34
movq 0x80(%rbx), %rax
testq %rax, %rax
je 0x2a913
movq (%rax), %rsi
movl 0x8(%rax), %edx
movq %r12, %rdi
callq 0x96638
cmpl $0x1, 0x10(%rbx)
movq (%r13), %rdi
movl 0x4c(%rdi), %eax
jne 0x2a970
cmpl $0x9, %eax
je 0x2abd5
cmpl $0x8, %eax
jne 0x2a9f5
cmpl $0x2, 0x54(%rdi)
jne 0x2ac09
movq 0x28(%r14), %rdi
movq %r15, %rsi
callq 0x2eb7f
movq %rax, 0x8(%r13)
testq %rax, %rax
je 0x2abfd
movq (%r13), %rdi
callq 0x3504b
movq %rax, 0x18(%r13)
jmp 0x2a988
movl $0x0, 0x20(%rbx)
jmp 0x2ae17
andl $-0x2, %eax
cmpl $0x8, %eax
jne 0x2a9f5
callq 0x3504b
movq %rax, 0x18(%r13)
movl $0x1, 0x34(%rbx)
cmpl $0x0, 0x34(%rbx)
je 0x2a9ce
cmpl $0x2, 0x30(%rbx)
jl 0x2a9ce
cmpl $0x2, 0x10(%rbx)
jne 0x2a9c4
testb $0x1, 0xae58f(%rip)     # 0xd8f30
jne 0x2a9c4
leaq 0x8a3b4(%rip), %rsi     # 0xb4d5e
leaq 0x8a3ef(%rip), %rdx     # 0xb4da0
movl $0x3, %edi
xorl %eax, %eax
callq 0x9e34
movb $0x1, 0xae56c(%rip)     # 0xd8f30
cmpl $0x2, 0x10(%rbx)
jne 0x2ac4e
cmpl $0x0, 0x34(%rbx)
je 0x2aa01
cmpq $0x0, 0x48(%rbx)
je 0x2aa01
movl $0x4, 0x20(%rbx)
leaq 0x8a375(%rip), %rsi     # 0xb4d5e
leaq 0x8a456(%rip), %rdx     # 0xb4e46
jmp 0x2ae66
movl $0x3, 0x20(%rbx)
jmp 0x2ae17
movq 0x18(%r13), %rax
movq %rax, 0x40(%rsp)
testq %rax, %rax
je 0x2ac42
movq 0x28(%r14), %rdi
callq 0x4950
movq %rax, 0x28(%r13)
movq 0x8(%rbx), %r14
testq %r14, %r14
je 0x2ac8a
movq %r13, 0x38(%rsp)
xorl %r15d, %r15d
movq $0x0, 0x20(%rsp)
movq $0x0, 0x8(%rsp)
movq %r14, 0x18(%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
movq %r14, 0x30(%rsp)
movzbl (%r14,%r15), %eax
cmpl $0x2c, %eax
je 0x2aa68
testl %eax, %eax
jne 0x2abcd
movslq %ebp, %r12
leaq 0x4(,%r12,4), %rsi
movq %r13, %rdi
callq 0x4870
testq %rax, %rax
je 0x2ab18
movq %rax, %rdi
leal 0x1(%rbp), %esi
leaq (%r14,%r15), %rax
movq %rax, %r13
subq 0x18(%rsp), %r13
cmpq $0x1, %r13
jne 0x2aab3
movq 0x18(%rsp), %rcx
cmpb $0x2e, (%rcx)
jne 0x2aab3
movl $0xffffffff, (%rdi,%r12,4) # imm = 0xFFFFFFFF
jmp 0x2ab9e
movq %r13, %rcx
addq $0x2, %rcx
movq %rbp, 0x50(%rsp)
movq %rdi, 0x48(%rsp)
movl %esi, 0x28(%rsp)
je 0x2ab25
movq 0x20(%rsp), %rdx
cmpq %rcx, %rdx
jae 0x2ab37
movq %rcx, %rdx
shrq $0x3e, %rdx
shrq %rcx
testq %rdx, %rdx
movl $0x0, %edx
cmoveq %rcx, %rdx
subq 0x18(%rsp), %rdx
leaq (%rdx,%rax), %rbp
addq $0x2, %rbp
movq 0x8(%rsp), %rdi
movq %rdi, 0x8(%rsp)
movq %rbp, %rsi
callq 0x4870
movq %rax, %r14
movq 0x8(%rsp), %rdx
testq %rax, %rax
jne 0x2ab3f
jmp 0x2ab74
movl $0x4, %eax
movq %r13, %rdi
jmp 0x2abc1
callq 0x4050
movl $0x4b, (%rax)
movq 0x8(%rsp), %rdx
jmp 0x2ab74
movq %rdx, %rbp
movq 0x8(%rsp), %r14
movq %rbp, 0x8(%rsp)
movq %r14, %rdi
movq 0x18(%rsp), %rbp
movq %rbp, %rsi
movq %r13, %rdx
callq 0x43c0
movq %r14, %rax
subq %rbp, %rax
addq 0x30(%rsp), %rax
movb $0x0, (%r15,%rax)
movq 0x8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq %r14, %rdx
movq 0x40(%rsp), %rdi
xorl %esi, %esi
movq %rdx, 0x8(%rsp)
callq 0x33da1
movq 0x48(%rsp), %rdi
movl %eax, (%rdi,%r12,4)
testl %eax, %eax
movl 0x28(%rsp), %esi
cmovsl 0x50(%rsp), %esi
movq 0x30(%rsp), %r14
xorl %eax, %eax
leaq (%r14,%r15), %rcx
incq %rcx
cmpb $0x0, -0x1(%rcx)
sete %al
movq 0x18(%rsp), %rdx
cmovneq %rcx, %rdx
movq %rdx, 0x18(%rsp)
leal (%rax,%rax,2), %eax
movl %esi, %ebp
movq 0x38(%rsp), %r13
testl %eax, %eax
jne 0x2ac15
movq %rdi, %r13
incq %r15
jmp 0x2aa56
cmpl $0x2, 0x54(%rdi)
jne 0x2ac09
callq 0x3504b
movq %rax, 0x18(%r13)
movq 0x28(%r14), %rdi
movq %r15, %rsi
callq 0x41980
movq %rax, 0x10(%r13)
testq %rax, %rax
jne 0x2a988
movl $0x2, 0x20(%rbx)
jmp 0x2ae17
movl $0x1, 0x20(%rbx)
jmp 0x2ae17
cmpl $0x3, %eax
je 0x2ac68
cmpl $0x4, %eax
movq 0x20(%rsp), %rax
jne 0x2ac86
testq %rax, %rax
je 0x2ac39
movq %rdi, %r14
movq 0x8(%rsp), %rdi
callq 0x45d0
movq %r14, %rdi
callq 0x45d0
xorl %edi, %edi
jmp 0x2ac86
movl $0x5, 0x20(%rbx)
jmp 0x2ae17
movl $0x4, 0x20(%rbx)
leaq 0x8a102(%rip), %rsi     # 0xb4d5e
leaq 0x8a19d(%rip), %rdx     # 0xb4e00
jmp 0x2ae66
cmpq $0x0, 0x20(%rsp)
je 0x2ac80
movq %rdi, %r15
movq 0x8(%rsp), %rdi
callq 0x45d0
movq %r15, %rdi
movl %ebp, 0x40(%r13)
jmp 0x2ac86
movq %rdi, 0x48(%r13)
cmpl $0x0, 0x38(%rbx)
jne 0x2ad59
cmpl $0x0, 0x34(%rbx)
jne 0x2ad59
movl $0x0, 0x14(%rsp)
cmpq $0x0, 0x48(%rbx)
jne 0x2acf0
movl $0x1, %edi
movl $0xd0, %esi
callq 0x42f0
testq %rax, %rax
je 0x2ace1
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0xa0(%rax)
movl $0xffffffff, 0xb0(%rax) # imm = 0xFFFFFFFF
movdqu %xmm0, 0xb8(%rax)
jmp 0x2ace3
xorl %eax, %eax
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x2ae58
movq 0x8(%r13), %rdi
testq %rdi, %rdi
je 0x2ad05
leaq 0x14(%rsp), %rsi
callq 0x2eb95
jmp 0x2ad13
movq 0x18(%r13), %rdi
leaq 0x14(%rsp), %rsi
callq 0x3886c
movq %rax, %r14
cmpl $0x0, 0x14(%rsp)
jle 0x2ad48
xorl %r15d, %r15d
movq 0x48(%rbx), %rdi
movq (%r14,%r15,8), %rsi
movq $-0x1, %rdx
movq $-0x1, %rcx
callq 0x2ae76
incq %r15
movslq 0x14(%rsp), %rax
cmpq %rax, %r15
jl 0x2ad20
movq %r14, %rdi
callq 0x45d0
movq 0x48(%rbx), %rdi
callq 0x2b13a
cmpl $0x2, 0x10(%rbx)
jne 0x2adb3
cmpl $0x2, 0x30(%rbx)
jl 0x2adb3
movq 0x28(%rbx), %rax
movq 0x18(%rax), %rax
movq 0x18(%r13), %rcx
movl 0x4(%rax), %r14d
cmpl 0x4(%rcx), %r14d
jne 0x2ae2a
testl %r14d, %r14d
jle 0x2adb3
movq 0x18(%rax), %r15
movq 0x18(%rcx), %r12
xorl %r13d, %r13d
movq (%r15), %rdi
movq (%r12), %rsi
callq 0x46f0
testl %eax, %eax
jne 0x2ae41
incq %r13
addq $0x10, %r15
addq $0x10, %r12
cmpq %r13, %r14
jne 0x2ad8f
movq 0x88(%rbx), %r15
testq %r15, %r15
je 0x2ae10
movq 0x1e0(%r15), %rdi
movslq 0x30(%rbx), %rsi
shlq $0x2, %rsi
callq 0x4870
movq %rax, %r14
testq %rax, %rax
je 0x2adf1
movslq 0x30(%rbx), %rax
movl 0x2c(%rsp), %ecx
movl %ecx, -0x4(%r14,%rax,4)
movq %r14, 0x1e0(%r15)
jmp 0x2ae0b
leaq 0x89f66(%rip), %rsi     # 0xb4d5e
leaq 0x8a14a(%rip), %rdx     # 0xb4f49
movl $0x1, %edi
xorl %eax, %eax
callq 0x9e34
testq %r14, %r14
je 0x2ae17
movl $0x1, %ebx
jmp 0x2ae19
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0xa, 0x20(%rbx)
leaq 0x89f26(%rip), %rsi     # 0xb4d5e
leaq 0x8a052(%rip), %rdx     # 0xb4e91
jmp 0x2ae66
movl $0xa, 0x20(%rbx)
leaq 0x89f0f(%rip), %rsi     # 0xb4d5e
leaq 0x8a094(%rip), %rdx     # 0xb4eea
jmp 0x2ae66
leaq 0x89eff(%rip), %rsi     # 0xb4d5e
leaq 0x8a004(%rip), %rdx     # 0xb4e6a
xorl %ebx, %ebx
movl $0x1, %edi
xorl %eax, %eax
callq 0x9e34
jmp 0x2ae19