// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
callq 0x4c990
movq %rax, -0x30(%rbp)
leaq -0x48(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x4240
leaq -0x60(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x4240
leaq 0xb9102(%rip), %rdi     # 0x10568c
callq 0x3f560
movq %rax, -0x68(%rbp)
movl $0x0, -0x6c(%rbp)
cmpq $0x0, -0x68(%rbp)
je 0x4c5a8
cmpq $0x0, -0x30(%rbp)
jne 0x4c5c7
movl $0x1, %edi
leaq 0xbbb8e(%rip), %rsi     # 0x108142
leaq 0xbb4c4(%rip), %rdx     # 0x107a7f
movb $0x0, %al
callq 0x9d90
jmp 0x4c957
movq -0x10(%rbp), %rdi
movl $0x1, %esi
leaq -0x48(%rbp), %rdx
callq 0x409c0
cmpl $0x0, %eax
jge 0x4c5fd
movl $0x1, %edi
leaq 0xbbb58(%rip), %rsi     # 0x108142
leaq 0xbbb60(%rip), %rdx     # 0x108151
movb $0x0, %al
callq 0x9d90
jmp 0x4c957
movq -0x68(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
callq 0x3f3a0
movq -0x88(%rbp), %rdi
movq %rax, %rsi
callq 0x3f420
movl $0x0, -0x70(%rbp)
movl -0x70(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x4c649
movq -0x28(%rbp), %rax
movslq -0x70(%rbp), %rcx
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x4c627
movq -0x10(%rbp), %rax
cmpl $0x0, 0x8(%rax)
jle 0x4c830
movq -0x38(%rbp), %rdi
callq 0x4c9a0
movq %rax, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x14(%rbp), %edx
movl $0x7, %eax
movl $0x8, %ecx
cmpl $0x0, %edx
cmovnel %ecx, %eax
movl %eax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
movl $0x9, %esi
callq 0x4160
movq %rax, %rcx
movq %rcx, -0x78(%rbp)
xorl %eax, %eax
cmpq $0x0, %rcx
movb %al, -0x89(%rbp)
je 0x4c6b3
movl -0x7c(%rbp), %eax
cmpl -0x80(%rbp), %eax
setl %al
movb %al, -0x89(%rbp)
movb -0x89(%rbp), %al
testb $0x1, %al
jne 0x4c6bf
jmp 0x4c6d6
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
movq -0x78(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x78(%rbp)
jmp 0x4c681
movl -0x7c(%rbp), %eax
cmpl -0x80(%rbp), %eax
je 0x4c6fd
movl $0x1, %edi
leaq 0xbba58(%rip), %rsi     # 0x108142
leaq 0xbba7a(%rip), %rdx     # 0x10816b
movb $0x0, %al
callq 0x9d90
jmp 0x4c957
movq -0x38(%rbp), %rdi
movq -0x78(%rbp), %rsi
movq -0x38(%rbp), %rax
subq %rax, %rsi
leaq -0x60(%rbp), %rdx
callq 0x43970
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x6c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl $0x0, -0x7c(%rbp)
movl -0x7c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x4c82e
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x4ca10
cmpl $0x0, %eax
je 0x4c77e
movq -0x20(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movl $0x1, %edi
leaq 0xbb9d7(%rip), %rsi     # 0x108142
leaq 0xbba27(%rip), %rdx     # 0x108199
movb $0x0, %al
callq 0x9d90
jmp 0x4c957
movq -0x10(%rbp), %rdi
movq -0x20(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movq (%rax,%rcx,8), %rdx
movl $0x2, %esi
callq 0x3e820
movl %eax, %edx
movq -0x28(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movslq -0x7c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jge 0x4c7b5
jmp 0x4c820
movl $0x9, %edi
leaq -0x60(%rbp), %rsi
callq 0x40b10
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x6c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x20(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq -0x60(%rbp), %rsi
callq 0x43910
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x6c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movq -0x30(%rbp), %rdi
movq -0x20(%rbp), %rax
movslq -0x7c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x4ca60
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x6c(%rbp), %eax
movl %eax, -0x6c(%rbp)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x4c72d
jmp 0x4c852
movq -0x38(%rbp), %rdi
movq -0x48(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x43970
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x6c(%rbp), %eax
movl %eax, -0x6c(%rbp)
jmp 0x4c854
xorl %eax, %eax
cmpq $0x0, -0x60(%rbp)
movb %al, -0x8a(%rbp)
je 0x4c8a5
movq -0x50(%rbp), %rcx
movq -0x60(%rbp), %rdx
subq $0x1, %rdx
movb $0x1, %al
cmpb $0x0, (%rcx,%rdx)
movb %al, -0x8b(%rbp)
je 0x4c899
movq -0x50(%rbp), %rax
movq -0x60(%rbp), %rcx
subq $0x1, %rcx
movsbl (%rax,%rcx), %eax
cmpl $0xa, %eax
sete %al
movb %al, -0x8b(%rbp)
movb -0x8b(%rbp), %al
movb %al, -0x8a(%rbp)
movb -0x8a(%rbp), %al
testb $0x1, %al
jne 0x4c8b1
jmp 0x4c8bf
movq -0x60(%rbp), %rax
addq $-0x1, %rax
movq %rax, -0x60(%rbp)
jmp 0x4c854
movl $0xa, %edi
leaq -0x60(%rbp), %rsi
callq 0x40b10
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x6c(%rbp), %eax
movl %eax, -0x6c(%rbp)
cmpl $0x0, -0x6c(%rbp)
je 0x4c90f
callq 0x4050
movl (%rax), %edi
callq 0x4120
movq %rax, %rcx
movl $0x1, %edi
leaq 0xbb843(%rip), %rsi     # 0x108142
leaq 0xbacfa(%rip), %rdx     # 0x107600
movb $0x0, %al
callq 0x9d90
jmp 0x4c957
movq -0x68(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x3e890
cmpl $0x0, %eax
jge 0x4c932
movq -0x68(%rbp), %rdi
callq 0x3fd50
movq $0x0, -0x68(%rbp)
movq -0x50(%rbp), %rdi
callq 0x45a0
movq -0x38(%rbp), %rdi
callq 0x45a0
movq -0x30(%rbp), %rdi
callq 0x4cb00
movq -0x68(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x4c983
leaq -0x60(%rbp), %rdi
callq 0x4cb30
leaq -0x48(%rbp), %rdi
callq 0x4cb30
movq -0x30(%rbp), %rdi
callq 0x4cb00
movq -0x68(%rbp), %rdi
callq 0x3fd50
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x90, %rsp
popq %rbp
retq