// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0xa0, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x30(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
leaq 0xc61de(%rip), %rdi     # 0x106470
callq 0x3f560
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x402c9
movl $0x1, %edi
leaq 0xc798c(%rip), %rsi     # 0x107c3a
leaq 0xc77ca(%rip), %rdx     # 0x107a7f
movb $0x0, %al
callq 0x9d90
movq $0x0, -0x8(%rbp)
jmp 0x406fa
movq $0x0, -0x20(%rbp)
movq $0x0, -0x28(%rbp)
movq $0x0, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x30(%rbp), %rdx
movl $0x2, %esi
callq 0xcd30
movl %eax, -0x34(%rbp)
cmpl $0x0, %eax
jl 0x40558
movl $0x0, -0x54(%rbp)
movq -0x30(%rbp), %rax
cmpq $0x0, (%rax)
jne 0x40312
jmp 0x402e1
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movsbl (%rax), %eax
cmpl $0x23, %eax
je 0x40341
movl $0x1, %edi
leaq 0xc790c(%rip), %rsi     # 0x107c3a
leaq 0xc7912(%rip), %rdx     # 0x107c47
movb $0x0, %al
callq 0x9d90
jmp 0x406c0
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movsbl 0x1(%rax), %eax
cmpl $0x23, %eax
je 0x40506
movq -0x10(%rbp), %rax
cmpq $0x0, 0x30(%rax)
je 0x40506
leaq -0x70(%rbp), %rdi
xorl %esi, %esi
movl $0x18, %edx
callq 0x4240
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rdi
leaq 0xc60ec(%rip), %rsi     # 0x106470
movb $0x0, %al
callq 0xed730
movq %rax, -0x78(%rbp)
cmpq $0x0, -0x78(%rbp)
jne 0x403bd
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rcx
movl $0x1, %edi
leaq 0xc7890(%rip), %rsi     # 0x107c3a
leaq 0xc78a5(%rip), %rdx     # 0x107c56
movb $0x0, %al
callq 0x9d90
jmp 0x406c0
jmp 0x403bf
movq $0x0, -0x70(%rbp)
movq -0x78(%rbp), %rdx
leaq -0x70(%rbp), %rdi
leaq 0xabaaa(%rip), %rsi     # 0xebe80
callq 0xd68a0
cmpl $0x0, %eax
jl 0x404bb
movq -0x60(%rbp), %rdi
movl $0x9, %esi
callq 0x4160
movq %rax, -0x80(%rbp)
cmpq $0x0, -0x80(%rbp)
jne 0x403ff
jmp 0x403bf
leaq 0xc7863(%rip), %rdi     # 0x107c69
leaq -0x28(%rbp), %rsi
callq 0x43910
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x60(%rbp), %rdi
movq -0x80(%rbp), %rsi
movq -0x60(%rbp), %rax
subq %rax, %rsi
leaq -0x28(%rbp), %rdx
callq 0x43970
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
leaq 0xc7827(%rip), %rdi     # 0x107c77
leaq -0x28(%rbp), %rsi
callq 0x43910
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x80(%rbp), %rdi
callq 0x45b0
movq %rax, %rdi
leaq -0x28(%rbp), %rsi
callq 0x43a20
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
leaq 0xc71a6(%rip), %rdi     # 0x10763d
movl $0x2, %esi
leaq -0x28(%rbp), %rdx
callq 0x43970
cmpl $0x0, %eax
setl %al
andb $0x1, %al
movzbl %al, %eax
orl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
jmp 0x403bf
movq -0x60(%rbp), %rdi
callq 0x45a0
movq -0x78(%rbp), %rdi
callq 0xec7a0
cmpl $0x0, %eax
je 0x404f9
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rcx
movl $0x1, %edi
leaq 0xc7754(%rip), %rsi     # 0x107c3a
leaq 0xc5cdd(%rip), %rdx     # 0x1061ca
movb $0x0, %al
callq 0x9d90
jmp 0x406c0
cmpl $0x0, -0x54(%rbp)
je 0x40504
jmp 0x406c0
jmp 0x40506
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rdi
movq -0x30(%rbp), %rax
movq (%rax), %rsi
leaq -0x28(%rbp), %rdx
callq 0x43970
cmpl $0x0, %eax
jge 0x40528
jmp 0x406c0
movl $0xa, %edi
leaq -0x28(%rbp), %rsi
callq 0x40b10
cmpl $0x0, %eax
jge 0x40540
jmp 0x406c0
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movsbl 0x1(%rax), %eax
cmpl $0x23, %eax
je 0x40553
jmp 0x40558
jmp 0x402e1
cmpl $-0x1, -0x34(%rbp)
jge 0x40563
jmp 0x406c0
cmpq $0x0, -0x18(%rbp)
jne 0x40589
movl $0x1, %edi
leaq 0xc76c4(%rip), %rsi     # 0x107c3a
leaq 0xc7703(%rip), %rdx     # 0x107c80
movb $0x0, %al
callq 0x9d90
jmp 0x406c0
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3e890
cmpl $0x0, %eax
jge 0x405a0
jmp 0x406c0
movq -0x10(%rbp), %rax
movq 0x28(%rax), %rdi
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edx
callq 0xf2240
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x406ad
movl $0x0, -0x8c(%rbp)
movq -0x48(%rbp), %rdi
leaq -0x88(%rbp), %rsi
callq 0xf24f0
movq %rax, -0x50(%rbp)
cmpq $0x0, -0x50(%rbp)
jne 0x405ef
jmp 0x406c0
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0x88(%rbp), %eax
jge 0x40680
movq -0x40(%rbp), %rdi
movq -0x50(%rbp), %rax
movslq -0x84(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
movl $0x3, %esi
leaq 0xc5972(%rip), %rdx     # 0x105f98
xorl %eax, %eax
movl %eax, %r8d
callq 0x3e160
movq %rax, -0x98(%rbp)
cmpq $0x0, -0x98(%rbp)
je 0x40643
jmp 0x4066c
movq -0x40(%rbp), %rdi
movq -0x50(%rbp), %rax
movslq -0x84(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x43a50
cmpl $0x0, %eax
jge 0x40662
jmp 0x406c0
movl $0x1, -0x8c(%rbp)
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x405f9
cmpl $0x0, -0x8c(%rbp)
je 0x4069b
movq -0x40(%rbp), %rdi
callq 0x3ae50
cmpl $0x0, %eax
jge 0x40699
jmp 0x406c0
jmp 0x4069b
movq -0x50(%rbp), %rdi
callq 0x45a0
movq -0x48(%rbp), %rdi
callq 0xf2040
movq -0x18(%rbp), %rdi
callq 0x45a0
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x406fa
cmpq $0x0, -0x48(%rbp)
je 0x406d0
movq -0x48(%rbp), %rdi
callq 0xf2040
movq -0x50(%rbp), %rdi
callq 0x45a0
movq -0x18(%rbp), %rdi
callq 0x45a0
cmpq $0x0, -0x40(%rbp)
je 0x406f2
movq -0x40(%rbp), %rdi
callq 0x3fd50
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xa0, %rsp
popq %rbp
retq
nopw (%rax,%rax)