// File: /workspace/github_c_makefile_star2_O1/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 0x2f85b
cmpl $0x8, %eax
jne 0x2f8dd
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
jmp 0x2f9e7
testb $0x10, (%rdi)
je 0x2f9c8
movq 0x38(%rdi), %r14
leaq 0x7d9c0(%rip), %rdi     # 0xad22f
callq 0x2f149
testq %rax, %rax
je 0x2f8ed
movq %rax, %rbx
leaq 0xf(%rsp), %rsi
movl $0x5, %edx
movq %r14, %rdi
callq 0x8d9e5
cmpq $0x5, %rax
jne 0x2f90b
movl $0x2464342, %eax        # imm = 0x2464342
xorl 0xf(%rsp), %eax
movzbl 0x13(%rsp), %ecx
xorl $0x2, %ecx
orl %eax, %ecx
je 0x2f93e
movzwl 0xf(%rsp), %eax
xorl $0x4342, %eax           # imm = 0x4342
movzbl 0x11(%rsp), %ecx
xorl $0x46, %ecx
orw %ax, %cx
leaq 0x7f19c(%rip), %rax     # 0xaea65
leaq 0x7f1ca(%rip), %rdx     # 0xaea9a
cmoveq %rax, %rdx
leaq 0x7f0c8(%rip), %rsi     # 0xae9a3
jmp 0x2f919
leaq 0x7f0bf(%rip), %rsi     # 0xae9a3
leaq 0x7f0c5(%rip), %rdx     # 0xae9b0
jmp 0x2f8fb
leaq 0x7f0af(%rip), %rsi     # 0xae9a3
leaq 0x7f110(%rip), %rdx     # 0xaea0b
xorl %ebx, %ebx
movl $0x1, %edi
xorl %eax, %eax
callq 0x9774
jmp 0x2f92f
leaq 0x7f091(%rip), %rsi     # 0xae9a3
leaq 0x7f110(%rip), %rdx     # 0xaea29
movl $0x1, %edi
xorl %eax, %eax
callq 0x9774
movq %rbx, %rdi
callq 0x2f696
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 0x8d9e5
cmpq $0x4, %rax
jne 0x2f99e
movl 0x14(%rsp), %r12d
leaq 0x1(%r12), %rdi
callq 0x46a0
testq %rax, %rax
je 0x2f99e
movq %rax, %r15
movq %r14, %rdi
movq %rax, %rsi
movq %r12, %rdx
callq 0x8d9e5
cmpq %r12, %rax
jne 0x2f9a1
movb $0x0, (%r15,%r12)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2e6a1
testl %eax, %eax
js 0x2f9a1
movq %r15, %rdi
callq 0x45c0
jmp 0x2f92f
xorl %r15d, %r15d
leaq 0x7effb(%rip), %rsi     # 0xae9a3
leaq 0x7f105(%rip), %rdx     # 0xaeab4
movl $0x1, %edi
xorl %eax, %eax
callq 0x9774
movq %r15, %rdi
callq 0x45c0
jmp 0x2f925
leaq 0x7f00c(%rip), %rdi     # 0xae9db
leaq 0x7ec4d(%rip), %rsi     # 0xae623
leaq 0x7f00b(%rip), %rcx     # 0xae9e8
movl $0x618, %edx            # imm = 0x618
callq 0x42e0