// File: /workspace/github_c_makefile_star2_O3/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 0x2e643
cmpl $0x8, %eax
jne 0x2e6c5
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x2e7cf
testb $0x10, (%rdi)
je 0x2e7b0
movq 0x38(%rdi), %r14
leaq 0x7bb83(%rip), %rdi     # 0xaa1da
callq 0x2df79
testq %rax, %rax
je 0x2e6d5
movq %rax, %rbx
leaq 0xf(%rsp), %rsi
movl $0x5, %edx
movq %r14, %rdi
callq 0x8b99c
cmpq $0x5, %rax
jne 0x2e6f3
movl $0x2464342, %eax        # imm = 0x2464342
xorl 0xf(%rsp), %eax
movzbl 0x13(%rsp), %ecx
xorl $0x2, %ecx
orl %eax, %ecx
je 0x2e726
movzwl 0xf(%rsp), %eax
xorl $0x4342, %eax           # imm = 0x4342
movzbl 0x11(%rsp), %ecx
xorl $0x46, %ecx
orw %ax, %cx
leaq 0x7d364(%rip), %rax     # 0xaba15
leaq 0x7d392(%rip), %rdx     # 0xaba4a
cmoveq %rax, %rdx
leaq 0x7d290(%rip), %rsi     # 0xab953
jmp 0x2e701
leaq 0x7d287(%rip), %rsi     # 0xab953
leaq 0x7d28d(%rip), %rdx     # 0xab960
jmp 0x2e6e3
leaq 0x7d277(%rip), %rsi     # 0xab953
leaq 0x7d2d8(%rip), %rdx     # 0xab9bb
xorl %ebx, %ebx
movl $0x1, %edi
xorl %eax, %eax
callq 0x942d
jmp 0x2e717
leaq 0x7d259(%rip), %rsi     # 0xab953
leaq 0x7d2d8(%rip), %rdx     # 0xab9d9
movl $0x1, %edi
xorl %eax, %eax
callq 0x942d
movq %rbx, %rdi
callq 0x2e474
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x14(%rsp), %rsi
movl $0x4, %edx
movq %r14, %rdi
callq 0x8b99c
cmpq $0x4, %rax
jne 0x2e786
movl 0x14(%rsp), %r12d
leaq 0x1(%r12), %rdi
callq 0x46a0
testq %rax, %rax
je 0x2e786
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x8b99c
cmpq %r12, %rax
jne 0x2e789
movb $0x0, (%r15,%r12)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2d4f2
testl %eax, %eax
js 0x2e789
movq %r15, %rdi
callq 0x45c0
jmp 0x2e717
xorl %r15d, %r15d
leaq 0x7d1c3(%rip), %rsi     # 0xab953
leaq 0x7d2cd(%rip), %rdx     # 0xaba64
movl $0x1, %edi
xorl %eax, %eax
callq 0x942d
movq %r15, %rdi
callq 0x45c0
jmp 0x2e70d
leaq 0x7d1d4(%rip), %rdi     # 0xab98b
leaq 0x7ce15(%rip), %rsi     # 0xab5d3
leaq 0x7d1d3(%rip), %rcx     # 0xab998
movl $0x618, %edx            # imm = 0x618
callq 0x42e0