// File: /workspace/github_c_makefile_star2_O2/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 0x2188d
movq %rcx, %r15
movl %edx, %ebx
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
andl $0x0, (%rax,%rcx,4)
movq 0x28(%r13), %rdi
imulq $0x60, %rcx, %rsi
addq $0x60, %rsi
callq 0x4870
movq %rax, 0x28(%r13)
movslq 0x30(%r13), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x30(%r13)
imulq $0x60, %rcx, %rcx
xorps %xmm0, %xmm0
movups %xmm0, 0x8(%rax,%rcx)
movups %xmm0, 0x18(%rax,%rcx)
movups %xmm0, 0x28(%rax,%rcx)
movups %xmm0, 0x38(%rax,%rcx)
movups %xmm0, 0x48(%rax,%rcx)
andq $0x0, 0x58(%rax,%rcx)
movq %r14, (%rax,%rcx)
andl $0x0, 0x20(%r13)
addq %rcx, %rax
movq %rax, 0x10(%rsp)
cmpl $0x2, 0x54(%r14)
jne 0x21834
movq %r14, %rdi
callq 0x9d88
movq %rax, %r12
testq %rax, %rax
je 0x2181a
movq %r12, %rdi
callq 0x73295
testl %eax, %eax
jne 0x2181a
movl $0x6, 0x20(%r13)
movq 0x28(%r14), %rcx
leaq 0x694e5(%rip), %rsi     # 0x8acee
leaq 0x694f1(%rip), %rdx     # 0x8ad01
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x86fa
movq 0x80(%r13), %rax
testq %rax, %rax
je 0x21834
movq (%rax), %rsi
movl 0x8(%rax), %edx
movq %r12, %rdi
callq 0x721fb
cmpl $0x1, 0x10(%r13)
movq 0x10(%rsp), %r12
movq (%r12), %rdi
movl 0x4c(%rdi), %eax
jne 0x21897
cmpl $0x9, %eax
je 0x21a42
cmpl $0x8, %eax
jne 0x2192a
cmpl $0x2, 0x54(%rdi)
jne 0x21a76
movq 0x28(%r14), %rdi
movq %r15, %rsi
callq 0x2509a
movq %rax, 0x8(%r12)
testq %rax, %rax
je 0x21a6c
movq (%r12), %rdi
callq 0x2a1c2
movq %rax, 0x18(%r12)
jmp 0x218b5
andl $0x0, 0x20(%r13)
jmp 0x21a88
andl $-0x2, %eax
cmpl $0x8, %eax
jne 0x2192a
callq 0x2a1c2
movq %rax, 0x18(%r12)
movl $0x1, 0x34(%r13)
cmpl $0x0, 0x34(%r13)
je 0x21937
cmpl $0x2, 0x30(%r13)
jl 0x21908
movl 0x10(%r13), %eax
cmpl $0x2, %eax
jne 0x218f8
testb $0x1, 0x9565d(%rip)     # 0xb6f30
jne 0x218f8
leaq 0x69412(%rip), %rsi     # 0x8acee
leaq 0x6944d(%rip), %rdx     # 0x8ad30
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x86fa
movb $0x1, 0x9563c(%rip)     # 0xb6f30
movl 0x10(%r13), %eax
cmpl $0x2, %eax
jne 0x21a9d
cmpl $0x0, 0x34(%r13)
je 0x21937
cmpq $0x0, 0x48(%r13)
je 0x21937
movl $0x4, 0x20(%r13)
leaq 0x693d0(%rip), %rsi     # 0x8acee
leaq 0x694b1(%rip), %rdx     # 0x8add6
jmp 0x21c75
movl $0x3, 0x20(%r13)
jmp 0x21a88
movq 0x18(%r12), %rax
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x21a80
movl %ebx, 0x1c(%rsp)
movq 0x28(%r14), %rdi
callq 0x4950
movq %rax, 0x28(%r12)
movq 0x8(%r13), %rcx
testq %rcx, %rcx
je 0x21b05
movq %r13, 0x40(%rsp)
xorps %xmm0, %xmm0
leaq 0x20(%rsp), %rax
movaps %xmm0, (%rax)
andq $0x0, 0x10(%rax)
leaq 0x1(%rcx), %rsi
movq $0x0, 0x8(%rsp)
movq %rcx, %r15
xorl %r12d, %r12d
xorl %ebx, %ebx
movzbl -0x1(%rsi), %eax
cmpl $0x2c, %eax
je 0x219a4
testl %eax, %eax
jne 0x21a37
movq %rsi, 0x50(%rsp)
movq %rcx, %r13
movslq %r12d, %r14
leaq 0x4(,%r14,4), %rsi
movq %rbx, %rdi
callq 0x4870
movq %rax, %rbp
testq %rax, %rax
je 0x21ab8
leal 0x1(%r12), %ebx
movq %r15, %rsi
subq %r13, %rsi
cmpq $0x1, %rsi
jne 0x219eb
cmpb $0x2e, (%r13)
jne 0x219eb
orl $-0x1, (%rbp,%r14,4)
jmp 0x21a1f
andq $0x0, 0x20(%rsp)
movq %r13, %rdi
leaq 0x20(%rsp), %rdx
callq 0x2386c
movq 0x30(%rsp), %rdx
movq 0x48(%rsp), %rdi
xorl %esi, %esi
movq %rdx, 0x8(%rsp)
callq 0x29398
movl %eax, (%rbp,%r14,4)
testl %eax, %eax
cmovsl %r12d, %ebx
movq 0x50(%rsp), %rsi
cmpb $0x0, -0x1(%rsi)
je 0x21ade
movq %rsi, %rcx
movl %ebx, %r12d
movq %rbp, %rbx
incq %rsi
incq %r15
jmp 0x21993
cmpl $0x2, 0x54(%rdi)
jne 0x21a76
callq 0x2a1c2
movq %rax, 0x18(%r12)
movq 0x28(%r14), %rdi
movq %r15, %rsi
callq 0x3128d
movq %rax, 0x10(%r12)
testq %rax, %rax
jne 0x218b5
movl $0x2, 0x20(%r13)
jmp 0x21a88
movl $0x1, 0x20(%r13)
jmp 0x21a88
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 0x69242(%rip), %rsi     # 0x8acee
leaq 0x692dd(%rip), %rdx     # 0x8ad90
jmp 0x21c75
cmpq $0x0, 0x28(%rsp)
je 0x21aca
movq 0x8(%rsp), %rdi
callq 0x45d0
movq %rbx, %rdi
callq 0x45d0
movq 0x40(%rsp), %r13
movq 0x10(%rsp), %r12
jmp 0x21b00
cmpq $0x0, 0x28(%rsp)
je 0x21af0
movq 0x8(%rsp), %rdi
callq 0x45d0
movq 0x10(%rsp), %rax
movl %ebx, 0x40(%rax)
movq %rax, %r12
movq 0x40(%rsp), %r13
movq %rbp, 0x48(%r12)
cmpl $0x0, 0x38(%r13)
jne 0x21b96
cmpl $0x0, 0x34(%r13)
jne 0x21b96
andl $0x0, 0x20(%rsp)
cmpq $0x0, 0x48(%r13)
jne 0x21b35
callq 0x21c97
movq %rax, 0x48(%r13)
testq %rax, %rax
je 0x21c87
movq 0x8(%r12), %rdi
testq %rdi, %rdi
je 0x21b4b
leaq 0x20(%rsp), %rsi
callq 0x250ac
jmp 0x21b5a
movq 0x18(%r12), %rdi
leaq 0x20(%rsp), %rsi
callq 0x2c5fe
movq %rax, %r14
xorl %ebx, %ebx
pushq $-0x1
popq %r15
movslq 0x20(%rsp), %rax
cmpq %rax, %rbx
jge 0x21b85
movq 0x48(%r13), %rdi
movq (%r14,%rbx,8), %rsi
movq %r15, %rdx
movq %r15, %rcx
callq 0x21cc7
incq %rbx
jmp 0x21b63
movq %r14, %rdi
callq 0x45d0
movq 0x48(%r13), %rdi
callq 0x21e55
cmpl $0x2, 0x10(%r13)
jne 0x21c0a
cmpl $0x2, 0x30(%r13)
jl 0x21c0a
movq 0x28(%r13), %rax
movq 0x18(%rax), %r14
movq 0x18(%r12), %r15
movl 0x4(%r14), %ebx
cmpl 0x4(%r15), %ebx
jne 0x21c5f
xorl %ebp, %ebp
testl %ebx, %ebx
cmovlel %ebp, %ebx
cmpl %ebp, %ebx
je 0x21c0a
movq %r14, %rdi
movl %ebp, %esi
callq 0x21f24
movq %rax, %r12
movq %r15, %rdi
movl %ebp, %esi
callq 0x21f24
movq %r12, %rdi
movq %rax, %rsi
callq 0x46f0
incl %ebp
testl %eax, %eax
je 0x21bc6
movl $0xa, 0x20(%r13)
leaq 0x690ed(%rip), %rsi     # 0x8acee
leaq 0x69272(%rip), %rdx     # 0x8ae7a
jmp 0x21c75
movq 0x88(%r13), %rbx
pushq $0x1
popq %r14
testq %rbx, %rbx
je 0x21a8b
movq 0x1e0(%rbx), %rdi
movslq 0x30(%r13), %rsi
shlq $0x2, %rsi
callq 0x4870
testq %rax, %rax
je 0x21c4f
movslq 0x30(%r13), %rcx
movl 0x1c(%rsp), %edx
movl %edx, -0x4(%rax,%rcx,4)
movq %rax, 0x1e0(%rbx)
jmp 0x21a8b
leaq 0x69098(%rip), %rsi     # 0x8acee
leaq 0x6927c(%rip), %rdx     # 0x8aed9
jmp 0x21c75
movl $0xa, 0x20(%r13)
leaq 0x69080(%rip), %rsi     # 0x8acee
leaq 0x691ac(%rip), %rdx     # 0x8ae21
xorl %r14d, %r14d
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x86fa
jmp 0x21a8b
leaq 0x69060(%rip), %rsi     # 0x8acee
leaq 0x69165(%rip), %rdx     # 0x8adfa
jmp 0x21c75