// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/vcf.c
// Function: vcf_hdr_read
bcf_hdr_t *vcf_hdr_read(htsFile *fp)
{
    kstring_t txt, *s = &fp->line;
    int ret;
    bcf_hdr_t *h;
    tbx_t *idx = NULL;
    const char **names = NULL;
    h = bcf_hdr_init("r");
    if (!h) {
        hts_log_error("Failed to allocate bcf header");
        return NULL;
    }
    txt.l = txt.m = 0; txt.s = 0;
    while ((ret = hts_getline(fp, KS_SEP_LINE, s)) >= 0) {
        int e = 0;
        if (s->l == 0) continue;
        if (s->s[0] != '#') {
            hts_log_error("No sample line");
            goto error;
        }
        if (s->s[1] != '#' && fp->fn_aux) { // insert contigs here
            kstring_t tmp = { 0, 0, NULL };
            hFILE *f = hopen(fp->fn_aux, "r");
            if (f == NULL) {
                hts_log_error("Couldn't open \"%s\"", fp->fn_aux);
                goto error;
            }
            while (tmp.l = 0, kgetline(&tmp, (kgets_func *) hgets, f) >= 0) {
                char *tab = strchr(tmp.s, '\t');
                if (tab == NULL) continue;
                e |= (kputs("##contig=<ID=", &txt) < 0);
                e |= (kputsn(tmp.s, tab - tmp.s, &txt) < 0);
                e |= (kputs(",length=", &txt) < 0);
                e |= (kputl(atol(tab), &txt) < 0);
                e |= (kputsn(">\n", 2, &txt) < 0);
            }
            free(tmp.s);
            if (hclose(f) != 0) {
                hts_log_error("Error on closing %s", fp->fn_aux);
                goto error;
            }
            if (e) goto error;
        }
        if (kputsn(s->s, s->l, &txt) < 0) goto error;
        if (kputc('\n', &txt) < 0) goto error;
        if (s->s[1] != '#') break;
    }
    if ( ret < -1 ) goto error;
    if ( !txt.s )
    {
        hts_log_error("Could not read the header");
        goto error;
    }
    if ( bcf_hdr_parse(h, txt.s) < 0 ) goto error;

    // check tabix index, are all contigs listed in the header? add the missing ones
    idx = tbx_index_load3(fp->fn, NULL, HTS_IDX_SILENT_FAIL);
    if ( idx )
    {
        int i, n, need_sync = 0;
        names = tbx_seqnames(idx, &n);
        if (!names) goto error;
        for (i=0; i<n; i++)
        {
            bcf_hrec_t *hrec = bcf_hdr_get_hrec(h, BCF_HL_CTG, "ID", (char*) names[i], NULL);
            if ( hrec ) continue;
            if (add_missing_contig_hrec(h, names[i]) < 0) goto error;
            need_sync = 1;
        }
        if ( need_sync ) {
            if (bcf_hdr_sync(h) < 0) goto error;
        }
        free(names);
        tbx_destroy(idx);
    }
    free(txt.s);
    return h;

 error:
    if (idx) tbx_destroy(idx);
    free(names);
    free(txt.s);
    if (h) bcf_hdr_destroy(h);
    return NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %rdi, %r12
leaq 0x5f915(%rip), %rdi     # 0x851a5
callq 0x250c7
testq %rax, %rax
je 0x25a79
movq %rax, 0x8(%rsp)
leaq 0x10(%r12), %r15
xorps %xmm0, %xmm0
leaq 0x50(%rsp), %r14
movaps %xmm0, (%r14)
andq $0x0, 0x10(%r14)
pushq $0x2
popq %r13
leaq 0x20(%rsp), %rbx
movq %r12, 0x48(%rsp)
movq %r15, 0x40(%rsp)
movq %r12, %rdi
movl %r13d, %esi
movq %r15, %rdx
callq 0x99a4
movl %eax, %ebp
testl %eax, %eax
js 0x25a6c
movq (%r15), %rsi
testq %rsi, %rsi
je 0x258cc
movq 0x20(%r12), %rdi
cmpb $0x23, (%rdi)
jne 0x25bcf
cmpb $0x23, 0x1(%rdi)
je 0x25a42
movq 0x30(%r12), %rax
testq %rax, %rax
je 0x25a42
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
andq $0x0, 0x30(%rsp)
movq %rax, %rdi
leaq 0x5f87b(%rip), %rsi     # 0x851a5
xorl %eax, %eax
callq 0x75953
testq %rax, %rax
leaq 0x4f31d(%rip), %r14     # 0x74c58
je 0x25c09
movq %rax, %r13
movl $0x0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movq %rbx, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x69393
movq 0x30(%rsp), %rdi
testl %eax, %eax
js 0x25a0e
pushq $0x9
popq %rsi
callq 0x4180
testq %rax, %rax
je 0x2594c
movq %rax, %r15
leaq 0x60f71(%rip), %rdi     # 0x868f5
leaq 0x50(%rsp), %r14
movq %r14, %rsi
callq 0x2783f
movl %eax, 0x1c(%rsp)
movq 0x30(%rsp), %rdi
movq %r15, %rsi
subq %rdi, %rsi
movq %r14, %rdx
callq 0x2787b
movl %eax, 0x18(%rsp)
leaq 0x60f50(%rip), %rdi     # 0x86903
movq %r14, %rsi
callq 0x2783f
movl %eax, %r12d
orl 0x1c(%rsp), %r12d
orl 0x18(%rsp), %r12d
movq %r15, %rdi
callq 0x45d0
movq %rax, %rdi
movq %r14, %rsi
callq 0x2c0c7
movl %eax, %r15d
leaq 0x60918(%rip), %rdi     # 0x862fd
pushq $0x2
popq %rsi
movq %r14, %rdx
leaq 0x4f266(%rip), %r14     # 0x74c58
callq 0x2787b
orl %r15d, %eax
orl %r12d, %eax
movq 0x48(%rsp), %r12
shrl $0x1f, %eax
orl %eax, 0x10(%rsp)
jmp 0x2594c
callq 0x45c0
movq %r13, %rdi
callq 0x750a6
testl %eax, %eax
jne 0x25c12
cmpl $0x0, 0x10(%rsp)
jne 0x25a98
movq 0x10(%r12), %rsi
movq 0x20(%r12), %rdi
movq 0x40(%rsp), %r15
leaq 0x50(%rsp), %r14
pushq $0x2
popq %r13
movq %r14, %rdx
callq 0x2787b
testl %eax, %eax
js 0x25a98
pushq $0xa
popq %rdi
movq %r14, %rsi
callq 0x25f76
testl %eax, %eax
js 0x25a98
movq 0x20(%r12), %rax
cmpb $0x23, 0x1(%rax)
je 0x258cc
cmpl $-0x1, %ebp
jge 0x25aa5
xorl %r15d, %r15d
jmp 0x25c32
leaq 0x60e46(%rip), %rsi     # 0x868c6
leaq 0x60c84(%rip), %rdx     # 0x8670b
xorl %ebx, %ebx
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x8132
jmp 0x25c53
movq 0x8(%rsp), %rbx
xorl %r15d, %r15d
jmp 0x25c37
movq 0x60(%rsp), %r14
testq %r14, %r14
movq 0x8(%rsp), %rbx
je 0x25bec
movq %rbx, %rdi
movq %r14, %rsi
callq 0x248c9
testl %eax, %eax
js 0x25a9d
movq 0x28(%r12), %rdi
pushq $0x2
popq %rdx
xorl %esi, %esi
callq 0x7822d
testq %rax, %rax
je 0x25cdc
movq %rax, %r12
leaq 0x20(%rsp), %rsi
movq %rax, %rdi
callq 0x7836c
movq %rax, %r15
testq %rax, %rax
je 0x25cab
movq %r12, 0x10(%rsp)
xorl %ebp, %ebp
xorl %ebx, %ebx
movslq 0x20(%rsp), %rax
cmpq %rax, %rbp
jge 0x25cb5
movq (%r15,%rbp,8), %rcx
movq 0x8(%rsp), %rdi
pushq $0x3
popq %rsi
leaq 0x5f1b0(%rip), %rdx     # 0x84cd5
xorl %r8d, %r8d
callq 0x244fd
testq %rax, %rax
jne 0x25bc7
movq (%r15,%rbp,8), %r13
pushq $0x1
popq %rdi
pushq $0x30
popq %rsi
callq 0x42f0
movq %rax, %r12
testq %rax, %rax
je 0x25c65
leaq 0x62291(%rip), %rdi     # 0x87de9
callq 0x4930
movq %rax, 0x8(%r12)
testq %rax, %rax
je 0x25c65
movq %r12, %rdi
leaq 0x5f160(%rip), %rsi     # 0x84cd5
pushq $0x2
popq %rdx
callq 0x22bfa
testl %eax, %eax
js 0x25c65
movl 0x18(%r12), %ebx
decl %ebx
movq %r13, %rdi
callq 0x41c0
movq %r12, %rdi
movl %ebx, %esi
movq %r13, %rdx
movq %rax, %rcx
xorl %r8d, %r8d
callq 0x22cd9
testl %eax, %eax
js 0x25c65
movq 0x8(%rsp), %rdi
movq %r12, %rsi
callq 0x238dd
pushq $0x1
popq %rbx
testl %eax, %eax
js 0x25c65
incq %rbp
jmp 0x25b04
leaq 0x60cf0(%rip), %rsi     # 0x868c6
leaq 0x60cf6(%rip), %rdx     # 0x868d3
xorl %r15d, %r15d
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x8132
jmp 0x25c32
leaq 0x60cd3(%rip), %rsi     # 0x868c6
leaq 0x60d12(%rip), %rdx     # 0x8690c
xorl %r15d, %r15d
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x8132
jmp 0x25c37
leaq 0x60cd2(%rip), %rdx     # 0x868e2
jmp 0x25c19
leaq 0x5f2ea(%rip), %rdx     # 0x84f03
movq 0x30(%r12), %rcx
leaq 0x60ca1(%rip), %rsi     # 0x868c6
xorl %r15d, %r15d
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x8132
movq 0x8(%rsp), %rbx
movq %r15, %rdi
callq 0x45c0
movq 0x60(%rsp), %rdi
callq 0x45c0
movq %rbx, %rdi
callq 0x25554
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4050
movq %rax, %r14
movl (%rax), %ebp
movl %ebp, %edi
callq 0x4140
leaq 0x619f8(%rip), %rsi     # 0x87675
leaq 0x6063c(%rip), %rdx     # 0x862c0
pushq $0x1
popq %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x8132
testq %r12, %r12
je 0x25c9e
movq %r12, %rdi
callq 0x22854
movl %ebp, (%r14)
movq 0x8(%rsp), %rbx
movq 0x10(%rsp), %r12
movq %r12, %rdi
callq 0x780f1
jmp 0x25c37
testl %ebx, %ebx
movq 0x8(%rsp), %rbx
je 0x25cca
movq %rbx, %rdi
callq 0x2276e
testl %eax, %eax
js 0x25ca6
movq %r15, %rdi
callq 0x45c0
movq 0x10(%rsp), %rdi
callq 0x780f1
movq %r14, %rdi
callq 0x45c0
jmp 0x25c53