// File: /workspace/github_c_makefile_star2_O1/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 $0xa8, %rsp
movq %rcx, 0x98(%rsp)
movq %rdx, 0x58(%rsp)
movl %esi, %ebp
movq %rdi, %rbx
movl $0x1, %edi
movl $0x28, %esi
callq 0x42f0
movq %rax, %r13
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movq $0x0, 0x80(%rsp)
leaq 0x6eb0c(%rip), %rdi     # 0xac451
callq 0x2f149
movq %rax, %r15
testq %rax, %rax
setne %al
testq %r13, %r13
setne %cl
testb %al, %cl
je 0x3daa3
leaq 0x70(%rsp), %rdx
movq %rbx, %rdi
movl $0x1, %esi
callq 0x30754
testl %eax, %eax
js 0x3dab3
movq %rbx, %rdi
callq 0x2f013
movq %r15, %rdi
movq %rax, %rsi
callq 0x2f058
testl %ebp, %ebp
jle 0x3d9aa
movl %ebp, %edx
shlq $0x2, %rdx
movq 0x98(%rsp), %rdi
movl $0xff, %esi
callq 0x4250
movq %rbx, 0x20(%rsp)
cmpl $0x0, 0x8(%rbx)
movq 0x80(%rsp), %r12
jle 0x3db40
leaq 0x7267e(%rip), %rsi     # 0xb0046
movl $0x7, %edx
movq %r12, %rdi
callq 0x4200
movq %r12, %rdi
testl %eax, %eax
je 0x3d9f6
leaq 0x72662(%rip), %rsi     # 0xb0045
movq %r12, %rdi
callq 0x40d0
leaq 0x1(%rax), %rdi
testq %rax, %rax
cmoveq %rax, %rdi
cmpl $0x1, %ebp
movl $0x8, %ebx
sbbl $0x0, %ebx
movl $0x9, %esi
callq 0x4180
movq %rax, %rdi
xorl %r14d, %r14d
testq %rax, %rax
je 0x3da33
incl %r14d
incq %rdi
movl $0x9, %esi
callq 0x4180
movq %rax, %rdi
testq %rax, %rax
je 0x3da33
cmpl %ebx, %r14d
jb 0x3da16
cmpl %ebx, %r14d
jne 0x3dba3
movabsq $0x3fffffffffffffff, %rdx # imm = 0x3FFFFFFFFFFFFFFF
subq %r12, %rdi
movq %rdi, %rax
addq $0x2, %rax
je 0x3dbf9
movq %rdi, %r14
movq %rax, %rdi
shrq %rdi
xorl %ecx, %ecx
cmpq %rdx, %rax
cmovaq %rcx, %rdi
addq %rax, %rdi
movq %rdi, 0x8(%rsp)
callq 0x46a0
testq %rax, %rax
je 0x3dc33
movq %rax, %rbx
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x43c0
movb $0x0, (%rbx,%r14)
movl %r14d, %eax
shrl $0x1f, %eax
movl %eax, 0x4(%rsp)
jmp 0x3dc49
leaq 0x71618(%rip), %rsi     # 0xaf0c2
leaq 0x70f5a(%rip), %rdx     # 0xaea0b
jmp 0x3dac1
leaq 0x71608(%rip), %rsi     # 0xaf0c2
leaq 0x71610(%rip), %rdx     # 0xaf0d1
xorl %ebp, %ebp
movl $0x1, %edi
xorl %eax, %eax
callq 0x9774
movq %rbp, %rdi
callq 0x45c0
movq 0x80(%rsp), %rdi
callq 0x45c0
xorps %xmm0, %xmm0
movaps %xmm0, 0x70(%rsp)
movq $0x0, 0x80(%rsp)
testq %r13, %r13
je 0x3db20
movq 0x18(%r13), %rdi
callq 0x45c0
movq 0x10(%r13), %rdi
callq 0x45c0
movq 0x20(%r13), %rdi
callq 0x45c0
movq %r13, %rdi
callq 0x45c0
movq %r15, %rdi
callq 0x2f696
xorl %r15d, %r15d
movq %r15, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x70(%rsp), %r14
movq %r14, %rax
addq $0x2, %rax
je 0x3dbd5
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %rdi
shrq %rdi
xorl %ebp, %ebp
testq %rcx, %rcx
cmovneq %rbp, %rdi
addq %rax, %rdi
movq %rdi, 0x8(%rsp)
callq 0x46a0
testq %rax, %rax
je 0x3dc1c
movq %rax, %rbx
movq %rax, %rdi
movq %r12, %rsi
movq %r14, %rdx
callq 0x43c0
movb $0x0, (%rbx,%r14)
movl %r14d, %r12d
shrl $0x1f, %r12d
movq %rbx, %rbp
jmp 0x3e187
leaq 0x71518(%rip), %rsi     # 0xaf0c2
leaq 0x7153a(%rip), %rdx     # 0xaf0eb
movl $0x1, %edi
xorl %eax, %eax
callq 0x9774
xorl %r14d, %r14d
movq $0x0, 0x8(%rsp)
xorl %ebp, %ebp
xorl %r12d, %r12d
xorl %eax, %eax
jmp 0x3e17f
callq 0x4050
movl $0x4b, (%rax)
movl $0x1, %r12d
xorl %r14d, %r14d
movq $0x0, 0x8(%rsp)
xorl %ebp, %ebp
jmp 0x3e187
callq 0x4050
movl $0x4b, (%rax)
movl $0x1, 0x4(%rsp)
xorl %r14d, %r14d
movq $0x0, 0x8(%rsp)
xorl %ebx, %ebx
jmp 0x3dc49
movl $0x1, %r12d
xorl %r14d, %r14d
movq $0x0, 0x8(%rsp)
jmp 0x3e187
xorl %ebx, %ebx
movl $0x1, 0x4(%rsp)
xorl %r14d, %r14d
movq $0x0, 0x8(%rsp)
movb $0x1, %al
testl %ebp, %ebp
movq 0x20(%rsp), %r12
jle 0x3e151
movl %ebp, %eax
movq %rax, 0xa0(%rsp)
movq %r15, 0x50(%rsp)
movq %r13, 0x18(%rsp)
movq %rbx, %rbp
xorl %ebx, %ebx
movq %r14, 0x10(%rsp)
movq 0x58(%rsp), %rax
movq (%rax,%rbx,8), %r8
movl (%r13), %eax
movl $0x0, %r14d
testl %eax, %eax
movq %rbx, 0x28(%rsp)
je 0x3dd77
movq %rax, 0x30(%rsp)
movq %rbp, 0x40(%rsp)
movb (%r8), %cl
testb %cl, %cl
je 0x3dcc6
leaq 0x1(%r8), %rax
movl $0x811c9dc5, %ebp       # imm = 0x811C9DC5
movzbl %cl, %ecx
xorl %ebp, %ecx
imull $0x1000193, %ecx, %ebp  # imm = 0x1000193
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x3dcb0
jmp 0x3dccb
movl $0x811c9dc5, %ebp       # imm = 0x811C9DC5
movq 0x30(%rsp), %rax
leal -0x1(%rax), %r12d
andl %r12d, %ebp
movq 0x10(%r13), %rsi
movl $0x1, %r15d
movl %ebp, %r14d
movq %r8, 0x68(%rsp)
movq %rsi, 0x60(%rsp)
movl %r14d, %eax
shrl $0x4, %eax
movl (%rsi,%rax,4), %r13d
leal (%r14,%r14), %ebx
andl $0x1e, %ebx
movl %r13d, %eax
movl %ebx, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x3dd4c
testb $0x1, %al
jne 0x3dd34
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movl %r14d, %ecx
movq (%rax,%rcx,8), %rdi
movq %r8, %rsi
callq 0x46e0
movq 0x60(%rsp), %rsi
movq 0x68(%rsp), %r8
testl %eax, %eax
je 0x3dd4c
addl %r15d, %r14d
andl %r12d, %r14d
incl %r15d
cmpl %ebp, %r14d
jne 0x3dcee
movq 0x30(%rsp), %rax
movl %eax, %r14d
jmp 0x3dd5e
movl %ebx, %ecx
shrl %cl, %r13d
testb $0x3, %r13b
movq 0x30(%rsp), %rax
cmovnel %eax, %r14d
movq 0x50(%rsp), %r15
movq 0x18(%rsp), %r13
movq 0x40(%rsp), %rbp
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %rbx
cmpl %eax, %r14d
jne 0x3e156
movq %r12, %rdi
movl $0x2, %esi
movq %r8, %rdx
callq 0x2e585
movq 0x98(%rsp), %rcx
movl %eax, (%rcx,%rbx,4)
testl %eax, %eax
js 0x3ddf0
movq 0x10(%rsp), %rcx
leaq 0x2(%rcx), %rax
movq 0x8(%rsp), %rbx
cmpq %rax, %rbx
jae 0x3ddfa
movq %rax, %rcx
shrq %rcx
movabsq $0x3fffffffffffffff, %rdx # imm = 0x3FFFFFFFFFFFFFFF
cmpq %rdx, %rax
movl $0x0, %ebx
cmovbeq %rcx, %rbx
addq %rax, %rbx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x4860
movq 0x10(%rsp), %rcx
testq %rax, %rax
jne 0x3ddfd
movl $0xffffffff, 0x3c(%rsp) # imm = 0xFFFFFFFF
jmp 0x3de16
movq 0x10(%rsp), %r14
jmp 0x3e137
movq %rbp, %rax
movw $0x9, (%rax,%rcx)
incq %rcx
movl $0x9, 0x3c(%rsp)
movq %rbx, 0x8(%rsp)
movq %rax, %rbp
movq %rcx, 0x10(%rsp)
movq 0x58(%rsp), %rax
movq 0x28(%rsp), %rbx
movq (%rax,%rbx,8), %r12
testq %r12, %r12
je 0x3de93
movq %r12, %rdi
callq 0x41c0
movq %rax, %r14
movq 0x10(%rsp), %rcx
addq %rcx, %rax
addq $0x2, %rax
cmpq %rcx, %rax
jbe 0x3dea0
movq 0x8(%rsp), %rbx
cmpq %rax, %rbx
jae 0x3deb3
movq %rax, %rcx
shrq %rcx
movabsq $0x3fffffffffffffff, %rdx # imm = 0x3FFFFFFFFFFFFFFF
cmpq %rdx, %rax
movl $0x0, %ebx
cmovbeq %rcx, %rbx
addq %rax, %rbx
movq %rbp, %rdi
movq %rbx, %rsi
callq 0x4860
movq 0x10(%rsp), %rcx
movq %rax, %r13
testq %rax, %rax
jne 0x3deb6
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x3dee4
callq 0x4050
movl $0xe, (%rax)
jmp 0x3deab
callq 0x4050
movl $0x4b, (%rax)
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x3deee
movq %rbp, %r13
leaq (%rcx,%r13), %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %r14, %r12
movq %rcx, %r14
callq 0x43c0
addq %r12, %r14
movq %r14, 0x10(%rsp)
movb $0x0, (%r13,%r14)
movq %r12, %r14
movq %rbx, 0x8(%rsp)
movq %r13, %rbp
movq 0x18(%rsp), %r13
movq 0x28(%rsp), %rbx
movq 0x58(%rsp), %rax
movq (%rax,%rbx,8), %rsi
movl 0x8(%r13), %eax
cmpl 0xc(%r13), %eax
movq 0x20(%rsp), %r12
movq %rbp, 0x40(%rsp)
jb 0x3df40
movq %r15, %r12
movq %rsi, %r15
movl (%r13), %esi
movl 0x4(%r13), %eax
addl %eax, %eax
cmpl %eax, %esi
jbe 0x3df23
decl %esi
jmp 0x3df25
incl %esi
movq %r13, %rdi
callq 0x42a26
testl %eax, %eax
movq %r15, %rsi
movq %r12, %r15
movq 0x20(%rsp), %r12
js 0x3e01e
movb (%rsi), %cl
testb %cl, %cl
je 0x3df65
leaq 0x1(%rsi), %rax
movl $0x811c9dc5, %ebp       # imm = 0x811C9DC5
movzbl %cl, %ecx
xorl %ebp, %ecx
imull $0x1000193, %ecx, %ebp  # imm = 0x1000193
movb (%rax), %cl
incq %rax
testb %cl, %cl
jne 0x3df4f
jmp 0x3df6a
movl $0x811c9dc5, %ebp       # imm = 0x811C9DC5
movq %r14, 0x90(%rsp)
movl (%r13), %edx
leal -0x1(%rdx), %edi
andl %edi, %ebp
movq 0x10(%r13), %r9
movl %ebp, %eax
shrl $0x4, %eax
movl (%r9,%rax,4), %eax
leal (,%rbp,2), %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x3e06c
movl $0x1, %r12d
movl %ebp, %r13d
movq %rdx, 0x48(%rsp)
movl %edx, %r14d
movq %rsi, 0x68(%rsp)
movq %r9, 0x60(%rsp)
movl %edi, 0x30(%rsp)
movl %r13d, %eax
shrl $0x4, %eax
movl (%r9,%rax,4), %r15d
leal (,%r13,2), %ebx
andl $0x1e, %ebx
movl %r15d, %eax
movl %ebx, %ecx
shrl %cl, %eax
testb $0x2, %al
jne 0x3e029
testb $0x1, %al
jne 0x3e003
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rax
movl %r13d, %ecx
movq (%rax,%rcx,8), %rdi
callq 0x46e0
movl 0x30(%rsp), %edi
movq 0x60(%rsp), %r9
movq 0x68(%rsp), %rsi
testl %eax, %eax
je 0x3e029
btl %ebx, %r15d
cmovbl %r13d, %r14d
addl %r12d, %r13d
andl %edi, %r13d
incl %r12d
movl %r14d, %eax
cmpl %ebp, %r13d
jne 0x3dfb8
jmp 0x3e02e
movl (%r13), %ebp
movb $0x1, %cl
jmp 0x3e0f5
movq 0x48(%rsp), %rax
movl %eax, %ebp
movq 0x48(%rsp), %rdx
cmpl %edx, %eax
movq 0x50(%rsp), %r15
movq 0x20(%rsp), %r12
movq 0x28(%rsp), %rbx
jne 0x3e06c
movl %r13d, %eax
shrl $0x4, %eax
movl (%r9,%rax,4), %eax
leal (,%r13,2), %ecx
shrl %cl, %eax
cmpl %edx, %r14d
cmovel %r13d, %r14d
testb $0x2, %al
cmovel %r13d, %r14d
movl %r14d, %ebp
movl %ebp, %eax
shrl $0x4, %eax
movl (%r9,%rax,4), %edx
leal (,%rbp,2), %ecx
andl $0x1e, %ecx
movl %edx, %edi
shrl %cl, %edi
testb $0x2, %dil
jne 0x3e0a2
testb $0x1, %dil
movq 0x18(%rsp), %r13
movq 0x90(%rsp), %r14
jne 0x3e0d6
movb $0x1, %al
xorl %ecx, %ecx
jmp 0x3e0f7
movq 0x18(%rsp), %r13
movq 0x18(%r13), %r8
movl $0x3, %edi
shll %cl, %edi
movl %ebp, %ecx
movq %rsi, (%r8,%rcx,8)
notl %edi
andl %edi, %edx
movl %edx, (%r9,%rax,4)
incl 0x4(%r13)
incl 0x8(%r13)
xorl %ecx, %ecx
xorl %eax, %eax
movq 0x90(%rsp), %r14
jmp 0x3e0f7
movq 0x18(%r13), %r8
movl $0x3, %edi
shll %cl, %edi
movl %ebp, %ecx
movq %rsi, (%r8,%rcx,8)
notl %edi
andl %edi, %edx
movl %edx, (%r9,%rax,4)
incl 0x4(%r13)
xorl %ecx, %ecx
xorl %eax, %eax
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
testb %cl, %cl
jne 0x3e11c
movl %ebp, %ecx
testb %al, %al
je 0x3e10f
movq 0x20(%r13), %rax
movl (%rax,%rcx,4), %edx
jmp 0x3e11c
movl 0x4(%r13), %edx
decl %edx
movq 0x20(%r13), %rax
movl %edx, (%rax,%rcx,4)
orl 0x3c(%rsp), %r14d
orl %edx, %r14d
shrl $0x1f, %r14d
orl %r14d, 0x4(%rsp)
movq 0x10(%rsp), %r14
movq 0x40(%rsp), %rbp
incq %rbx
cmpq 0xa0(%rsp), %rbx
jne 0x3dc71
movl 0x4(%rsp), %r12d
movb $0x1, %al
jmp 0x3e17f
movq %rbx, %rbp
jmp 0x3e17a
leaq 0x70f65(%rip), %rsi     # 0xaf0c2
leaq 0x70fb5(%rip), %rdx     # 0xaf119
movl $0x1, %edi
movq %r8, %rcx
xorl %eax, %eax
callq 0x9774
xorl %eax, %eax
movq 0x10(%rsp), %r14
movl 0x4(%rsp), %r12d
testb %al, %al
je 0x3dacf
testq %r14, %r14
je 0x3e1a3
movzbl -0x1(%rbp,%r14), %eax
cmpl $0xa, %eax
je 0x3e19b
testl %eax, %eax
jne 0x3e1a3
decq %r14
jne 0x3e18c
xorl %r14d, %r14d
leaq 0x2(%r14), %rax
cmpq %rax, 0x8(%rsp)
jae 0x3e1db
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %rdx
shrq %rdx
xorl %esi, %esi
testq %rcx, %rcx
cmoveq %rdx, %rsi
addq %rax, %rsi
movq %rbp, %rdi
callq 0x4860
testq %rax, %rax
jne 0x3e1de
movl $0x1, %ecx
jmp 0x3e1ea
movq %rbp, %rax
movw $0xa, (%rax,%r14)
xorl %ecx, %ecx
movq %rax, %rbp
orl %r12d, %ecx
je 0x3e21d
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0x70ec0(%rip), %rsi     # 0xaf0c2
leaq 0x703b7(%rip), %rdx     # 0xae5c0
movl $0x1, %edi
movq %rax, %rcx
xorl %eax, %eax
callq 0x9774
jmp 0x3dacf
movq %r15, %rdi
movq %rbp, %rsi
callq 0x2e6a1
testl %eax, %eax
jns 0x3e237
movq %r15, %rdi
callq 0x2f696
xorl %r15d, %r15d
movq %rbp, %rdi
callq 0x45c0
movq 0x80(%rsp), %rdi
callq 0x45c0
testq %r13, %r13
je 0x3db2b
movq 0x18(%r13), %rdi
callq 0x45c0
movq 0x10(%r13), %rdi
callq 0x45c0
movq 0x20(%r13), %rdi
callq 0x45c0
movq %r13, %rdi
callq 0x45c0
jmp 0x3db2b