// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/vcf.c
// Function: bcf_hdr_read
bcf_hdr_t *bcf_hdr_read(htsFile *hfp)
{
    if (hfp->format.format == vcf)
        return vcf_hdr_read(hfp);
    if (hfp->format.format != bcf) {
        hts_log_error("Input is not detected as bcf or vcf format");
        return NULL;
    }

    assert(hfp->is_bgzf);

    BGZF *fp = hfp->fp.bgzf;
    uint8_t magic[5];
    bcf_hdr_t *h;
    h = bcf_hdr_init("r");
    if (!h) {
        hts_log_error("Failed to allocate bcf header");
        return NULL;
    }
    if (bgzf_read(fp, magic, 5) != 5)
    {
        hts_log_error("Failed to read the header (reading BCF in text mode?)");
        bcf_hdr_destroy(h);
        return NULL;
    }
    if (strncmp((char*)magic, "BCF\2\2", 5) != 0)
    {
        if (!strncmp((char*)magic, "BCF", 3))
            hts_log_error("Invalid BCF2 magic string: only BCFv2.2 is supported");
        else
            hts_log_error("Invalid BCF2 magic string");
        bcf_hdr_destroy(h);
        return NULL;
    }
    uint8_t buf[4];
    size_t hlen;
    char *htxt = NULL;
    if (bgzf_read(fp, buf, 4) != 4) goto fail;
    hlen = buf[0] | (buf[1] << 8) | (buf[2] << 16) | ((size_t) buf[3] << 24);
    if (hlen >= SIZE_MAX) { errno = ENOMEM; goto fail; }
#ifdef FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION
    if (hlen > FUZZ_ALLOC_LIMIT/2) { errno = ENOMEM; goto fail; }
#endif
    htxt = (char*)malloc(hlen + 1);
    if (!htxt) goto fail;
    if (bgzf_read(fp, htxt, hlen) != hlen) goto fail;
    htxt[hlen] = '\0'; // Ensure htxt is terminated
    if ( bcf_hdr_parse(h, htxt) < 0 ) goto fail;
    free(htxt);
    return h;
 fail:
    hts_log_error("Failed to read BCF header");
    free(htxt);
    bcf_hdr_destroy(h);
    return NULL;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl 0x4c(%rdi), %eax
cmpl $0x9, %eax
je 0x256f2
cmpl $0x8, %eax
jne 0x25776
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x25878
testb $0x10, (%rdi)
je 0x25859
movq 0x38(%rdi), %r14
leaq 0x5fa9f(%rip), %rdi     # 0x851a5
callq 0x250c7
testq %rax, %rax
je 0x25786
movq %rax, %rbx
leaq 0xf(%rsp), %rsi
pushq $0x5
popq %rdx
movq %r14, %rdi
callq 0x6af65
cmpq $0x5, %rax
jne 0x257a2
leaq 0x6102f(%rip), %rsi     # 0x8675f
leaq 0xf(%rsp), %rdi
pushq $0x5
popq %rdx
callq 0x44d0
testl %eax, %eax
je 0x257d3
leaq 0x5d367(%rip), %rsi     # 0x82ab3
leaq 0xf(%rsp), %rdi
pushq $0x3
popq %rdx
callq 0x44d0
testl %eax, %eax
leaq 0x61003(%rip), %rax     # 0x86765
leaq 0x61031(%rip), %rdx     # 0x8679a
cmoveq %rax, %rdx
leaq 0x60f2f(%rip), %rsi     # 0x866a3
jmp 0x257b0
leaq 0x60f26(%rip), %rsi     # 0x866a3
leaq 0x60f2c(%rip), %rdx     # 0x866b0
jmp 0x25794
leaq 0x60f16(%rip), %rsi     # 0x866a3
leaq 0x60f77(%rip), %rdx     # 0x8670b
xorl %ebx, %ebx
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x8132
jmp 0x257c4
leaq 0x60efa(%rip), %rsi     # 0x866a3
leaq 0x60f79(%rip), %rdx     # 0x86729
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x8132
movq %rbx, %rdi
callq 0x25554
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x14(%rsp), %rsi
pushq $0x4
popq %rdx
movq %r14, %rdi
callq 0x6af65
cmpq $0x4, %rax
jne 0x25831
movl 0x14(%rsp), %r12d
leaq 0x1(%r12), %rdi
callq 0x46a0
testq %rax, %rax
je 0x25831
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x6af65
cmpq %r12, %rax
jne 0x25834
movb $0x0, (%r15,%r12)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x248c9
testl %eax, %eax
js 0x25834
movq %r15, %rdi
callq 0x45c0
jmp 0x257c4
xorl %r15d, %r15d
leaq 0x60e68(%rip), %rsi     # 0x866a3
leaq 0x60f72(%rip), %rdx     # 0x867b4
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x8132
movq %r15, %rdi
callq 0x45c0
jmp 0x257ba
leaq 0x60e7b(%rip), %rdi     # 0x866db
leaq 0x60abc(%rip), %rsi     # 0x86323
leaq 0x60e7a(%rip), %rcx     # 0x866e8
movl $0x618, %edx            # imm = 0x618
callq 0x42e0