// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/vcf.c
// Function: bcf_update_info
int bcf_update_info(const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type)
{
    static int negative_rlen_warned = 0;
    int is_end_tag, is_svlen_tag = 0;

    // Is the field already present?
    int i, inf_id = bcf_hdr_id2int(hdr,BCF_DT_ID,key);
    if ( !bcf_hdr_idinfo_exists(hdr,BCF_HL_INFO,inf_id) ) return -1;    // No such INFO field in the header
    if ( !(line->unpacked & BCF_UN_INFO) ) bcf_unpack(line, BCF_UN_INFO);

    is_end_tag = strcmp(key, "END") == 0;
    is_svlen_tag = strcmp(key, "SVLEN") == 0;

    for (i=0; i<line->n_info; i++)
        if ( inf_id==line->d.info[i].key ) break;
    bcf_info_t *inf = i==line->n_info ? NULL : &line->d.info[i];

    if ( !n || (type==BCF_HT_STR && !values) )
    {
        if ( inf )
        {
            // Mark the tag for removal, free existing memory if necessary
            if ( inf->vptr_free )
            {
                free(inf->vptr - inf->vptr_off);
                inf->vptr_free = 0;
            }
            line->d.shared_dirty |= BCF1_DIRTY_INF;
            inf->vptr = NULL;
            inf->vptr_off = inf->vptr_len = 0;
        }
        if ( n==0 && (is_end_tag || is_svlen_tag) ) {
            line->rlen = get_rlen(hdr, line);
        }
        return 0;
    }

    if (is_end_tag)
    {
        if (n != 1)
        {
            hts_log_error("END info tag should only have one value at %s:%"PRIhts_pos, bcf_seqname_safe(hdr,line), line->pos+1);
            line->errcode |= BCF_ERR_TAG_INVALID;
            return -1;
        }
        if (type != BCF_HT_INT && type != BCF_HT_LONG)
        {
            hts_log_error("Wrong type (%d) for END info tag at %s:%"PRIhts_pos, type, bcf_seqname_safe(hdr,line), line->pos+1);
            line->errcode |= BCF_ERR_TAG_INVALID;
            return -1;
        }
    }

    // Encode the values and determine the size required to accommodate the values
    kstring_t str = {0,0,0};
    bcf_enc_int1(&str, inf_id);
    if ( type==BCF_HT_INT )
        bcf_enc_vint(&str, n, (int32_t*)values, -1);
    else if ( type==BCF_HT_REAL )
        bcf_enc_vfloat(&str, n, (float*)values);
    else if ( type==BCF_HT_FLAG || type==BCF_HT_STR )
    {
        if ( values==NULL )
            bcf_enc_size(&str, 0, BCF_BT_NULL);
        else
            bcf_enc_vchar(&str, strlen((char*)values), (char*)values);
    }
#ifdef VCF_ALLOW_INT64
    else if ( type==BCF_HT_LONG )
    {
        if (n != 1) {
            hts_log_error("Only storing a single BCF_HT_LONG value is supported at %s:%"PRIhts_pos, bcf_seqname_safe(hdr,line), line->pos+1);
            abort();
        }
        bcf_enc_long1(&str, *(int64_t *) values);
    }
#endif
    else
    {
        hts_log_error("The type %d not implemented yet at %s:%"PRIhts_pos, type, bcf_seqname_safe(hdr,line), line->pos+1);
        abort();
    }

    // Is the INFO tag already present
    if ( inf )
    {
        // Is it big enough to accommodate new block?
        if ( inf->vptr && str.l <= inf->vptr_len + inf->vptr_off )
        {
            if ( str.l != inf->vptr_len + inf->vptr_off ) line->d.shared_dirty |= BCF1_DIRTY_INF;
            uint8_t *ptr = inf->vptr - inf->vptr_off;
            memcpy(ptr, str.s, str.l);
            free(str.s);
            int vptr_free = inf->vptr_free;
            bcf_unpack_info_core1(ptr, inf);
            inf->vptr_free = vptr_free;
        }
        else
        {
            if ( inf->vptr_free )
                free(inf->vptr - inf->vptr_off);
            bcf_unpack_info_core1((uint8_t*)str.s, inf);
            inf->vptr_free = 1;
            line->d.shared_dirty |= BCF1_DIRTY_INF;
        }
    }
    else
    {
        // The tag is not present, create new one
        line->n_info++;
        hts_expand0(bcf_info_t, line->n_info, line->d.m_info , line->d.info);
        inf = &line->d.info[line->n_info-1];
        bcf_unpack_info_core1((uint8_t*)str.s, inf);
        inf->vptr_free = 1;
        line->d.shared_dirty |= BCF1_DIRTY_INF;
    }
    line->unpacked |= BCF_UN_INFO;

   if ( n==1 && is_end_tag) {
        hts_pos_t end = type == BCF_HT_INT ? *(int32_t *) values : *(int64_t *) values;
        if ( (type == BCF_HT_INT && end!=bcf_int32_missing) || (type == BCF_HT_LONG && end!=bcf_int64_missing) )
        {
            if ( end <= line->pos )
            {
                if ( !negative_rlen_warned )
                {
                    hts_log_warning("INFO/END=%"PRIhts_pos" is smaller than POS at %s:%"PRIhts_pos,end,bcf_seqname_safe(hdr,line),line->pos+1);
                    negative_rlen_warned = 1;
                }
            }
        }
    }
    if (is_svlen_tag || is_end_tag) {
        line->rlen = get_rlen(hdr, line);
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movl %r9d, %ebx
movl %r8d, %r15d
movq %rcx, 0x20(%rsp)
movq %rdx, %rbp
movq %rsi, 0x18(%rsp)
movq %rdi, %r14
xorl %esi, %esi
callq 0x2489c
pushq $-0x1
popq %r13
testl %eax, %eax
js 0x2ef26
movl %eax, %r12d
cmpl (%r14), %eax
jge 0x2ef26
movq 0x10(%r14), %rax
movl %r12d, %ecx
shlq $0x4, %rcx
movq 0x8(%rax,%rcx), %rax
testq %rax, %rax
je 0x2ef26
movl 0x8(%rax), %eax
notl %eax
testb $0xf, %al
je 0x2ef26
movl %r15d, 0x2c(%rsp)
movq 0x18(%rsp), %r15
testb $0x4, 0xbc(%r15)
jne 0x2eaea
pushq $0x4
popq %rsi
movq %r15, %rdi
callq 0x2b198
leaq 0x58410(%rip), %rsi     # 0x86f01
movq %rbp, %rdi
callq 0x46e0
movl %eax, 0x14(%rsp)
leaq 0x58401(%rip), %rsi     # 0x86f05
movq %rbp, %rdi
callq 0x46e0
leaq 0x90(%r15), %rbp
movzwl 0x18(%r15), %ecx
imulq $0x28, %rcx, %rdx
xorl %r9d, %r9d
xorl %r8d, %r8d
movq %r15, %rsi
movl 0x2c(%rsp), %r15d
cmpq %r8, %rdx
je 0x2eb53
movq (%rbp), %rdi
cmpl (%rdi,%r8), %r12d
je 0x2eb3f
addq $0x28, %r8
jmp 0x2eb2a
imull $0x28, %ecx, %ecx
cmpl %r8d, %ecx
jne 0x2eb4c
xorl %r9d, %r9d
jmp 0x2eb53
addq (%rbp), %r8
movq %r8, %r9
testl %r15d, %r15d
je 0x2ebbd
cmpl $0x3, %ebx
setne %dl
cmpq $0x0, 0x20(%rsp)
setne %cl
orb %dl, %cl
je 0x2ebbd
cmpl $0x0, 0x14(%rsp)
je 0x2ec40
movq %r9, 0x50(%rsp)
movl %eax, 0x28(%rsp)
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movl %r12d, %esi
callq 0x28086
movl %ebx, %r13d
cmpl $0x1, %ebx
jne 0x2ec96
leaq 0x30(%rsp), %rdi
pushq $-0x1
popq %rcx
movl %r15d, %esi
movq 0x20(%rsp), %rdx
callq 0x27d4a
jmp 0x2ed28
testq %r9, %r9
movl 0x14(%rsp), %ebx
je 0x2ec0e
movl 0x1c(%r9), %ecx
testl %ecx, %ecx
jns 0x2ebf5
movq 0x10(%r9), %rdi
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
subq %rcx, %rdi
movl %eax, %ebp
movq %r9, %r12
callq 0x45c0
movq %r12, %r9
movl %ebp, %eax
movq 0x18(%rsp), %rsi
andb $0x7f, 0x1f(%r12)
orb $0x8, 0xb0(%rsi)
andq $0x0, 0x10(%r9)
andl $0x0, 0x18(%r9)
andl $0x80000000, 0x1c(%r9)  # imm = 0x80000000
testl %eax, %eax
sete %al
testl %ebx, %ebx
sete %cl
xorl %r13d, %r13d
testl %r15d, %r15d
jne 0x2ef26
orb %al, %cl
je 0x2ef26
movq %r14, %rdi
movq %rsi, %rbx
callq 0x2a765
movq %rax, 0x8(%rbx)
jmp 0x2ef26
cmpl $0x1, %r15d
jne 0x2ece2
movl %ebx, %ecx
andl $0xfffffeff, %ecx       # imm = 0xFFFFFEFF
cmpl $0x1, %ecx
je 0x2eb76
movq %r14, %rdi
movq %rsi, %r14
callq 0x27650
movq (%r14), %r9
incq %r9
leaq 0x58298(%rip), %rsi     # 0x86f0b
leaq 0x582d3(%rip), %rdx     # 0x86f4d
pushq $0x1
popq %rdi
movl %ebx, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x8132
orb $0x40, 0xcc(%r14)
jmp 0x2ef26
testl %r13d, %r13d
je 0x2ecbf
cmpl $0x3, %r13d
je 0x2ecbf
cmpl $0x2, %r13d
jne 0x2ef38
leaq 0x30(%rsp), %rdi
movl %r15d, %esi
movq 0x20(%rsp), %rdx
callq 0x28170
jmp 0x2ed28
movq 0x20(%rsp), %r12
testq %r12, %r12
je 0x2ed1a
movq %r12, %rdi
callq 0x41c0
leaq 0x30(%rsp), %rdi
movl %eax, %esi
movq %r12, %rdx
callq 0x28223
jmp 0x2ed28
movq %r14, %rdi
movq %rsi, %rbx
callq 0x27650
movq (%rbx), %r8
incq %r8
leaq 0x58211(%rip), %rsi     # 0x86f0b
leaq 0x5821a(%rip), %rdx     # 0x86f1b
pushq $0x1
popq %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x8132
orb $0x40, 0xcc(%rbx)
jmp 0x2ef26
leaq 0x30(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x27feb
movq 0x50(%rsp), %r9
testq %r9, %r9
movq 0x18(%rsp), %r8
je 0x2edcb
movq 0x10(%r9), %r12
testq %r12, %r12
je 0x2ee4c
movq 0x30(%rsp), %rdx
movl 0x1c(%r9), %eax
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl 0x18(%r9), %esi
addl %ecx, %esi
cmpq %rsi, %rdx
ja 0x2ee50
je 0x2ed7b
orb $0x8, 0xb0(%r8)
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl 0x1c(%r9), %ecx
movl %ecx, %eax
subq %rax, %r12
movq 0x40(%rsp), %rbp
movq %r12, %rdi
movq %rbp, %rsi
movq %r9, %r13
callq 0x43c0
movq %rbp, %rdi
callq 0x45c0
movl $0x80000000, %ebp       # imm = 0x80000000
andl 0x1c(%r13), %ebp
movq %r12, %rdi
movq %r13, %rsi
callq 0x2b607
movq 0x18(%rsp), %rsi
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl 0x1c(%r13), %eax
orl %ebp, %eax
movl %eax, 0x1c(%r13)
movl %ebx, %r13d
jmp 0x2ee89
movl 0x18(%r8), %eax
incl %eax
movzwl %ax, %edi
movw %di, 0x18(%r8)
movslq 0x54(%r8), %rsi
cmpl %edi, %esi
jge 0x2ee14
cmpq $0x1, %rdi
adcq $0x0, %rdi
leaq 0x5811b(%rip), %rax     # 0x86f0b
movq %rax, (%rsp)
pushq $0x4
popq %rdx
pushq $0x28
popq %rcx
pushq $0x1
popq %r8
movq %rbp, %r9
callq 0xef4f
movq 0x18(%rsp), %r8
movl %eax, 0x54(%r8)
movzwl 0x18(%r8), %edi
movl 0x14(%rsp), %ebx
movq 0x90(%r8), %rax
imulq $0x28, %rdi, %rcx
leaq (%rax,%rcx), %r12
addq $-0x28, %r12
movq 0x40(%rsp), %rdi
movq %r12, %rsi
callq 0x2b607
movq 0x18(%rsp), %rsi
orb $-0x80, 0x1f(%r12)
orb $0x8, 0xb0(%rsi)
jmp 0x2ee8d
movl 0x1c(%r9), %eax
testl %eax, %eax
jns 0x2ee69
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subq %rax, %r12
movq %r12, %rdi
callq 0x45c0
movq 0x50(%rsp), %r9
movq 0x40(%rsp), %rdi
movq %r9, %rsi
movq %r9, %rbx
callq 0x2b607
orb $-0x80, 0x1f(%rbx)
movq 0x18(%rsp), %rsi
orb $0x8, 0xb0(%rsi)
movl 0x14(%rsp), %ebx
orb $0x4, 0xbc(%rsi)
xorl $0x1, %r15d
orl %ebx, %r15d
movl 0x28(%rsp), %eax
jne 0x2ef03
cmpl $0x1, %r13d
jne 0x2ef14
movq 0x20(%rsp), %rax
movslq (%rax), %r15
cmpq $-0x80000000, %r15      # imm = 0x80000000
je 0x2ef14
movq (%rsi), %r12
cmpq %r15, %r12
jl 0x2ef14
testb $0x1, 0x80f41(%rip)     # 0xafe08
jne 0x2ef14
movq %r14, %rdi
callq 0x27650
incq %r12
leaq 0x58030(%rip), %rsi     # 0x86f0b
leaq 0x580c0(%rip), %rdx     # 0x86fa2
pushq $0x3
popq %rdi
movq %r15, %rcx
movq %rax, %r8
movq %r12, %r9
xorl %eax, %eax
callq 0x8132
movq 0x18(%rsp), %rsi
movb $0x1, 0x80f07(%rip)     # 0xafe08
jmp 0x2ef14
testl %eax, %eax
sete %al
testl %ebx, %ebx
sete %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x2ef23
movq %r14, %rdi
movq %rsi, %rbx
callq 0x2a765
movq %rax, 0x8(%rbx)
xorl %r13d, %r13d
movl %r13d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %rdi
movq 0x18(%rsp), %rbx
movq %rbx, %rsi
callq 0x27650
movq (%rbx), %r9
incq %r9
leaq 0x57fb6(%rip), %rsi     # 0x86f0b
leaq 0x5801c(%rip), %rdx     # 0x86f78
pushq $0x1
popq %rdi
movl %r13d, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x8132
callq 0x4260