// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/synced_bcf_reader.c
// Function: bcf_sr_set_samples
int bcf_sr_set_samples(bcf_srs_t *files, const char *fname, int is_file)
{
    int i, j, nsmpl, free_smpl = 0;
    char **smpl = NULL;

    void *exclude = (fname[0]=='^') ? khash_str2int_init() : NULL;
    if ( exclude || strcmp("-",fname) ) // "-" stands for all samples
    {
        smpl = hts_readlist(fname, is_file, &nsmpl);
        if ( !smpl )
        {
            hts_log_error("Could not read the file: \"%s\"", fname);
            return 0;
        }
        if ( exclude )
        {
            for (i=0; i<nsmpl; i++)
                khash_str2int_inc(exclude, smpl[i]);
        }
        free_smpl = 1;
    }
    if ( !smpl )
    {
        smpl  = files->readers[0].header->samples;   // intersection of all samples
        nsmpl = bcf_hdr_nsamples(files->readers[0].header);
    }

    files->samples = NULL;
    files->n_smpl  = 0;
    for (i=0; i<nsmpl; i++)
    {
        if ( exclude && khash_str2int_has_key(exclude,smpl[i])  ) continue;

        int n_isec = 0;
        for (j=0; j<files->nreaders; j++)
        {
            if ( bcf_hdr_id2int(files->readers[j].header, BCF_DT_SAMPLE, smpl[i])<0 ) break;
            n_isec++;
        }
        if ( n_isec!=files->nreaders )
        {
            hts_log_warning("The sample \"%s\" was not found in %s, skipping",
                smpl[i], files->readers[n_isec].fname);
            continue;
        }

        files->samples = (char**) realloc(files->samples, (files->n_smpl+1)*sizeof(const char*));
        files->samples[files->n_smpl++] = strdup(smpl[i]);
    }

    if ( exclude ) khash_str2int_destroy(exclude);
    if ( free_smpl )
    {
        for (i=0; i<nsmpl; i++) free(smpl[i]);
        free(smpl);
    }

    if ( !files->n_smpl )
    {
        if ( files->nreaders>1 )
            hts_log_warning("No samples in common");
        return 0;
    }
    for (i=0; i<files->nreaders; i++)
    {
        bcf_sr_t *reader = &files->readers[i];
        reader->samples  = (int*) malloc(sizeof(int)*files->n_smpl);
        reader->n_smpl   = files->n_smpl;
        for (j=0; j<files->n_smpl; j++)
            reader->samples[j] = bcf_hdr_id2int(reader->header, BCF_DT_SAMPLE, files->samples[j]);
    }
    return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %rbx
movzbl (%rsi), %eax
cmpl $0x5e, %eax
jne 0x22f84
callq 0x23246
movq %rax, 0x8(%rsp)
testq %rax, %rax
sete %r15b
jmp 0x22fa5
subl $0x2d, %eax
jne 0x22f8f
movzbl 0x1(%r12), %eax
negl %eax
testl %eax, %eax
je 0x23049
movb $0x1, %r15b
movq $0x0, 0x8(%rsp)
leaq 0x4(%rsp), %rdx
movq %r12, %rdi
movl %ebp, %esi
callq 0xa01b
testq %rax, %rax
je 0x22fd4
movq %rax, %r14
testb %r15b, %r15b
je 0x22ff6
movb $0x1, %al
movl %eax, 0x18(%rsp)
movl $0x0, 0x14(%rsp)
jmp 0x23071
leaq 0x67f68(%rip), %rsi     # 0x8af43
leaq 0x67f74(%rip), %rdx     # 0x8af56
xorl %ebp, %ebp
pushq $0x1
popq %rdi
movq %r12, %rcx
xorl %eax, %eax
callq 0x86fa
jmp 0x23235
xorl %r15d, %r15d
leaq 0x24(%rsp), %r12
movq 0x8(%rsp), %r13
movslq 0x4(%rsp), %rax
cmpq %rax, %r15
jge 0x23037
movq (%r14,%r15,8), %rsi
movq %r13, %rdi
movq %r12, %rdx
callq 0x23a88
cmpl $0x0, 0x24(%rsp)
jle 0x23032
movl 0x4(%r13), %ecx
decl %ecx
movq 0x20(%r13), %rdx
movl %eax, %eax
movl %ecx, (%rdx,%rax,4)
incq %r15
jmp 0x23003
movl $0x0, 0x14(%rsp)
movl $0x0, 0x18(%rsp)
jmp 0x23071
movq 0x28(%rbx), %rax
movq 0x18(%rax), %rax
movq 0x40(%rax), %r14
movl 0x8(%rax), %eax
movl %eax, 0x4(%rsp)
movb $0x1, %al
movl %eax, 0x14(%rsp)
movq $0x0, 0x8(%rsp)
movb $0x1, %al
movl %eax, 0x18(%rsp)
andq $0x0, 0x40(%rbx)
andl $0x0, 0x78(%rbx)
pushq $0x2
popq %rbp
xorl %r12d, %r12d
movslq 0x4(%rsp), %rax
cmpq %rax, %r12
jge 0x2314a
cmpb $0x0, 0x18(%rsp)
jne 0x230af
movq (%r14,%r12,8), %rsi
movq 0x8(%rsp), %r15
movq %r15, %rdi
callq 0x239ad
cmpl (%r15), %eax
jne 0x23142
xorl %r13d, %r13d
xorl %r15d, %r15d
movslq 0x30(%rbx), %rax
cmpq %rax, %r15
jge 0x230e2
movq 0x28(%rbx), %rax
movq 0x18(%rax,%r13), %rdi
movq (%r14,%r12,8), %rdx
movl %ebp, %esi
callq 0x29398
testl %eax, %eax
js 0x230df
incq %r15
addq $0x60, %r13
jmp 0x230b5
movl 0x30(%rbx), %eax
cmpl %r15d, %eax
jne 0x2311d
movq 0x40(%rbx), %rdi
movslq 0x78(%rbx), %rax
leaq 0x8(,%rax,8), %rsi
callq 0x4870
movq %rax, %r13
movq %rax, 0x40(%rbx)
movq (%r14,%r12,8), %rdi
callq 0x4950
movslq 0x78(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x78(%rbx)
movq %rax, (%r13,%rcx,8)
jmp 0x23142
movq (%r14,%r12,8), %rcx
movq 0x28(%rbx), %rax
movq 0x28(%rax,%r13), %r8
pushq $0x3
popq %rdi
leaq 0x67e0f(%rip), %rsi     # 0x8af43
leaq 0x67e39(%rip), %rdx     # 0x8af74
xorl %eax, %eax
callq 0x86fa
incq %r12
jmp 0x23080
cmpb $0x0, 0x18(%rsp)
jne 0x2315b
movq 0x8(%rsp), %rdi
callq 0x23251
cmpb $0x0, 0x14(%rsp)
jne 0x23185
xorl %r15d, %r15d
movslq 0x4(%rsp), %rax
cmpq %rax, %r15
jge 0x2317d
movq (%r14,%r15,8), %rdi
callq 0x45d0
incq %r15
jmp 0x23165
movq %r14, %rdi
callq 0x45d0
movl 0x78(%rbx), %r12d
testl %r12d, %r12d
je 0x23213
xorl %ecx, %ecx
pushq $0x2
popq %r14
movslq 0x30(%rbx), %rax
cmpq %rax, %rcx
jge 0x2320e
movq 0x28(%rbx), %rbp
movq %rcx, 0x18(%rsp)
imulq $0x60, %rcx, %r15
leaq (%r15,%rbp), %r13
movslq %r12d, %rax
movq %rax, 0x8(%rsp)
leaq (,%rax,4), %rdi
callq 0x46b0
movq %rax, 0x50(%rbp,%r15)
movq 0x8(%rsp), %rax
movl %eax, 0x58(%rbp,%r15)
xorl %ebp, %ebp
movslq %r12d, %rax
cmpq %rax, %rbp
jge 0x23204
movq 0x18(%r13), %rdi
movq 0x40(%rbx), %rax
movq (%rax,%rbp,8), %rdx
movl %r14d, %esi
callq 0x29398
movq 0x50(%r13), %rcx
movl %eax, (%rcx,%rbp,4)
incq %rbp
movl 0x78(%rbx), %r12d
jmp 0x231d8
movq 0x18(%rsp), %rcx
incq %rcx
jmp 0x23198
pushq $0x1
popq %rbp
jmp 0x23235
xorl %ebp, %ebp
cmpl $0x2, 0x30(%rbx)
jl 0x23235
leaq 0x67d21(%rip), %rsi     # 0x8af43
leaq 0x67d79(%rip), %rdx     # 0x8afa2
xorl %ebp, %ebp
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x86fa
movl %ebp, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq