// File: /workspace/github_c_makefile_star2_O0/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 %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpl $0x8, 0x4c(%rax)
jne 0x3ffd8
movq -0x10(%rbp), %rdi
callq 0x40260
movq %rax, -0x8(%rbp)
jmp 0x40247
movq -0x10(%rbp), %rax
cmpl $0x9, 0x4c(%rax)
je 0x40009
movl $0x1, %edi
leaq 0xc7a29(%rip), %rsi     # 0x107a17
leaq 0xc7a2f(%rip), %rdx     # 0x107a24
movb $0x0, %al
callq 0x9d90
movq $0x0, -0x8(%rbp)
jmp 0x40247
movq -0x10(%rbp), %rax
movl (%rax), %eax
shrl $0x4, %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x4001c
jmp 0x4003b
leaq 0xc7a2c(%rip), %rdi     # 0x107a4f
leaq 0xc7639(%rip), %rsi     # 0x107663
movl $0x618, %edx            # imm = 0x618
leaq 0xc7a26(%rip), %rcx     # 0x107a5c
callq 0x42d0
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x18(%rbp)
leaq 0xc6422(%rip), %rdi     # 0x106470
callq 0x3f560
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0x40085
movl $0x1, %edi
leaq 0xc79ad(%rip), %rsi     # 0x107a17
leaq 0xc7a0e(%rip), %rdx     # 0x107a7f
movb $0x0, %al
callq 0x9d90
movq $0x0, -0x8(%rbp)
jmp 0x40247
movq -0x18(%rbp), %rdi
leaq -0x1d(%rbp), %rsi
movl $0x5, %edx
callq 0xd98c0
cmpq $0x5, %rax
je 0x400cd
movl $0x1, %edi
leaq 0xc796e(%rip), %rsi     # 0x107a17
leaq 0xc79ed(%rip), %rdx     # 0x107a9d
movb $0x0, %al
callq 0x9d90
movq -0x28(%rbp), %rdi
callq 0x3fd50
movq $0x0, -0x8(%rbp)
jmp 0x40247
leaq -0x1d(%rbp), %rdi
leaq 0xc79fb(%rip), %rsi     # 0x107ad3
movl $0x5, %edx
callq 0x41f0
cmpl $0x0, %eax
je 0x4014d
leaq -0x1d(%rbp), %rdi
leaq 0xc39ed(%rip), %rsi     # 0x103adf
movl $0x3, %edx
callq 0x41f0
cmpl $0x0, %eax
jne 0x4011d
movl $0x1, %edi
leaq 0xc790a(%rip), %rsi     # 0x107a17
leaq 0xc79c5(%rip), %rdx     # 0x107ad9
movb $0x0, %al
callq 0x9d90
jmp 0x40137
movl $0x1, %edi
leaq 0xc78ee(%rip), %rsi     # 0x107a17
leaq 0xc79de(%rip), %rdx     # 0x107b0e
movb $0x0, %al
callq 0x9d90
movq -0x28(%rbp), %rdi
callq 0x3fd50
movq $0x0, -0x8(%rbp)
jmp 0x40247
movq $0x0, -0x40(%rbp)
movq -0x18(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
movl $0x4, %edx
callq 0xd98c0
cmpq $0x4, %rax
je 0x40172
jmp 0x40213
movzbl -0x2c(%rbp), %eax
movzbl -0x2b(%rbp), %ecx
shll $0x8, %ecx
orl %ecx, %eax
movzbl -0x2a(%rbp), %ecx
shll $0x10, %ecx
orl %ecx, %eax
cltq
movzbl -0x29(%rbp), %ecx
shlq $0x18, %rcx
orq %rcx, %rax
movq %rax, -0x38(%rbp)
cmpq $-0x1, -0x38(%rbp)
jb 0x401ad
callq 0x4050
movl $0xc, (%rax)
jmp 0x40213
movq -0x38(%rbp), %rdi
addq $0x1, %rdi
callq 0x4670
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x401c7
jmp 0x40213
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
movq -0x38(%rbp), %rdx
callq 0xd98c0
cmpq -0x38(%rbp), %rax
je 0x401e0
jmp 0x40213
movq -0x40(%rbp), %rax
movq -0x38(%rbp), %rcx
movb $0x0, (%rax,%rcx)
movq -0x28(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x3e890
cmpl $0x0, %eax
jge 0x40200
jmp 0x40213
movq -0x40(%rbp), %rdi
callq 0x45a0
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x40247
movl $0x1, %edi
leaq 0xc77f8(%rip), %rsi     # 0x107a17
leaq 0xc7902(%rip), %rdx     # 0x107b28
movb $0x0, %al
callq 0x9d90
movq -0x40(%rbp), %rdi
callq 0x45a0
movq -0x28(%rbp), %rdi
callq 0x3fd50
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)