// File: /workspace/github_c_makefile_star2_O1/samtools[P]htslib/vcf.c
// Function: bcf_hdr_parse
int bcf_hdr_parse(bcf_hdr_t *hdr, char *htxt)
{
    int len, done = 0;
    char *p = htxt;

    // Check sanity: "fileformat" string must come as first
    bcf_hrec_t *hrec = bcf_hdr_parse_line(hdr,p,&len);
    if ( !hrec || !hrec->key || strcasecmp(hrec->key,"fileformat") )
        hts_log_warning("The first line should be ##fileformat; is the VCF/BCF header broken?");
    if (bcf_hdr_add_hrec(hdr, hrec) < 0) {
        bcf_hrec_destroy(hrec);
        return -1;
    }

    // The filter PASS must appear first in the dictionary
    hrec = bcf_hdr_parse_line(hdr,"##FILTER=<ID=PASS,Description=\"All filters passed\">",&len);
    if (!hrec || bcf_hdr_add_hrec(hdr, hrec) < 0) {
        bcf_hrec_destroy(hrec);
        return -1;
    }

    // Parse the whole header
    do {
        while (NULL != (hrec = bcf_hdr_parse_line(hdr, p, &len))) {
            if (bcf_hdr_add_hrec(hdr, hrec) < 0) {
                bcf_hrec_destroy(hrec);
                return -1;
            }
            p += len;
        }
        assert(hrec == NULL);
        if (len < 0) {
            // len < 0 indicates out-of-memory, or similar error
            hts_log_error("Could not parse header line: %s", strerror(errno));
            return -1;
        } else if (len > 0) {
            // Bad header line.  bcf_hdr_parse_line() will have logged it.
            // Skip and try again on the next line (p + len will be the start
            // of the next one).
            p += len;
            continue;
        }

        // Next should be the sample line.  If not, it was a malformed
        // header, in which case print a warning and skip (many VCF
        // operations do not really care about a few malformed lines).
        // In the future we may want to add a strict mode that errors in
        // this case.
        if ( strncmp("#CHROM\t",p,7) && strncmp("#CHROM ",p,7) ) {
            char *eol = strchr(p, '\n');
            if (*p != '\0') {
                char buffer[320];
                hts_log_warning("Could not parse header line: %s",
                                hts_strprint(buffer, sizeof(buffer),
                                               '"', p,
                                               eol ? (eol - p) : SIZE_MAX));
            }
            if (eol) {
                p = eol + 1; // Try from the next line.
            } else {
                done = -1; // No more lines left, give up.
            }
        } else {
            done = 1; // Sample line found
        }
    } while (!done);

    if (done < 0) {
        // No sample line is fatal.
        hts_log_error("Could not parse the header, sample line not found");
        return -1;
    }

    if (bcf_hdr_parse_sample_line(hdr,p) < 0)
        return -1;
    if (bcf_hdr_sync(hdr) < 0)
        return -1;
    bcf_hdr_check_sanity(hdr);
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rsi, %r14
movq %rdi, %rbx
leaq 0xc(%rsp), %rdx
callq 0x2c456
movq %rax, %r15
testq %rax, %rax
je 0x2e6e3
movq 0x8(%r15), %rdi
testq %rdi, %rdi
je 0x2e6e3
leaq 0x800c0(%rip), %rsi     # 0xae79a
callq 0x4520
testl %eax, %eax
je 0x2e6fd
leaq 0x80134(%rip), %rsi     # 0xae81e
leaq 0x8013b(%rip), %rdx     # 0xae82c
movl $0x3, %edi
xorl %eax, %eax
callq 0x9774
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2ce41
testl %eax, %eax
js 0x2e892
leaq 0x8015a(%rip), %rsi     # 0xae871
leaq 0xc(%rsp), %rdx
callq 0x2c456
movq %rax, %r15
testq %rax, %rax
je 0x2e892
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2ce41
testl %eax, %eax
js 0x2e892
leaq 0xc(%rsp), %r15
leaq 0x818fa(%rip), %r12     # 0xb0046
xorl %r13d, %r13d
movq %r14, %rsi
movq %r15, %rdx
callq 0x2c456
testq %rax, %rax
je 0x2e790
movq %rax, %rbp
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x2ce41
testl %eax, %eax
js 0x2e897
movslq 0xc(%rsp), %rax
addq %rax, %r14
movq %r14, %rsi
movq %r15, %rdx
callq 0x2c456
movq %rax, %rbp
testq %rax, %rax
jne 0x2e762
movslq 0xc(%rsp), %rax
testq %rax, %rax
js 0x2e8b8
testl %eax, %eax
je 0x2e7aa
addq %rax, %r14
jmp 0x2e85b
movl $0x7, %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0x4200
testl %eax, %eax
je 0x2e855
movl $0x7, %edx
leaq 0x800f7(%rip), %rdi     # 0xae8c5
movq %r14, %rsi
callq 0x4200
testl %eax, %eax
je 0x2e855
movq %r14, %rdi
movl $0xa, %esi
callq 0x4180
movq %rax, %rbp
cmpb $0x0, (%r14)
je 0x2e83a
movq %rbp, %rax
subq %r14, %rax
cmpq $0x1, %rbp
movl $0x0, %r8d
sbbq %r8, %r8
orq %rax, %r8
movl $0x140, %esi            # imm = 0x140
leaq 0x10(%rsp), %rdi
movl $0x22, %edx
movq %r14, %rcx
callq 0x2a3a0
movl $0x3, %edi
leaq 0x7fff5(%rip), %rsi     # 0xae81e
leaq 0x80075(%rip), %rdx     # 0xae8a5
movq %rax, %rcx
xorl %eax, %eax
callq 0x9774
leaq 0x1(%rbp), %rax
cmpq $0x1, %rbp
movl $0x0, %ecx
sbbl %ecx, %ecx
orl %ecx, %r13d
testq %rbp, %rbp
cmovneq %rax, %r14
jmp 0x2e85b
movl $0x1, %r13d
testl %r13d, %r13d
je 0x2e74f
js 0x2e8e3
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2bb58
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x2e8a4
movq %rbx, %rdi
callq 0x2bc46
testl %eax, %eax
js 0x2e8a4
movq %rbx, %rdi
callq 0x2e495
xorl %ebp, %ebp
jmp 0x2e8a4
movq %r15, %rdi
jmp 0x2e89a
movq %rbp, %rdi
callq 0x2bd39
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0x7ff53(%rip), %rsi     # 0xae81e
leaq 0x7ffd3(%rip), %rdx     # 0xae8a5
movl $0x1, %edi
movq %rax, %rcx
xorl %eax, %eax
callq 0x9774
jmp 0x2e89f
leaq 0x7ff34(%rip), %rsi     # 0xae81e
leaq 0x7ffdc(%rip), %rdx     # 0xae8cd
movl $0x1, %edi
xorl %eax, %eax
callq 0x9774
jmp 0x2e89f