// File: /workspace/github_c_makefile_star2_O3/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 0x2b376
movq %rax, %r15
testq %rax, %rax
je 0x2d534
movq 0x8(%r15), %rdi
testq %rdi, %rdi
je 0x2d534
leaq 0x7e21f(%rip), %rsi     # 0xab74a
callq 0x4520
testl %eax, %eax
je 0x2d54e
leaq 0x7e293(%rip), %rsi     # 0xab7ce
leaq 0x7e29a(%rip), %rdx     # 0xab7dc
movl $0x3, %edi
xorl %eax, %eax
callq 0x942d
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2bd95
testl %eax, %eax
js 0x2d6b7
leaq 0x7e2b9(%rip), %rsi     # 0xab821
leaq 0xc(%rsp), %rdx
callq 0x2b376
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
testq %rax, %rax
je 0x2d6d3
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2bd95
testl %eax, %eax
js 0x2d6cb
leaq 0xc(%rsp), %r15
leaq 0x7fa54(%rip), %r12     # 0xacff6
movq %r14, %rsi
movq %r15, %rdx
callq 0x2b376
testq %rax, %rax
je 0x2d5e3
movq %rax, %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2bd95
testl %eax, %eax
js 0x2d6c6
movslq 0xc(%rsp), %rax
addq %rax, %r14
movq %r14, %rsi
movq %r15, %rdx
callq 0x2b376
movq %rax, %r13
testq %rax, %rax
jne 0x2d5b5
movslq 0xc(%rsp), %rax
testq %rax, %rax
js 0x2d6e7
testl %eax, %eax
je 0x2d5fa
addq %rax, %r14
jmp 0x2d5a2
movl $0x7, %edx
movq %r12, %rdi
movq %r14, %rsi
callq 0x4200
testl %eax, %eax
je 0x2d712
movl $0x7, %edx
leaq 0x7e257(%rip), %rdi     # 0xab875
movq %r14, %rsi
callq 0x4200
testl %eax, %eax
je 0x2d712
movq %r14, %rdi
movl $0xa, %esi
callq 0x4180
movq %rax, %r13
cmpb $0x0, (%r14)
je 0x2d68e
movq %r13, %rax
subq %r14, %rax
cmpq $0x1, %r13
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 0x29393
movl $0x3, %edi
leaq 0x7e151(%rip), %rsi     # 0xab7ce
leaq 0x7e1d1(%rip), %rdx     # 0xab855
movq %rax, %rcx
xorl %eax, %eax
callq 0x942d
leaq 0x1(%r13), %r14
testq %r13, %r13
jne 0x2d5a2
leaq 0x7e12c(%rip), %rsi     # 0xab7ce
leaq 0x7e1d4(%rip), %rdx     # 0xab87d
movl $0x1, %edi
xorl %eax, %eax
callq 0x942d
jmp 0x2d6d3
movq %r15, %rdi
callq 0x2ac82
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
jmp 0x2d6d3
movq %r13, %rdi
jmp 0x2d6ce
movq %r15, %rdi
callq 0x2ac82
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 0x7e0d4(%rip), %rsi     # 0xab7ce
leaq 0x7e154(%rip), %rdx     # 0xab855
movl $0x1, %edi
movq %rax, %rcx
xorl %eax, %eax
callq 0x942d
jmp 0x2d6d3
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2aaa0
testl %eax, %eax
js 0x2d6d3
movq %rbx, %rdi
callq 0x2ab97
testl %eax, %eax
js 0x2d6d3
movq %rbx, %rdi
callq 0x2d2e9
xorl %ebp, %ebp
jmp 0x2d6d3