// File: /workspace/github_c_makefile_star2_O2/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, %r12
cmpb $0x23, (%rsi)
jne 0x22f8e
movq %rsi, %r15
cmpb $0x23, 0x1(%rsi)
jne 0x22f8e
leaq 0x2(%r15), %rbp
xorl %r13d, %r13d
movabsq $0x2000000000000401, %rax # imm = 0x2000000000000401
movzbl 0x2(%r15,%r13), %ebx
cmpq $0x3d, %rbx
ja 0x22f89
btq %rbx, %rax
jb 0x22fab
incq %r13
jmp 0x22f77
andl $0x0, (%r12)
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, %bl
setne %al
testq %r13, %r13
sete %cl
orb %al, %cl
jne 0x23232
pushq $0x1
popq %rdi
pushq $0x30
popq %rsi
callq 0x42f0
testq %rax, %rax
je 0x232af
movq %rax, %r14
movq %r12, (%rsp)
leaq 0x1(%r13), %rdi
callq 0x46a0
movq %rax, 0x8(%r14)
testq %rax, %rax
je 0x233f6
movq %rax, %r12
movq %rax, %rdi
movq %rbp, %rsi
movq %r13, %rdx
callq 0x43c0
orl $-0x1, (%r14)
movb $0x0, (%r12,%r13)
leaq (%r15,%r13), %rbp
addq $0x3, %rbp
movb (%rbp), %bl
cmpb $0x3c, %bl
jne 0x232b9
pushq $0x1
popq %r12
movb $0x3c, %al
movq %r14, 0x8(%rsp)
testb %al, %al
je 0x23319
cmpb $0xa, %al
je 0x23319
testl %r12d, %r12d
jle 0x23319
leaq 0x1(%rbp), %rax
leaq 0x2(%rbp), %rcx
movq %rax, %r14
movq %rcx, %r13
movzbl 0x1(%rbp), %ebx
incq %rbp
incq %rax
incq %rcx
cmpl $0x20, %ebx
je 0x2304a
testl %ebx, %ebx
je 0x2307f
callq 0x4510
movq (%rax), %rax
cmpb $0x5f, %bl
je 0x23083
movzwl (%rax,%rbx,2), %ecx
andl $0x400, %ecx            # imm = 0x400
jne 0x23083
xorl %edx, %edx
jmp 0x230a7
pushq $0x1
popq %rdx
movzbl (%rbp,%rdx), %ebx
testq %rbx, %rbx
je 0x230a5
testb $0x8, (%rax,%rbx,2)
jne 0x230a0
cmpl $0x5f, %ebx
je 0x230a0
cmpl $0x2e, %ebx
jne 0x230a7
incq %rdx
jmp 0x23086
xorl %ebx, %ebx
leaq (%rdx,%rbp), %r8
addq %rdx, %r13
cmpb $0x20, %bl
jne 0x230c2
movb 0x1(%r8), %bl
incq %r8
incq %r14
incq %r13
jmp 0x230ae
cmpb $0x3d, %bl
jne 0x233b7
testq %rdx, %rdx
je 0x233b7
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbp, %rsi
callq 0x22bfa
testl %eax, %eax
js 0x233f6
movzbl (%r13), %eax
incq %r13
cmpl $0x20, %eax
je 0x230ec
cmpl $0x5b, %eax
je 0x2310f
cmpl $0x22, %eax
jne 0x2311f
movb $0x1, %cl
xorl %eax, %eax
pushq $0x22
popq %rbp
pushq $0x1
popq %rbx
jmp 0x2312a
leaq -0x1(%r13), %rdx
movb $0x1, %al
pushq $0x5d
popq %rbp
pushq $0x1
popq %rbx
movb $0x1, %cl
jmp 0x2312d
decq %r13
xorl %ebp, %ebp
xorl %eax, %eax
xorl %ebx, %ebx
xorl %ecx, %ecx
movq %r13, %rdx
leaq -0x1(%r13), %rsi
movzbl (%r13), %edi
testl %edi, %edi
je 0x2319d
cmpl $0xa, %edi
je 0x2319d
testb %cl, %cl
je 0x23163
movsbl %dil, %r8d
cmpl %r8d, %ebp
jne 0x23195
xorl %r8d, %r8d
leaq (%rsi,%r8), %r9
cmpq %rdx, %r9
jb 0x2318f
cmpb $0x5c, (%r9)
jne 0x2318f
decq %r8
jmp 0x2314f
xorl %r8d, %r8d
cmpb $0x3c, %dil
sete %r8b
addl %r8d, %r12d
xorl %r8d, %r8d
cmpb $0x3e, %dil
sete %r8b
subl %r8d, %r12d
je 0x231b4
cmpb $0x2c, %dil
jne 0x23195
cmpl $0x1, %r12d
jne 0x23195
jmp 0x231b9
testb $0x1, %r8b
je 0x2319d
incq %r13
incq %rsi
jmp 0x23131
andb %cl, %al
cmpb $0x1, %al
jne 0x231bd
cmpb $0x5d, %dil
jne 0x233c0
incq %r13
xorl %ebx, %ebx
jmp 0x231bd
xorl %r12d, %r12d
jmp 0x231bd
pushq $0x1
popq %r12
movq %r13, %rsi
subq %rdx, %rsi
movq %r13, %rax
movq %rsi, %rcx
cmpq %rdx, %rax
jbe 0x231dc
cmpb $0x20, -0x1(%rax)
leaq -0x1(%rax), %rax
leaq -0x1(%rcx), %rsi
je 0x231c6
movl 0x18(%r14), %esi
decl %esi
movq %r14, %rdi
movl %ebx, %r8d
callq 0x22cd9
testl %eax, %eax
js 0x233f6
testl %ebx, %ebx
je 0x23208
movsbl (%r13), %eax
xorl %ecx, %ecx
cmpl %eax, %ebp
sete %cl
addq %rcx, %r13
movl %r12d, %eax
subl $0x1, %eax
movl $0x0, %ecx
cmovbl %ecx, %eax
xorl %ecx, %ecx
cmpb $0x3e, (%r13)
sete %cl
cmovel %eax, %r12d
leaq (%rcx,%r13), %rbp
movb (%r13,%rcx), %al
jmp 0x23029
leaq (%r15,%r13), %r8
addq $0x2, %r8
movq $0x0, 0x8(%rsp)
leaq 0x1(%r8), %r14
movl %r8d, %ebp
subl %r15d, %ebp
subq %r15, %r8
testb %bl, %bl
je 0x23269
movzbl %bl, %eax
cmpl $0xa, %eax
je 0x23269
movb (%r14), %bl
incq %r14
incl %ebp
incq %r8
jmp 0x23250
leaq 0x10(%rsp), %rdi
pushq $0x22
popq %rdx
movl $0x140, %esi            # imm = 0x140
movq %r15, %rcx
callq 0x20ff6
leaq 0x630dd(%rip), %rsi     # 0x86362
leaq 0x63171(%rip), %rdx     # 0x863fd
pushq $0x1
popq %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x8132
cmpb $0x1, -0x1(%r14)
sbbl $-0x1, %ebp
movl %ebp, (%r12)
movq 0x8(%rsp), %rdi
jmp 0x23400
orl $-0x1, (%r12)
jmp 0x22f93
xorl %r12d, %r12d
testb %bl, %bl
je 0x232d5
movzbl %bl, %eax
cmpl $0xa, %eax
je 0x232d5
movb 0x4(%r15,%r13), %bl
incq %r13
incq %r12
jmp 0x232bc
leaq 0x1(%r12), %rdi
callq 0x46a0
movq %rax, 0x10(%r14)
testq %rax, %rax
je 0x233f6
movq %rax, %r15
movq %rax, %rdi
movq %rbp, %rsi
movq %r12, %rdx
callq 0x43c0
movb $0x0, (%r15,%r12)
cmpb $0x1, %bl
sbbl $-0x1, %r13d
addl $0x3, %r13d
movq (%rsp), %rax
movl %r13d, (%rax)
jmp 0x22f96
testl %r12d, %r12d
je 0x2333d
movsbl %al, %r8d
leaq 0x63039(%rip), %rsi     # 0x86362
leaq 0x63063(%rip), %rdx     # 0x86393
pushq $0x3
popq %rdi
movq %r15, %rcx
xorl %eax, %eax
callq 0x8132
movq %rbp, %r12
subq %r15, %r12
xorl %ebx, %ebx
movzbl (%rbp), %eax
testl %eax, %eax
je 0x2336b
cmpl $0xa, %eax
je 0x2336b
movsbl %al, %edi
callq 0x2340a
xorl %ecx, %ecx
testl %eax, %eax
sete %cl
orl %ecx, %ebx
incq %rbp
incq %r12
jmp 0x23345
testl %ebx, %ebx
je 0x233a5
leaq 0x10(%rsp), %rdi
pushq $0x22
popq %rdx
movl $0x140, %esi            # imm = 0x140
movq %r15, %rcx
movq %r12, %r8
callq 0x20ff6
leaq 0x62fd4(%rip), %rsi     # 0x86362
leaq 0x6303c(%rip), %rdx     # 0x863d1
pushq $0x3
popq %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x8132
movb (%rbp), %al
cmpb $0x1, %al
sbbl $-0x1, %r12d
movq (%rsp), %rax
movl %r12d, (%rax)
jmp 0x22f96
movq (%rsp), %r12
jmp 0x23243
subq %r15, %r13
leaq 0x10(%rsp), %rdi
pushq $0x22
popq %rdx
movl $0x140, %esi            # imm = 0x140
movq %r15, %rcx
movq %r13, %r8
callq 0x20ff6
leaq 0x62f80(%rip), %rsi     # 0x86362
leaq 0x62f8c(%rip), %rdx     # 0x86375
pushq $0x1
popq %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x8132
movq (%rsp), %rax
orl $-0x1, (%rax)
movq %r14, %rdi
callq 0x22854
jmp 0x22f93