// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/vcf.c
// Function: bcf_hdr_subset
bcf_hdr_t *bcf_hdr_subset(const bcf_hdr_t *h0, int n, char *const* samples, int *imap)
{
    void *names_hash = khash_str2int_init();
    kstring_t htxt = {0,0,0};
    kstring_t str = {0,0,0};
    bcf_hdr_t *h = bcf_hdr_init("w");
    int r = 0;
    if (!h || !names_hash) {
        hts_log_error("Failed to allocate bcf header");
        goto err;
    }
    if (bcf_hdr_format(h0, 1, &htxt) < 0) {
        hts_log_error("Failed to get header text");
        goto err;
    }
    bcf_hdr_set_version(h,bcf_hdr_get_version(h0));
    int j;
    for (j=0; j<n; j++) imap[j] = -1;
    if ( bcf_hdr_nsamples(h0) > 0) {
        char *p = find_chrom_header_line(htxt.s);
        int i = 0, end = n? 8 : 7;
        while ((p = strchr(p, '\t')) != 0 && i < end) ++i, ++p;
        if (i != end) {
            hts_log_error("Wrong number of columns in header #CHROM line");
            goto err;
        }
        r |= kputsn(htxt.s, p - htxt.s, &str) < 0;
        for (i = 0; i < n; ++i) {
            if ( khash_str2int_has_key(names_hash,samples[i]) )
            {
                hts_log_error("Duplicate sample name \"%s\"", samples[i]);
                goto err;
            }
            imap[i] = bcf_hdr_id2int(h0, BCF_DT_SAMPLE, samples[i]);
            if (imap[i] < 0) continue;
            r |= kputc('\t', &str) < 0;
            r |= kputs(samples[i], &str) < 0;
            r |= khash_str2int_inc(names_hash,samples[i]) < 0;
        }
    } else r |= kputsn(htxt.s, htxt.l, &str) < 0;
    while (str.l && (!str.s[str.l-1] || str.s[str.l-1]=='\n') ) str.l--; // kill trailing zeros and newlines
    r |= kputc('\n',&str) < 0;
    if (r) {
        hts_log_error("%s", strerror(errno));
        goto err;
    }
    if ( bcf_hdr_parse(h, str.s) < 0 ) {
        bcf_hdr_destroy(h);
        h = NULL;
    }
    free(str.s);
    free(htxt.s);
    khash_str2int_destroy(names_hash);
    return h;

 err:
    ks_free(&str);
    ks_free(&htxt);
    khash_str2int_destroy(names_hash);
    bcf_hdr_destroy(h);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rcx, %r13
movq %rdx, 0x68(%rsp)
movl %esi, %ebp
movq %rdi, %r15
pushq $0x1
popq %rdi
pushq $0x28
popq %rsi
callq 0x42f0
movq %rax, %r12
pxor %xmm0, %xmm0
movdqa %xmm0, 0x70(%rsp)
andq $0x0, 0x80(%rsp)
movdqa %xmm0, 0x40(%rsp)
andq $0x0, 0x50(%rsp)
leaq 0x56da3(%rip), %rdi     # 0x843c1
callq 0x250c7
movq %rax, %rbx
testq %rax, %rax
setne %al
testq %r12, %r12
setne %cl
testb %al, %cl
je 0x2d67d
pushq $0x1
popq %rsi
leaq 0x70(%rsp), %rdx
movq %r15, %rdi
callq 0x25ea7
testl %eax, %eax
js 0x2da5e
movq %r15, %rdi
callq 0x24f9e
movq %rbx, %rdi
movq %rax, %rsi
callq 0x24fdf
xorl %eax, %eax
testl %ebp, %ebp
movl $0x0, %ecx
cmovgl %ebp, %ecx
cmpq %rax, %rcx
je 0x2d690
orl $-0x1, (%r13,%rax,4)
incq %rax
jmp 0x2d66d
leaq 0x5974a(%rip), %rsi     # 0x86dce
leaq 0x59080(%rip), %rdx     # 0x8670b
jmp 0x2da6c
cmpl $0x0, 0x8(%r15)
movq 0x80(%rsp), %r14
jle 0x2dab1
movq %rcx, 0x60(%rsp)
movq %r15, 0x90(%rsp)
movq %rbx, 0x28(%rsp)
leaq 0x5a696(%rip), %rsi     # 0x87d52
pushq $0x7
popq %rdx
movq %r14, %rdi
callq 0x4200
movl %eax, %ecx
movq %r14, %rax
testl %ecx, %ecx
je 0x2d6ec
leaq 0x5a67a(%rip), %rsi     # 0x87d51
movq %r14, %rdi
callq 0x40d0
movq %rax, %rcx
incq %rax
testq %rcx, %rcx
cmoveq %rcx, %rax
cmpl $0x1, %ebp
pushq $0x8
popq %rbx
sbbl $0x0, %ebx
xorl %r15d, %r15d
pushq $0x9
popq %rbp
movq %rax, %rdi
movl %ebp, %esi
callq 0x4180
testq %rax, %rax
je 0x2d717
cmpl %ebx, %r15d
jae 0x2d717
incl %r15d
incq %rax
jmp 0x2d6fb
cmpl %r15d, %ebx
jne 0x2daca
subq %r14, %rax
leaq 0x40(%rsp), %rdx
movq %r14, %rdi
movq %rax, %rsi
callq 0x2787b
shrl $0x1f, %eax
movl %eax, 0x18(%rsp)
xorl %r15d, %r15d
movq %r12, (%rsp)
movq 0x60(%rsp), %rax
movq %r13, 0x88(%rsp)
cmpq %rax, %r15
je 0x2dae7
movq 0x68(%rsp), %rax
movq %r15, 0x38(%rsp)
movq (%rax,%r15,8), %r8
movl (%r12), %eax
testl %eax, %eax
je 0x2d802
movq %rax, 0x30(%rsp)
leal -0x1(%rax), %ebx
movq %r8, %rdi
movq %r8, 0x20(%rsp)
callq 0x30cc9
movq 0x20(%rsp), %r8
movl %eax, %ebp
movl %ebx, 0x8(%rsp)
andl %ebx, %ebp
movq 0x10(%r12), %r15
pushq $0x1
popq %r14
movl %ebp, %ebx
movl %ebx, %eax
shrl $0x4, %eax
movl (%r15,%rax,4), %r13d
leal (%rbx,%rbx), %r12d
andl $0x1e, %r12d
movl %r13d, %eax
movl %r12d, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x2d7ee
testb $0x1, %al
jne 0x2d7de
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %ebx, %ecx
movq (%rax,%rcx,8), %rdi
movq %r8, %rsi
callq 0x46e0
movq 0x20(%rsp), %r8
testl %eax, %eax
je 0x2d7ee
addl %r14d, %ebx
andl 0x8(%rsp), %ebx
incl %r14d
cmpl %ebp, %ebx
jne 0x2d79e
jmp 0x2d80c
movl %r12d, %ecx
shrl %cl, %r13d
testb $0x3, %r13b
movq 0x30(%rsp), %rax
cmovnel %eax, %ebx
jmp 0x2d804
xorl %ebx, %ebx
cmpl %eax, %ebx
jne 0x2db97
movq 0x90(%rsp), %rdi
pushq $0x2
popq %rsi
movq %r8, %rdx
callq 0x2489c
movq 0x88(%rsp), %r13
movq 0x38(%rsp), %r15
movl %eax, (%r13,%r15,4)
testl %eax, %eax
js 0x2d887
pushq $0x9
popq %rdi
leaq 0x40(%rsp), %r14
movq %r14, %rsi
callq 0x25f76
movl %eax, %ebp
movq 0x68(%rsp), %rbx
movq (%rbx,%r15,8), %rdi
movq %r14, %rsi
callq 0x2783f
movl %eax, %r14d
movq (%rbx,%r15,8), %rax
movq %rax, 0x8(%rsp)
movq (%rsp), %r12
movl 0x8(%r12), %eax
cmpl 0xc(%r12), %eax
jb 0x2d8a5
movl (%r12), %esi
movl 0x4(%r12), %eax
addl %eax, %eax
cmpl %eax, %esi
jbe 0x2d890
decl %esi
jmp 0x2d892
movq (%rsp), %r12
jmp 0x2da51
incl %esi
movq %r12, %rdi
callq 0x314a7
pushq $-0x1
popq %rcx
testl %eax, %eax
js 0x2da42
movl %ebp, 0x1c(%rsp)
movl (%r12), %ebp
leal -0x1(%rbp), %ebx
movq 0x8(%rsp), %rdi
callq 0x30cc9
movl %eax, %edi
andl %ebx, %edi
movq 0x10(%r12), %rsi
movl %edi, %eax
shrl $0x4, %eax
movl (%rsi,%rax,4), %eax
leal (%rdi,%rdi), %ecx
shrl %cl, %eax
testb $0x2, %al
je 0x2d8db
movl %edi, %ebp
jmp 0x2d9a4
movl %r14d, 0x14(%rsp)
pushq $0x1
popq %r14
movl %edi, %r15d
movq %rbp, 0x58(%rsp)
movq %rdi, 0x20(%rsp)
movl %ebx, 0x30(%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 0x2d976
testb $0x1, %al
jne 0x2d943
movq (%rsp), %rax
movq 0x18(%rax), %rax
movl %r15d, %ecx
movq (%rax,%rcx,8), %rdi
movq %rsi, %rbx
movq 0x8(%rsp), %rsi
callq 0x46e0
movq 0x20(%rsp), %rdi
movq %rbx, %rsi
movl 0x30(%rsp), %ebx
testl %eax, %eax
je 0x2d976
btl %r12d, %r13d
cmovbl %r15d, %ebp
addl %r14d, %r15d
andl %ebx, %r15d
incl %r14d
cmpl %edi, %r15d
jne 0x2d8f5
movb $0x1, %al
movq 0x58(%rsp), %rdx
movl %edx, %ecx
cmpl %edx, %ebp
movq (%rsp), %r12
movq 0x38(%rsp), %r15
movl 0x14(%rsp), %r14d
je 0x2d996
jmp 0x2d9a4
movl %r12d, %ecx
shrl %cl, %r13d
testb $0x2, %r13b
sete %al
movl %ebp, %ecx
movl %r15d, %edi
movq (%rsp), %r12
movq 0x38(%rsp), %r15
movl 0x14(%rsp), %r14d
cmpl 0x58(%rsp), %ecx
cmovel %edi, %ecx
testb %al, %al
cmovnel %edi, %ecx
movl %ecx, %ebp
movl %ebp, %edx
shrl $0x4, %edx
movl (%rsi,%rdx,4), %esi
leal (,%rbp,2), %ecx
andl $0x1e, %ecx
shrl %cl, %esi
movl %ebp, %eax
testb $0x2, %sil
jne 0x2d9d4
testb $0x1, %sil
movl 0x1c(%rsp), %ebp
jne 0x2da10
movq 0x20(%r12), %rcx
movl (%rcx,%rax,4), %ecx
jmp 0x2da42
movq 0x18(%r12), %rsi
movq 0x8(%rsp), %rdi
movq %rdi, (%rsi,%rax,8)
pushq $0x3
popq %rsi
shll %cl, %esi
notl %esi
movq 0x10(%r12), %rcx
andl %esi, (%rcx,%rdx,4)
movq 0x4(%r12), %rcx
movq %rcx, %xmm0
psubd 0x562dd(%rip), %xmm0    # 0x83ce0
movq %xmm0, 0x4(%r12)
movl 0x1c(%rsp), %ebp
jmp 0x2da3a
movq 0x18(%r12), %rsi
movq 0x8(%rsp), %rdi
movq %rdi, (%rsi,%rax,8)
pushq $0x3
popq %rsi
shll %cl, %esi
notl %esi
movq 0x10(%r12), %rcx
andl %esi, (%rcx,%rdx,4)
movl 0x4(%r12), %ecx
leal 0x1(%rcx), %edx
movl %edx, 0x4(%r12)
movq 0x20(%r12), %rdx
movl %ecx, (%rdx,%rax,4)
orl %ebp, %r14d
orl %ecx, %r14d
shrl $0x1f, %r14d
orl %r14d, 0x18(%rsp)
incq %r15
movq 0x60(%rsp), %rax
jmp 0x2d74e
leaq 0x59369(%rip), %rsi     # 0x86dce
leaq 0x59371(%rip), %rdx     # 0x86ddd
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x8132
leaq 0x40(%rsp), %rdi
callq 0x2dbee
leaq 0x70(%rsp), %rdi
callq 0x2dbee
movq %r12, %rdi
callq 0x2dbc0
movq %rbx, %rdi
callq 0x25554
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x70(%rsp), %rsi
leaq 0x40(%rsp), %rdx
movq %r14, %rdi
callq 0x2787b
movl %eax, %ebp
shrl $0x1f, %ebp
jmp 0x2daf0
leaq 0x592fd(%rip), %rsi     # 0x86dce
leaq 0x5931f(%rip), %rdx     # 0x86df7
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x8132
jmp 0x2dbb6
movq 0x28(%rsp), %rbx
movl 0x18(%rsp), %ebp
movq 0x40(%rsp), %rax
movq 0x50(%rsp), %rcx
decq %rax
cmpq $-0x1, %rax
je 0x2db17
movzbl (%rcx,%rax), %edx
cmpl $0xa, %edx
je 0x2db10
testl %edx, %edx
jne 0x2db17
movq %rax, 0x40(%rsp)
jmp 0x2dafa
pushq $0xa
popq %rdi
leaq 0x40(%rsp), %rsi
callq 0x25f76
shrl $0x1f, %eax
orl %ebp, %eax
je 0x2db57
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0x59290(%rip), %rsi     # 0x86dce
leaq 0x5877b(%rip), %rdx     # 0x862c0
pushq $0x1
popq %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x8132
jmp 0x2da76
movq 0x50(%rsp), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x248c9
testl %eax, %eax
jns 0x2db75
movq %rbx, %rdi
callq 0x25554
xorl %ebx, %ebx
movq %r14, %rdi
callq 0x45c0
movq 0x80(%rsp), %rdi
callq 0x45c0
movq %r12, %rdi
callq 0x2dbc0
jmp 0x2da9c
leaq 0x59230(%rip), %rsi     # 0x86dce
leaq 0x59280(%rip), %rdx     # 0x86e25
pushq $0x1
popq %rdi
movq %r8, %rcx
xorl %eax, %eax
callq 0x8132
movq (%rsp), %r12
movq 0x28(%rsp), %rbx
jmp 0x2da76