// File: /workspace/github_c_makefile_star2_O3/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, %r13
testq %rsi, %rsi
je 0x299c3
movq %rcx, %r15
movl %edx, %ebp
movq %rsi, %r14
movq 0x18(%r13), %rdi
movslq 0x30(%r13), %rax
leaq 0x4(,%rax,4), %rsi
callq 0x4870
movq %rax, 0x18(%r13)
movslq 0x30(%r13), %rcx
xorl %ebx, %ebx
movl %ebx, (%rax,%rcx,4)
movq 0x28(%r13), %rdi
leaq (%rcx,%rcx,2), %rsi
shlq $0x5, %rsi
addq $0x60, %rsi
callq 0x4870
movq %rax, 0x28(%r13)
movslq 0x30(%r13), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x30(%r13)
leaq (%rcx,%rcx,2), %rcx
shlq $0x5, %rcx
leaq (%rax,%rcx), %rdx
movq %rdx, 0x28(%rsp)
pxor %xmm0, %xmm0
movdqu %xmm0, 0x8(%rax,%rcx)
movdqu %xmm0, 0x18(%rax,%rcx)
movdqu %xmm0, 0x28(%rax,%rcx)
movdqu %xmm0, 0x38(%rax,%rcx)
movdqu %xmm0, 0x48(%rax,%rcx)
movq $0x0, 0x58(%rax,%rcx)
movq %r14, (%rax,%rcx)
movl %ebx, 0x20(%r13)
cmpl $0x2, 0x54(%r14)
jne 0x2996e
movq %r14, %rdi
callq 0xb277
movq %rax, %r12
testq %rax, %rax
je 0x29954
movq %r12, %rdi
callq 0x95e08
testl %eax, %eax
jne 0x29954
movl $0x6, 0x20(%r13)
movq 0x28(%r14), %rcx
leaq 0x8940d(%rip), %rsi     # 0xb2d4e
leaq 0x89419(%rip), %rdx     # 0xb2d61
movl $0x3, %edi
xorl %eax, %eax
callq 0x9b31
movq 0x80(%r13), %rax
testq %rax, %rax
je 0x2996e
movq (%rax), %rsi
movl 0x8(%rax), %edx
movq %r12, %rdi
callq 0x949b8
cmpl $0x1, 0x10(%r13)
movq 0x28(%rsp), %rbx
movq (%rbx), %rdi
movl 0x4c(%rdi), %eax
jne 0x299d0
cmpl $0x9, %eax
je 0x29c5d
cmpl $0x8, %eax
jne 0x29a64
cmpl $0x2, 0x54(%rdi)
jne 0x29c8f
movq 0x28(%r14), %rdi
movq %r15, %rsi
callq 0x2de8d
movq %rax, 0x8(%rbx)
testq %rax, %rax
je 0x29c85
movq (%rbx), %rdi
callq 0x341a3
movq %rax, 0x18(%rbx)
jmp 0x299ed
movl $0x0, 0x20(%r13)
jmp 0x29ca1
andl $-0x2, %eax
cmpl $0x8, %eax
jne 0x29a64
callq 0x341a3
movq %rax, 0x18(%rbx)
movl $0x1, 0x34(%r13)
cmpl $0x0, 0x34(%r13)
je 0x29a71
cmpl $0x2, 0x30(%r13)
jl 0x29a42
movl 0x10(%r13), %eax
cmpl $0x2, %eax
jne 0x29a32
testb $0x1, 0xad525(%rip)     # 0xd6f30
jne 0x29a32
leaq 0x8933a(%rip), %rsi     # 0xb2d4e
leaq 0x89375(%rip), %rdx     # 0xb2d90
movl $0x3, %edi
xorl %eax, %eax
callq 0x9b31
movb $0x1, 0xad502(%rip)     # 0xd6f30
movl 0x10(%r13), %eax
cmpl $0x2, %eax
jne 0x29cb6
cmpl $0x0, 0x34(%r13)
je 0x29a71
cmpq $0x0, 0x48(%r13)
je 0x29a71
movl $0x4, 0x20(%r13)
leaq 0x892f6(%rip), %rsi     # 0xb2d4e
leaq 0x893d7(%rip), %rdx     # 0xb2e36
jmp 0x29ee8
movl $0x3, 0x20(%r13)
jmp 0x29ca1
movq 0x18(%rbx), %rax
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x29c99
movq 0x28(%r14), %rdi
callq 0x4950
movq %rax, 0x28(%rbx)
movq 0x8(%r13), %r14
testq %r14, %r14
je 0x29d2f
movl %ebp, 0x20(%rsp)
movq %r13, 0x30(%rsp)
xorl %ebx, %ebx
movq $0x0, 0x18(%rsp)
movq $0x0, 0x10(%rsp)
movq %r14, %r12
xorl %r13d, %r13d
xorl %ebp, %ebp
movq %r14, 0x38(%rsp)
movzbl (%r14,%rbx), %eax
cmpl $0x2c, %eax
je 0x29ad9
testl %eax, %eax
jne 0x29b74
movslq %r13d, %r15
leaq 0x4(,%r15,4), %rsi
movq %rbp, %rdi
callq 0x4870
movq %rax, %rdx
testq %rax, %rax
je 0x29cd1
movq %r13, 0x50(%rsp)
incl %r13d
leaq (%r14,%rbx), %rax
movq %rax, %rbp
movq %r12, %rsi
subq %r12, %rbp
cmpq $0x1, %rbp
je 0x29b79
movq %rdx, 0x40(%rsp)
movq %rbp, %rcx
addq $0x2, %rcx
movl %r13d, 0x24(%rsp)
je 0x29b8d
movq 0x18(%rsp), %rdx
cmpq %rcx, %rdx
jae 0x29b9f
movq %rcx, %rdx
shrq $0x3e, %rdx
shrq %rcx
testq %rdx, %rdx
movl $0x0, %edx
cmoveq %rcx, %rdx
subq %rsi, %rdx
leaq (%rdx,%rax), %r13
addq $0x2, %r13
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
callq 0x4870
movq %r12, %rsi
movq %r13, %r12
movq %rax, %r13
testq %rax, %rax
jne 0x29ba7
jmp 0x29c11
jmp 0x29c55
movb (%rsi), %cl
cmpb $0x2e, %cl
jne 0x29bce
movl $0xffffffff, (%rdx,%r15,4) # imm = 0xFFFFFFFF
jmp 0x29c40
callq 0x4050
movl $0x4b, (%rax)
movq 0x10(%rsp), %r14
jmp 0x29c11
movq %rdx, %r12
movq 0x10(%rsp), %r13
movq %r13, %rdi
movq %rsi, %r14
movq %rbp, %rdx
callq 0x43c0
movq %r13, %rax
subq %r14, %rax
addq 0x38(%rsp), %rax
movb $0x0, (%rbx,%rax)
movq %r12, 0x18(%rsp)
movq %r13, %r14
jmp 0x29c11
movq %rdx, 0x40(%rsp)
movl %r13d, 0x24(%rsp)
cmpq $0x2, 0x18(%rsp)
movq 0x10(%rsp), %rdi
ja 0x29c08
movl $0x4, %esi
movq %rdi, %r14
callq 0x4870
testq %rax, %rax
je 0x29c11
movb (%r12), %cl
movl $0x4, %edx
movq %rdx, 0x18(%rsp)
movq %rax, %rdi
movb %cl, (%rdi)
movb $0x0, 0x1(%rdi)
movq %rdi, %r14
movq 0x48(%rsp), %rdi
xorl %esi, %esi
movq %r14, 0x10(%rsp)
movq %r14, %rdx
callq 0x32f65
movq 0x40(%rsp), %rdx
movl %eax, (%rdx,%r15,4)
testl %eax, %eax
movl 0x24(%rsp), %r13d
cmovsl 0x50(%rsp), %r13d
movq 0x38(%rsp), %r14
cmpb $0x0, (%r14,%rbx)
je 0x29d01
leaq (%r14,%rbx), %r12
incq %r12
movq %rdx, %rbp
incq %rbx
jmp 0x29ac7
cmpl $0x2, 0x54(%rdi)
jne 0x29c8f
callq 0x341a3
movq %rax, 0x18(%rbx)
movq 0x28(%r14), %rdi
movq %r15, %rsi
callq 0x40fb7
movq %rax, 0x10(%rbx)
testq %rax, %rax
jne 0x299ed
movl $0x2, 0x20(%r13)
jmp 0x29ca1
movl $0x1, 0x20(%r13)
jmp 0x29ca1
movl $0x5, 0x20(%r13)
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl $0x4, 0x20(%r13)
leaq 0x89089(%rip), %rsi     # 0xb2d4e
leaq 0x89124(%rip), %rdx     # 0xb2df0
jmp 0x29ee8
movq %rdx, %r14
cmpq $0x0, 0x18(%rsp)
je 0x29ce6
movq 0x10(%rsp), %rdi
callq 0x45d0
movq %rbp, %rdi
callq 0x45d0
movq 0x30(%rsp), %r13
movl 0x20(%rsp), %ebp
movq 0x28(%rsp), %rbx
movq %r14, %rdx
jmp 0x29d2b
cmpq $0x0, 0x18(%rsp)
je 0x29d19
movq 0x10(%rsp), %rdi
movq %rdx, %rbx
callq 0x45d0
movq %rbx, %rdx
movq 0x28(%rsp), %rbx
movl %r13d, 0x40(%rbx)
movq 0x30(%rsp), %r13
movl 0x20(%rsp), %ebp
movq %rdx, 0x48(%rbx)
cmpl $0x0, 0x38(%r13)
jne 0x29dfb
cmpl $0x0, 0x34(%r13)
jne 0x29dfb
movl $0x0, 0xc(%rsp)
cmpq $0x0, 0x48(%r13)
jne 0x29d8e
movl $0x1, %edi
movl $0xd0, %esi
callq 0x42f0
testq %rax, %rax
je 0x29ed2
pcmpeqd %xmm0, %xmm0
movdqu %xmm0, 0xa0(%rax)
movl $0xffffffff, 0xb0(%rax) # imm = 0xFFFFFFFF
movdqu %xmm0, 0xb8(%rax)
movq %rax, 0x48(%r13)
movq 0x8(%rbx), %rdi
testq %rdi, %rdi
je 0x29da3
leaq 0xc(%rsp), %rsi
callq 0x2dea3
jmp 0x29db1
movq 0x18(%rbx), %rdi
leaq 0xc(%rsp), %rsi
callq 0x379e4
movq %rax, %r14
cmpl $0x0, 0xc(%rsp)
jle 0x29de5
xorl %ebx, %ebx
movq 0x48(%r13), %rdi
movq (%r14,%rbx,8), %rsi
movq $-0x1, %rdx
movq $-0x1, %rcx
callq 0x29efc
incq %rbx
movslq 0xc(%rsp), %rax
cmpq %rax, %rbx
jl 0x29dbd
movq %r14, %rdi
callq 0x45d0
movq 0x48(%r13), %rdi
callq 0x2a19e
movq 0x28(%rsp), %rbx
cmpl $0x2, 0x10(%r13)
jne 0x29e4f
cmpl $0x2, 0x30(%r13)
jl 0x29e4f
movq 0x28(%r13), %rax
movq 0x18(%rax), %rax
movq 0x18(%rbx), %rcx
movl 0x4(%rax), %ebx
cmpl 0x4(%rcx), %ebx
jne 0x29ea2
testl %ebx, %ebx
jle 0x29e4f
movq 0x18(%rax), %r14
movq 0x18(%rcx), %r15
xorl %r12d, %r12d
movq (%r14), %rdi
movq (%r15), %rsi
callq 0x46f0
testl %eax, %eax
jne 0x29eba
incq %r12
addq $0x10, %r14
addq $0x10, %r15
cmpq %r12, %rbx
jne 0x29e30
movq 0x88(%r13), %rbx
movl $0x1, %r14d
testq %rbx, %rbx
je 0x29ca4
movq 0x1e0(%rbx), %rdi
movslq 0x30(%r13), %rsi
shlq $0x2, %rsi
callq 0x4870
testq %rax, %rax
je 0x29e92
movslq 0x30(%r13), %rcx
movl %ebp, -0x4(%rax,%rcx,4)
movq %rax, 0x1e0(%rbx)
jmp 0x29ca4
leaq 0x88eb5(%rip), %rsi     # 0xb2d4e
leaq 0x89099(%rip), %rdx     # 0xb2f39
jmp 0x29ee8
movl $0xa, 0x20(%r13)
leaq 0x88e9d(%rip), %rsi     # 0xb2d4e
leaq 0x88fc9(%rip), %rdx     # 0xb2e81
jmp 0x29ee8
movl $0xa, 0x20(%r13)
leaq 0x88e85(%rip), %rsi     # 0xb2d4e
leaq 0x8900a(%rip), %rdx     # 0xb2eda
jmp 0x29ee8
movq $0x0, 0x48(%r13)
leaq 0x88e6d(%rip), %rsi     # 0xb2d4e
leaq 0x88f72(%rip), %rdx     # 0xb2e5a
xorl %r14d, %r14d
movl $0x1, %edi
xorl %eax, %eax
callq 0x9b31
jmp 0x29ca4