// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/vcf.c
// Function: bcf_hdr_parse_line
bcf_hrec_t *bcf_hdr_parse_line(const bcf_hdr_t *h, const char *line, int *len)
{
    bcf_hrec_t *hrec = NULL;
    const char *p = line;
    if (p[0] != '#' || p[1] != '#') { *len = 0; return NULL; }
    p += 2;

    const char *q = p;
    while ( *q && *q!='=' && *q != '\n' ) q++;
    ptrdiff_t n = q-p;
    if ( *q!='=' || !n ) // wrong format
        goto malformed_line;

    hrec = (bcf_hrec_t*) calloc(1,sizeof(bcf_hrec_t));
    if (!hrec) { *len = -1; return NULL; }
    hrec->key = (char*) malloc(sizeof(char)*(n+1));
    if (!hrec->key) goto fail;
    memcpy(hrec->key,p,n);
    hrec->key[n] = 0;
    hrec->type = -1;

    p = ++q;
    if ( *p!='<' ) // generic field, e.g. ##samtoolsVersion=0.1.18-r579
    {
        while ( *q && *q!='\n' ) q++;
        hrec->value = (char*) malloc((q-p+1)*sizeof(char));
        if (!hrec->value) goto fail;
        memcpy(hrec->value, p, q-p);
        hrec->value[q-p] = 0;
        *len = q - line + (*q ? 1 : 0); // Skip \n but not \0
        return hrec;
    }

    // structured line, e.g.
    // ##INFO=<ID=PV1,Number=1,Type=Float,Description="P-value for baseQ bias">
    // ##PEDIGREE=<Name_0=G0-ID,Name_1=G1-ID,Name_3=GN-ID>
    int nopen = 1;
    while ( *q && *q!='\n' && nopen>0 )
    {
        p = ++q;
        while ( *q && *q==' ' ) { p++; q++; }
        // ^[A-Za-z_][0-9A-Za-z_.]*$
        if (p==q && *q && (isalpha_c(*q) || *q=='_'))
        {
            q++;
            while ( *q && (isalnum_c(*q) || *q=='_' || *q=='.') ) q++;
        }
        n = q-p;
        int m = 0;
        while ( *q && *q==' ' ) { q++; m++; }
        if ( *q!='=' || !n )
            goto malformed_line;

        if (bcf_hrec_add_key(hrec, p, q-p-m) < 0) goto fail;
        p = ++q;
        while ( *q && *q==' ' ) { p++; q++; }

        int quoted = 0;
        char ending = '\0';
        switch (*p) {
        case '"':
            quoted = 1;
            ending = '"';
            p++;
            break;
        case '[':
            quoted = 1;
            ending = ']';
            break;
        }
        if ( quoted ) q++;
        while ( *q && *q != '\n' )
        {
            if ( quoted ) { if ( *q==ending && !is_escaped(p,q) ) break; }
            else
            {
                if ( *q=='<' ) nopen++;
                if ( *q=='>' ) nopen--;
                if ( !nopen ) break;
                if ( *q==',' && nopen==1 ) break;
            }
            q++;
        }
        const char *r = q;
        if (quoted && ending == ']') {
            if (*q == ending) {
                r++;
                q++;
                quoted = 0;
            } else {
                char buffer[320];
                hts_log_error("Missing ']' in header line %s",
                              hts_strprint(buffer, sizeof(buffer), '"',
                                           line, q-line));
                goto fail;
            }
        }
        while ( r > p && r[-1] == ' ' ) r--;
        if (bcf_hrec_set_val(hrec, hrec->nkeys-1, p, r-p, quoted) < 0)
            goto fail;
        if ( quoted && *q==ending ) q++;
        if ( *q=='>' )
        {
            if (nopen) nopen--;     // this can happen with nested angle brackets <>
            q++;
        }
    }
    if ( nopen )
        hts_log_warning("Incomplete header line, trying to proceed anyway:\n\t[%s]\n\t[%d]",line,q[0]);

    // Skip to end of line
    int nonspace = 0;
    p = q;
    while ( *q && *q!='\n' ) { nonspace |= !isspace_c(*q); q++; }
    if (nonspace) {
        char buffer[320];
        hts_log_warning("Dropped trailing junk from header line '%s'",
                        hts_strprint(buffer, sizeof(buffer),
                                     '"', line, q - line));
    }

    *len = q - line + (*q ? 1 : 0);
    return hrec;

 fail:
    *len = -1;
    bcf_hrec_destroy(hrec);
    return NULL;

 malformed_line:
    {
        char buffer[320];
        while ( *q && *q!='\n' ) q++;  // Ensure *len includes full line
        hts_log_error("Could not parse the header line: %s",
                      hts_strprint(buffer, sizeof(buffer),
                                   '"', line, q - line));
        *len = q - line + (*q ? 1 : 0);
        bcf_hrec_destroy(hrec);
        return NULL;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movq %rdx, %rbx
cmpb $0x23, (%rsi)
jne 0x2b3c0
movq %rsi, %r15
cmpb $0x23, 0x1(%rsi)
jne 0x2b3c0
leaq 0x2(%r15), %r12
xorl %r13d, %r13d
movabsq $0x2000000000000401, %rax # imm = 0x2000000000000401
movzbl 0x2(%r15,%r13), %ebp
cmpq $0x3d, %rbp
ja 0x2b3bb
btq %rbp, %rax
jb 0x2b3de
incq %r13
jmp 0x2b3a9
movl $0x0, (%rbx)
xorl %r14d, %r14d
movq %r14, %rax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x3d, %bpl
setne %al
testq %r13, %r13
sete %cl
orb %al, %cl
jne 0x2b6bd
movl $0x1, %edi
movl $0x30, %esi
callq 0x42f0
testq %rax, %rax
je 0x2b741
movq %rax, %r14
movq %rbx, 0x8(%rsp)
leaq 0x1(%r13), %rdi
callq 0x46a0
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x2b88f
movq %rax, %rbp
movq %rax, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x43c0
movb $0x0, (%rbp,%r13)
movl $0xffffffff, (%r14)     # imm = 0xFFFFFFFF
leaq (%r15,%r13), %r12
addq $0x3, %r12
movb (%r12), %bl
cmpb $0x3c, %bl
jne 0x2b74c
movb $0x3c, %al
movl $0x1, %ebx
cmpb $0xa, %al
je 0x2b7aa
testl %ebx, %ebx
jle 0x2b7aa
movb 0x1(%r12), %bpl
incq %r12
cmpb $0x20, %bpl
je 0x2b473
testb %bpl, %bpl
je 0x2b4ad
callq 0x4510
movq (%rax), %rcx
cmpb $0x5f, %bpl
je 0x2b4b7
movzbl %bpl, %eax
movzwl (%rcx,%rax,2), %eax
andl $0x400, %eax            # imm = 0x400
jne 0x2b4b7
movq %r12, %rax
movq %r12, %r13
xorl %ecx, %ecx
jmp 0x2b4fa
xorl %ecx, %ecx
movq %r12, %rax
movq %r12, %r13
jmp 0x2b4f8
leaq 0x1(%r12), %rax
movb 0x1(%r12), %bpl
testb %bpl, %bpl
je 0x2b4f3
leaq 0x2(%r12), %rdx
movzbl %bpl, %esi
testb $0x8, (%rcx,%rsi,2)
jne 0x2b4e4
cmpb $0x2e, %bpl
je 0x2b4e4
cmpl $0x5f, %esi
jne 0x2b696
movb 0x1(%rax), %bpl
incq %rax
incq %rdx
testb %bpl, %bpl
jne 0x2b4cb
xorl %ecx, %ecx
movq %rax, %r13
xorl %ebp, %ebp
cmpb $0x3d, %bpl
jne 0x2b6cc
cmpq %r12, %rax
je 0x2b6cc
addq %r12, %rcx
movq %r13, %rdx
subq %rcx, %rdx
movq %r14, %rdi
movq %r12, %rsi
callq 0x2af5d
testl %eax, %eax
js 0x2b88f
movb 0x1(%r13), %cl
incq %r13
cmpb $0x20, %cl
je 0x2b529
movb $0x1, %al
cmpb $0x5b, %cl
je 0x2b555
movzbl %cl, %ecx
xorl %r12d, %r12d
cmpl $0x22, %ecx
jne 0x2b571
leaq 0x1(%r13), %rdx
movl $0x22, %r12d
xorl %ecx, %ecx
jmp 0x2b560
movl $0x5d, %r12d
movq %r13, %rdx
movb $0x1, %cl
movq %r13, %rbp
incq %rbp
movl $0x1, %r8d
movq %rdx, %r13
jmp 0x2b57b
xorl %ecx, %ecx
xorl %r8d, %r8d
xorl %eax, %eax
movq %r13, %rbp
movzbl (%rbp), %edx
testl %edx, %edx
je 0x2b5e5
cmpl $0xa, %edx
je 0x2b5e5
testb %al, %al
je 0x2b5b6
movsbl %dl, %esi
cmpl %esi, %r12d
jne 0x2b5e0
leaq -0x1(%rbp), %rdi
cmpq %r13, %rdi
jb 0x2b5e5
xorl %esi, %esi
cmpb $0x5c, (%rdi)
jne 0x2b5ae
incl %esi
decq %rdi
cmpq %r13, %rdi
jae 0x2b59f
testb $0x1, %sil
jne 0x2b5e0
jmp 0x2b5e5
xorl %esi, %esi
cmpb $0x3c, %dl
sete %sil
addl %esi, %ebx
xorl %esi, %esi
cmpb $0x3e, %dl
sete %sil
subl %esi, %ebx
je 0x2b67c
cmpb $0x2c, %dl
jne 0x2b5e0
cmpl $0x1, %ebx
je 0x2b689
incq %rbp
jmp 0x2b57b
andb %al, %cl
cmpb $0x1, %cl
jne 0x2b5fb
cmpb $0x5d, %dl
jne 0x2b855
incq %rbp
xorl %r8d, %r8d
movl %ebx, 0x4(%rsp)
movq %rbp, %rdx
subq %r13, %rdx
movq %rbp, %rax
movq %rdx, %rcx
cmpq %r13, %rax
jbe 0x2b61e
cmpb $0x20, -0x1(%rax)
leaq -0x1(%rax), %rax
leaq -0x1(%rcx), %rdx
je 0x2b608
movl 0x18(%r14), %esi
decl %esi
movq %r14, %rdi
movq %r13, %rdx
movl %r8d, %ebx
callq 0x2b041
testl %eax, %eax
js 0x2b88f
testl %ebx, %ebx
je 0x2b64d
movsbl (%rbp), %eax
xorl %ecx, %ecx
cmpl %eax, %r12d
sete %cl
addq %rcx, %rbp
movl 0x4(%rsp), %ecx
xorl %eax, %eax
movl %ecx, %ebx
subl $0x1, %ebx
cmovbl %eax, %ebx
xorl %eax, %eax
cmpb $0x3e, (%rbp)
cmovnel %ecx, %ebx
sete %al
leaq (%rax,%rbp), %r12
movb (%rbp,%rax), %al
testb %al, %al
jne 0x2b463
jmp 0x2b7a8
movl $0x0, 0x4(%rsp)
jmp 0x2b5ff
movl $0x1, 0x4(%rsp)
jmp 0x2b5ff
cmpl $0x20, %esi
jne 0x2b6b5
xorl %ecx, %ecx
movb (%rdx), %bpl
incq %rcx
incq %rdx
cmpb $0x20, %bpl
je 0x2b69d
leaq (%rax,%rcx), %r13
jmp 0x2b4fa
movq %rax, %r13
jmp 0x2b4a9
movq %rbx, 0x8(%rsp)
addq %r15, %r13
addq $0x2, %r13
xorl %r14d, %r14d
leaq 0x1(%r13), %r12
movl %r13d, %ebx
subl %r15d, %ebx
subq %r15, %r13
testb %bpl, %bpl
je 0x2b6f5
movzbl %bpl, %eax
cmpl $0xa, %eax
je 0x2b6f5
movb (%r12), %bpl
incq %r12
incl %ebx
incq %r13
jmp 0x2b6d9
leaq 0x10(%rsp), %rdi
movl $0x140, %esi            # imm = 0x140
movl $0x22, %edx
movq %r15, %rcx
movq %r13, %r8
callq 0x29393
leaq 0x7fefc(%rip), %rsi     # 0xab612
leaq 0x7ff90(%rip), %rdx     # 0xab6ad
movl $0x1, %edi
movq %rax, %rcx
xorl %eax, %eax
callq 0x942d
cmpb $0x1, -0x1(%r12)
sbbl $-0x1, %ebx
movq 0x8(%rsp), %rax
movl %ebx, (%rax)
jmp 0x2b89a
movl $0xffffffff, (%rbx)     # imm = 0xFFFFFFFF
jmp 0x2b3c6
xorl %ebp, %ebp
testb %bl, %bl
je 0x2b767
movzbl %bl, %eax
cmpl $0xa, %eax
je 0x2b767
movb 0x4(%r15,%r13), %bl
incq %r13
incq %rbp
jmp 0x2b74e
leaq 0x1(%rbp), %rdi
callq 0x46a0
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x2b88f
movq %rax, %r15
movq %rax, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x43c0
movb $0x0, (%r15,%rbp)
cmpb $0x1, %bl
sbbl $-0x1, %r13d
addl $0x3, %r13d
movq 0x8(%rsp), %rax
jmp 0x2b84d
xorl %eax, %eax
testl %ebx, %ebx
je 0x2b7cf
movsbl %al, %r8d
leaq 0x7fe59(%rip), %rsi     # 0xab612
leaq 0x7fe83(%rip), %rdx     # 0xab643
movl $0x3, %edi
movq %r15, %rcx
xorl %eax, %eax
callq 0x942d
movq %r12, %r13
subq %r15, %r13
xorl %ebx, %ebx
movzbl (%r12), %ebp
testl %ebp, %ebp
je 0x2b801
cmpl $0xa, %ebp
je 0x2b801
callq 0x4510
movq (%rax), %rax
xorl %ecx, %ecx
testb $0x20, 0x1(%rax,%rbp,2)
sete %cl
orl %ecx, %ebx
incq %r12
incq %r13
jmp 0x2b7d7
testl %ebx, %ebx
je 0x2b840
leaq 0x10(%rsp), %rdi
movl $0x140, %esi            # imm = 0x140
movl $0x22, %edx
movq %r15, %rcx
movq %r13, %r8
callq 0x29393
leaq 0x7fdec(%rip), %rsi     # 0xab612
leaq 0x7fe54(%rip), %rdx     # 0xab681
movl $0x3, %edi
movq %rax, %rcx
xorl %eax, %eax
callq 0x942d
movb (%r12), %bpl
movq 0x8(%rsp), %rax
cmpb $0x1, %bpl
sbbl $-0x1, %r13d
movl %r13d, (%rax)
jmp 0x2b3c9
subq %r15, %rbp
leaq 0x10(%rsp), %rdi
movl $0x140, %esi            # imm = 0x140
movl $0x22, %edx
movq %r15, %rcx
movq %rbp, %r8
callq 0x29393
leaq 0x7fd99(%rip), %rsi     # 0xab612
leaq 0x7fda5(%rip), %rdx     # 0xab625
movl $0x1, %edi
movq %rax, %rcx
xorl %eax, %eax
callq 0x942d
movq 0x8(%rsp), %rax
movl $0xffffffff, (%rax)     # imm = 0xFFFFFFFF
movq %r14, %rdi
callq 0x2ac82
jmp 0x2b3c6