// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movl %edx, %ebp
movq %rsi, %r12
movq %rdi, %rbx
cmpb $0x5e, (%rsi)
jne 0x2c74e
movl $0x1, %edi
movl $0x28, %esi
callq 0x42f0
movq %rax, %r13
jmp 0x2c751
xorl %r13d, %r13d
testq %r13, %r13
jne 0x2c76d
leaq 0x875ca(%rip), %rdi     # 0xb3d27
movq %r12, %rsi
callq 0x46f0
testl %eax, %eax
je 0x2c7f9
leaq 0x8(%rsp), %rdx
movq %r12, %rdi
movl %ebp, %esi
callq 0xb842
testq %rax, %rax
je 0x2c7d5
movq %rax, %rbp
testq %r13, %r13
je 0x2c7cb
cmpl $0x0, 0x8(%rsp)
jle 0x2c7cb
xorl %r14d, %r14d
leaq 0x24(%rsp), %r12
movq (%rbp,%r14,8), %rsi
movq %r13, %rdi
movq %r12, %rdx
callq 0x2d3e5
cmpl $0x0, 0x24(%rsp)
jle 0x2c7be
movl 0x4(%r13), %ecx
decl %ecx
movq 0x20(%r13), %rdx
movl %eax, %eax
movl %ecx, (%rdx,%rax,4)
incq %r14
movslq 0x8(%rsp), %rax
cmpq %rax, %r14
jl 0x2c798
movl $0x0, 0xc(%rsp)
jmp 0x2c801
leaq 0x887d7(%rip), %rsi     # 0xb4fb3
leaq 0x887e3(%rip), %rdx     # 0xb4fc6
xorl %ebp, %ebp
movl $0x1, %edi
movq %r12, %rcx
xorl %eax, %eax
callq 0x9e34
jmp 0x2cb0c
movb $0x1, %al
movl %eax, 0xc(%rsp)
xorl %ebp, %ebp
testq %rbp, %rbp
jne 0x2c819
movq 0x28(%rbx), %rax
movq 0x18(%rax), %rax
movq 0x40(%rax), %rbp
movl 0x8(%rax), %eax
movl %eax, 0x8(%rsp)
movq $0x0, 0x40(%rbx)
movl $0x0, 0x78(%rbx)
cmpl $0x0, 0x8(%rsp)
jle 0x2ca0e
xorl %r12d, %r12d
movq %rbp, 0x30(%rsp)
movq %r13, 0x18(%rsp)
movq %rbx, 0x28(%rsp)
testq %r13, %r13
je 0x2c949
movl (%r13), %eax
testl %eax, %eax
je 0x2c88d
movq %rax, 0x10(%rsp)
movq (%rbp,%r12,8), %rbx
movb (%rbx), %cl
testb %cl, %cl
movq %r12, 0x38(%rsp)
je 0x2c895
leaq 0x1(%rbx), %rax
movl $0x811c9dc5, %r14d      # imm = 0x811C9DC5
movzbl %cl, %ecx
xorl %r14d, %ecx
imull $0x1000193, %ecx, %r14d # imm = 0x1000193
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x2c875
jmp 0x2c89b
xorl %r15d, %r15d
jmp 0x2c940
movl $0x811c9dc5, %r14d      # imm = 0x811C9DC5
movq 0x10(%rsp), %rax
leal -0x1(%rax), %edx
andl %edx, %r14d
movq 0x10(%r13), %rsi
movl $0x1, %ebp
movl %r14d, %r15d
movl %edx, 0x20(%rsp)
movq %rsi, 0x40(%rsp)
movl %r15d, %eax
shrl $0x4, %eax
movl (%rsi,%rax,4), %r13d
leal (%r15,%r15), %r12d
andl $0x1e, %r12d
movl %r13d, %eax
movl %r12d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x2c919
testb $0x1, %al
jne 0x2c902
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rbx, %rsi
callq 0x46f0
movq 0x40(%rsp), %rsi
movl 0x20(%rsp), %edx
testl %eax, %eax
je 0x2c919
addl %ebp, %r15d
andl %edx, %r15d
incl %ebp
cmpl %r14d, %r15d
jne 0x2c8bb
movq 0x10(%rsp), %rax
movl %eax, %r15d
jmp 0x2c92c
movl %r12d, %ecx
shrl %cl, %r13d
testb $0x3, %r13b
movq 0x10(%rsp), %rax
cmovnel %eax, %r15d
movq 0x18(%rsp), %r13
movq 0x30(%rsp), %rbp
movq 0x38(%rsp), %r12
movq 0x28(%rsp), %rbx
cmpl %eax, %r15d
jne 0x2c9fd
cmpl $0x0, 0x30(%rbx)
jle 0x2c985
movl $0x18, %r15d
xorl %r14d, %r14d
movq 0x28(%rbx), %rax
movq (%rax,%r15), %rdi
movq (%rbp,%r12,8), %rdx
movl $0x2, %esi
callq 0x33da1
testl %eax, %eax
js 0x2c988
incq %r14
movslq 0x30(%rbx), %rax
addq $0x60, %r15
cmpq %rax, %r14
jl 0x2c958
jmp 0x2c988
xorl %r14d, %r14d
cmpl 0x30(%rbx), %r14d
jne 0x2c9ca
movq 0x40(%rbx), %rdi
movslq 0x78(%rbx), %rax
leaq 0x8(,%rax,8), %rsi
callq 0x4870
movq %r12, %r14
movq %rax, %r12
movq %rax, 0x40(%rbx)
movq (%rbp,%r14,8), %rdi
callq 0x4950
movslq 0x78(%rbx), %rcx
leal 0x1(%rcx), %edx
movl %edx, 0x78(%rbx)
movq %rax, (%r12,%rcx,8)
movq %r14, %r12
jmp 0x2c9fd
movq (%rbp,%r12,8), %rcx
movq 0x28(%rbx), %rax
movl %r14d, %edx
leaq (%rdx,%rdx,2), %rdx
shlq $0x5, %rdx
movq 0x28(%rax,%rdx), %r8
movl $0x3, %edi
leaq 0x885c4(%rip), %rsi     # 0xb4fb3
leaq 0x885ee(%rip), %rdx     # 0xb4fe4
xorl %eax, %eax
callq 0x9e34
incq %r12
movslq 0x8(%rsp), %rax
cmpq %rax, %r12
jl 0x2c845
testq %r13, %r13
je 0x2ca36
movq 0x18(%r13), %rdi
callq 0x45d0
movq 0x10(%r13), %rdi
callq 0x45d0
movq 0x20(%r13), %rdi
callq 0x45d0
movq %r13, %rdi
callq 0x45d0
cmpb $0x0, 0xc(%rsp)
jne 0x2ca66
cmpl $0x0, 0x8(%rsp)
jle 0x2ca5e
xorl %r14d, %r14d
movq (%rbp,%r14,8), %rdi
callq 0x45d0
incq %r14
movslq 0x8(%rsp), %rax
cmpq %rax, %r14
jl 0x2ca47
movq %rbp, %rdi
callq 0x45d0
cmpl $0x0, 0x78(%rbx)
movl 0x30(%rbx), %eax
je 0x2cae9
movl $0x1, %ebp
testl %eax, %eax
jle 0x2cb0c
xorl %r14d, %r14d
movq 0x28(%rbx), %r15
leaq (%r14,%r14,2), %r12
shlq $0x5, %r12
movslq 0x78(%rbx), %r13
movq %r13, %rdi
shlq $0x2, %rdi
callq 0x46b0
movq %rax, 0x50(%r15,%r12)
movl %r13d, 0x58(%r15,%r12)
cmpl $0x0, 0x78(%rbx)
jle 0x2cadb
addq %r12, %r15
xorl %r12d, %r12d
movq 0x18(%r15), %rdi
movq 0x40(%rbx), %rax
movq (%rax,%r12,8), %rdx
movl $0x2, %esi
callq 0x33da1
movq 0x50(%r15), %rcx
movl %eax, (%rcx,%r12,4)
incq %r12
movslq 0x78(%rbx), %rax
cmpq %rax, %r12
jl 0x2cab1
incq %r14
movslq 0x30(%rbx), %rax
cmpq %rax, %r14
jl 0x2ca7f
jmp 0x2cb0c
xorl %ebp, %ebp
cmpl $0x2, %eax
jl 0x2cb0c
leaq 0x884bc(%rip), %rsi     # 0xb4fb3
leaq 0x88514(%rip), %rdx     # 0xb5012
xorl %ebp, %ebp
movl $0x3, %edi
xorl %eax, %eax
callq 0x9e34
movl %ebp, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq