// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/vcf.c
// Function: bcf_update_format
int bcf_update_format(const bcf_hdr_t *hdr, bcf1_t *line, const char *key, const void *values, int n, int type)
{
    // Is the field already present?
    int i, fmt_id = bcf_hdr_id2int(hdr,BCF_DT_ID,key);
    int is_len = 0;
    if ( !bcf_hdr_idinfo_exists(hdr,BCF_HL_FMT,fmt_id) )
    {
        if ( !n ) return 0;
        return -1;  // the key not present in the header
    }

    if ( !(line->unpacked & BCF_UN_FMT) ) bcf_unpack(line, BCF_UN_FMT);

    for (i=0; i<line->n_fmt; i++)
        if ( line->d.fmt[i].id==fmt_id ) break;
    bcf_fmt_t *fmt = i==line->n_fmt ? NULL : &line->d.fmt[i];

    is_len = strcmp(key, "LEN") == 0;
    if ( !n )
    {
        if ( fmt )
        {
            // Mark the tag for removal, free existing memory if necessary
            if ( fmt->p_free )
            {
                free(fmt->p - fmt->p_off);
                fmt->p_free = 0;
            }
            line->d.indiv_dirty = 1;
            fmt->p = NULL;
        }
        if (is_len) {
            line->rlen = get_rlen(hdr, line);
        }
        return 0;
    }

    line->n_sample = bcf_hdr_nsamples(hdr);
    int nps = n / line->n_sample;  // number of values per sample
    assert( nps && nps*line->n_sample==n );     // must be divisible by n_sample

    // Encode the values and determine the size required to accommodate the values
    kstring_t str = {0,0,0};
    bcf_enc_int1(&str, fmt_id);
    assert(values != NULL);
    if ( type==BCF_HT_INT )
        bcf_enc_vint(&str, n, (int32_t*)values, nps);
    else if ( type==BCF_HT_REAL )
    {
        bcf_enc_size(&str, nps, BCF_BT_FLOAT);
        serialize_float_array(&str, nps*line->n_sample, (float *) values);
    }
    else if ( type==BCF_HT_STR )
    {
        bcf_enc_size(&str, nps, BCF_BT_CHAR);
        kputsn((char*)values, nps*line->n_sample, &str);
    }
    else
    {
        hts_log_error("The type %d not implemented yet at %s:%"PRIhts_pos, type, bcf_seqname_safe(hdr,line), line->pos+1);
        abort();
    }

    if ( !fmt )
    {
        // Not present, new format field
        line->n_fmt++;
        hts_expand0(bcf_fmt_t, line->n_fmt, line->d.m_fmt, line->d.fmt);

        // Special case: VCF specification requires that GT is always first
        if ( line->n_fmt > 1 && key[0]=='G' && key[1]=='T' && !key[2] )
        {
            for (i=line->n_fmt-1; i>0; i--)
                line->d.fmt[i] = line->d.fmt[i-1];
            fmt = &line->d.fmt[0];
        }
        else
            fmt = &line->d.fmt[line->n_fmt-1];
        bcf_unpack_fmt_core1((uint8_t*)str.s, line->n_sample, fmt);
        line->d.indiv_dirty = 1;
        fmt->p_free = 1;
    }
    else
    {
        // The tag is already present, check if it is big enough to accommodate the new block
        if ( fmt->p && str.l <= fmt->p_len + fmt->p_off )
        {
            // good, the block is big enough
            if ( str.l != fmt->p_len + fmt->p_off ) line->d.indiv_dirty = 1;
            uint8_t *ptr = fmt->p - fmt->p_off;
            memcpy(ptr, str.s, str.l);
            free(str.s);
            int p_free = fmt->p_free;
            bcf_unpack_fmt_core1(ptr, line->n_sample, fmt);
            fmt->p_free = p_free;
        }
        else
        {
            if ( fmt->p_free )
                free(fmt->p - fmt->p_off);
            bcf_unpack_fmt_core1((uint8_t*)str.s, line->n_sample, fmt);
            fmt->p_free = 1;
            line->d.indiv_dirty = 1;
        }
    }
    line->unpacked |= BCF_UN_FMT;

    if (is_len) {
        line->rlen = get_rlen(hdr, line);
    }
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %r9d, %r14d
movl %r8d, %ebx
movq %rcx, %r13
movq %rdx, %r15
movq %rsi, 0x8(%rsp)
movq %rdi, %rbp
xorl %r12d, %r12d
xorl %esi, %esi
callq 0x2489c
testl %eax, %eax
js 0x2f0e2
movq %rbp, %rdx
movl %eax, %ebp
cmpl (%rdx), %eax
jge 0x2f0e2
movq 0x10(%rdx), %rax
movl %ebp, %ecx
shlq $0x4, %rcx
movq 0x8(%rax,%rcx), %rax
testq %rax, %rax
je 0x2f0e2
movl 0x10(%rax), %eax
notl %eax
testb $0xf, %al
jne 0x2f0f9
negl %ebx
sbbl %r12d, %r12d
movl %r12d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdx, 0x18(%rsp)
movq 0x8(%rsp), %r12
testb $0x8, 0xbc(%r12)
jne 0x2f119
pushq $0x8
popq %rsi
movq %r12, %rdi
callq 0x2b198
movq %r12, %rax
addq $0x98, %r12
movq 0x18(%rax), %rax
movq %rax, 0x10(%rsp)
shrq $0x20, %rax
movzbl %al, %eax
movl %eax, %edx
shll $0x5, %edx
movq $0x0, 0x20(%rsp)
xorl %ecx, %ecx
cmpq %rcx, %rdx
je 0x2f172
movq (%r12), %rsi
cmpl %ebp, (%rsi,%rcx)
je 0x2f157
addq $0x20, %rcx
jmp 0x2f143
shll $0x5, %eax
cmpl %ecx, %eax
jne 0x2f169
movq $0x0, 0x20(%rsp)
jmp 0x2f172
addq (%r12), %rcx
movq %rcx, 0x20(%rsp)
leaq 0x57d8e(%rip), %rsi     # 0x86f07
movq %r15, %rdi
callq 0x46e0
movl %eax, %ecx
testl %ebx, %ebx
je 0x2f233
movl %ecx, 0x2c(%rsp)
movq 0x18(%rsp), %rax
movl 0x8(%rax), %eax
movl %eax, %ecx
andl $0xffffff, %ecx         # imm = 0xFFFFFF
shlq $0x28, %rax
movabsq $0xffffffffff, %rdx     # imm = 0xFFFFFFFFFF
movq 0x10(%rsp), %rsi
andq %rdx, %rsi
orq %rax, %rsi
movq 0x8(%rsp), %rax
movq %rsi, 0x18(%rax)
movl %ebx, %eax
cltd
idivl %ecx
testl %eax, %eax
je 0x2f546
imull %eax, %ecx
cmpl %ebx, %ecx
jne 0x2f546
movl %eax, 0x10(%rsp)
xorps %xmm0, %xmm0
leaq 0x30(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movl %ebp, %esi
callq 0x28086
testq %r13, %r13
je 0x2f565
cmpl $0x3, %r14d
je 0x2f2d4
cmpl $0x2, %r14d
je 0x2f29e
cmpl $0x1, %r14d
jne 0x2f584
leaq 0x30(%rsp), %rdi
movl %ebx, %esi
movq %r13, %rdx
movl 0x10(%rsp), %ecx
callq 0x27d4a
jmp 0x2f308
movq 0x20(%rsp), %r15
testq %r15, %r15
movq 0x18(%rsp), %rdi
je 0x2f27d
movl 0x1c(%r15), %eax
testl %eax, %eax
jns 0x2f269
movq 0x10(%r15), %rdi
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subq %rax, %rdi
movl %ecx, %ebx
callq 0x45c0
movq 0x18(%rsp), %rdi
movl %ebx, %ecx
andb $0x7f, 0x1f(%r15)
movq 0x8(%rsp), %rax
movl $0x1, 0xb4(%rax)
andq $0x0, 0x10(%r15)
xorl %r12d, %r12d
testl %ecx, %ecx
jne 0x2f0e7
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x2a765
movq %rax, 0x8(%rbx)
jmp 0x2f0e7
leaq 0x30(%rsp), %rbx
pushq $0x5
popq %rdx
movq %rbx, %rdi
movl 0x10(%rsp), %ebp
movl %ebp, %esi
callq 0x27feb
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
shrq $0x28, %rax
imull %eax, %ebp
movslq %ebp, %rsi
movq %rbx, %rdi
movq %r13, %rdx
callq 0x281bb
jmp 0x2f308
leaq 0x30(%rsp), %rbx
pushq $0x7
popq %rdx
movq %rbx, %rdi
movl 0x10(%rsp), %ebp
movl %ebp, %esi
callq 0x27feb
movq 0x8(%rsp), %rax
movq 0x18(%rax), %rax
shrq $0x28, %rax
imull %eax, %ebp
movslq %ebp, %rsi
movq %r13, %rdi
movq %rbx, %rdx
callq 0x2787b
movq 0x20(%rsp), %r13
testq %r13, %r13
je 0x2f3ad
movq 0x10(%r13), %rbx
testq %rbx, %rbx
je 0x2f493
movq 0x30(%rsp), %rdx
movl 0x1c(%r13), %eax
movl %eax, %ecx
andl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
movl 0x18(%r13), %esi
addl %ecx, %esi
cmpq %rsi, %rdx
movq 0x8(%rsp), %r12
ja 0x2f49c
je 0x2f35f
movl $0x1, 0xb4(%r12)
movl $0x7fffffff, %ecx       # imm = 0x7FFFFFFF
andl 0x1c(%r13), %ecx
movl %ecx, %eax
subq %rax, %rbx
movq 0x40(%rsp), %r15
movq %rbx, %rdi
movq %r15, %rsi
callq 0x43c0
movq %r15, %rdi
callq 0x45c0
movl $0x80000000, %ebp       # imm = 0x80000000
andl 0x1c(%r13), %ebp
movq 0x18(%r12), %rsi
shrq $0x28, %rsi
movq %rbx, %rdi
movq %r13, %rdx
callq 0x2635c
movl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
andl 0x1c(%r13), %eax
orl %ebp, %eax
movl %eax, 0x1c(%r13)
jmp 0x2f4d7
movq 0x8(%rsp), %rdi
movq 0x18(%rdi), %rax
movabsq $0x100000000, %rcx      # imm = 0x100000000
addq %rax, %rcx
movabsq $0xff00000000, %rdx     # imm = 0xFF00000000
andq %rcx, %rdx
movabsq $-0xff00000001, %rsi    # imm = 0xFFFFFF00FFFFFFFF
andq %rax, %rsi
orq %rdx, %rsi
movq %rsi, 0x18(%rdi)
shrq $0x20, %rcx
movzbl %cl, %edx
movslq 0x50(%rdi), %rax
cmpl %eax, %edx
jle 0x2f42b
testl %edx, %edx
movzbl %cl, %ecx
pushq $0x1
popq %rdi
cmovneq %rcx, %rdi
leaq 0x57c4c(%rip), %rcx     # 0x87052
movq %rcx, (%rsp)
pushq $0x4
popq %rdx
pushq $0x20
popq %rcx
pushq $0x1
popq %r8
movq %rax, %rsi
movq %r12, %r9
callq 0xef4f
movq 0x8(%rsp), %rcx
movl %eax, 0x50(%rcx)
movq 0x18(%rcx), %rsi
movq %rsi, %rax
shrq $0x20, %rax
movabsq $0xfe00000000, %rcx     # imm = 0xFE00000000
testq %rcx, %rsi
je 0x2f459
cmpb $0x47, (%r15)
jne 0x2f459
cmpb $0x54, 0x1(%r15)
jne 0x2f459
cmpb $0x0, 0x2(%r15)
je 0x2f501
movq (%r12), %rcx
movzbl %al, %eax
shll $0x5, %eax
leaq (%rcx,%rax), %rbx
addq $-0x20, %rbx
movq 0x8(%rsp), %r12
movq 0x40(%rsp), %rdi
shrq $0x28, %rsi
movq %rbx, %rdx
callq 0x2635c
movl $0x1, 0xb4(%r12)
orb $-0x80, 0x1f(%rbx)
jmp 0x2f4d7
movl 0x1c(%r13), %eax
movq 0x8(%rsp), %r12
testl %eax, %eax
jns 0x2f4b0
andl $0x7fffffff, %eax       # imm = 0x7FFFFFFF
subq %rax, %rbx
movq %rbx, %rdi
callq 0x45c0
movq 0x40(%rsp), %rdi
movq 0x18(%r12), %rsi
shrq $0x28, %rsi
movq %r13, %rdx
callq 0x2635c
orb $-0x80, 0x1f(%r13)
movl $0x1, 0xb4(%r12)
orb $0x8, 0xbc(%r12)
cmpl $0x0, 0x2c(%rsp)
movq 0x18(%rsp), %rdi
jne 0x2f4f9
movq %r12, %rsi
callq 0x2a765
movq %rax, 0x8(%r12)
xorl %r12d, %r12d
jmp 0x2f0e7
movzbl %al, %eax
movl %eax, %ecx
shll $0x5, %ecx
addq $-0x20, %rcx
cmpq $0x2, %rax
jl 0x2f52f
decq %rax
movq (%r12), %rdx
movups -0x20(%rdx,%rcx), %xmm0
movups -0x10(%rdx,%rcx), %xmm1
movups %xmm1, 0x10(%rdx,%rcx)
movups %xmm0, (%rdx,%rcx)
jmp 0x2f509
movq 0x8(%rsp), %r12
movq 0x18(%r12), %rsi
movq 0x98(%r12), %rbx
jmp 0x2f470
leaq 0x57a80(%rip), %rdi     # 0x86fcd
leaq 0x56dcf(%rip), %rsi     # 0x86323
leaq 0x57a8f(%rip), %rcx     # 0x86fea
movl $0x157a, %edx           # imm = 0x157A
callq 0x42e0
leaq 0x57ad7(%rip), %rdi     # 0x87043
leaq 0x56db0(%rip), %rsi     # 0x86323
leaq 0x57a70(%rip), %rcx     # 0x86fea
movl $0x157f, %edx           # imm = 0x157F
callq 0x42e0
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x27650
movq (%rbx), %r9
incq %r9
leaq 0x57aaf(%rip), %rsi     # 0x87052
leaq 0x579ce(%rip), %rdx     # 0x86f78
pushq $0x1
popq %rdi
movl %r14d, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x8132
callq 0x4260