// File: /workspace/github_c_makefile_star2_O2/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 0x22f44
movq %rax, %r15
testq %rax, %rax
je 0x2490b
movq 0x8(%r15), %rdi
testq %rdi, %rdi
je 0x2490b
leaq 0x61b98(%rip), %rsi     # 0x8649a
callq 0x4520
testl %eax, %eax
je 0x24923
leaq 0x61c0c(%rip), %rsi     # 0x8651e
leaq 0x61c13(%rip), %rdx     # 0x8652c
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x8132
movq %rbx, %rdi
movq %r15, %rsi
callq 0x238dd
testl %eax, %eax
js 0x24a6b
leaq 0x61c34(%rip), %rsi     # 0x86571
leaq 0xc(%rsp), %rdx
callq 0x22f44
movq %rax, %r15
testq %rax, %rax
je 0x24a6b
movq %rbx, %rdi
movq %r15, %rsi
callq 0x238dd
testl %eax, %eax
js 0x24a6b
leaq 0xc(%rsp), %r15
leaq 0x633e0(%rip), %r12     # 0x87d52
pushq $0x7
popq %r13
movq %r14, %rsi
movq %r15, %rdx
callq 0x22f44
testq %rax, %rax
je 0x249a3
movq %rax, %rbp
movq %rbx, %rdi
movq %rax, %rsi
callq 0x238dd
testl %eax, %eax
js 0x24a8a
movslq 0xc(%rsp), %rax
jmp 0x249b5
movslq 0xc(%rsp), %rax
testq %rax, %rax
js 0x24a8f
testl %eax, %eax
je 0x249ba
addq %rax, %r14
jmp 0x24976
movq %r12, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x4200
testl %eax, %eax
je 0x24ab8
leaq 0x61bee(%rip), %rdi     # 0x865c5
movq %r14, %rsi
movq %r13, %rdx
callq 0x4200
testl %eax, %eax
je 0x24ab8
movq %r14, %rdi
pushq $0xa
popq %rsi
callq 0x4180
movq %rax, %rbp
cmpb $0x0, (%r14)
je 0x24a44
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
pushq $0x22
popq %rdx
movq %r14, %rcx
callq 0x20ff6
pushq $0x3
popq %rdi
leaq 0x61aeb(%rip), %rsi     # 0x8651e
leaq 0x61b6b(%rip), %rdx     # 0x865a5
movq %rax, %rcx
xorl %eax, %eax
callq 0x8132
leaq 0x1(%rbp), %r14
testq %rbp, %rbp
jne 0x24976
leaq 0x61ac6(%rip), %rsi     # 0x8651e
leaq 0x61b6e(%rip), %rdx     # 0x865cd
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x8132
jmp 0x24a73
movq %r15, %rdi
callq 0x22854
pushq $-0x1
popq %rbp
movl %ebp, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbp, %rdi
jmp 0x24a6e
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0x61a7c(%rip), %rsi     # 0x8651e
leaq 0x61afc(%rip), %rdx     # 0x865a5
pushq $0x1
popq %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x8132
jmp 0x24a73
movq %rbx, %rdi
movq %r14, %rsi
callq 0x22679
pushq $-0x1
popq %rbp
testl %eax, %eax
js 0x24a76
movq %rbx, %rdi
callq 0x2276e
testl %eax, %eax
js 0x24a76
movq %rbx, %rdi
callq 0x247b0
xorl %ebp, %ebp
jmp 0x24a76