// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/vcf.c
// Function: bcf_get_format_values
int bcf_get_format_values(const bcf_hdr_t *hdr, bcf1_t *line, const char *tag, void **dst, int *ndst, int type)
{
    int i,j, tag_id = bcf_hdr_id2int(hdr, BCF_DT_ID, tag);
    if ( !bcf_hdr_idinfo_exists(hdr,BCF_HL_FMT,tag_id) ) return -1;    // no such FORMAT field in the header
    if ( tag[0]=='G' && tag[1]=='T' && tag[2]==0 )
    {
        // Ugly: GT field is considered to be a string by the VCF header but BCF represents it as INT.
        if ( bcf_hdr_id2type(hdr,BCF_HL_FMT,tag_id)!=BCF_HT_STR ) return -2;
    }
    else if ( bcf_hdr_id2type(hdr,BCF_HL_FMT,tag_id)!=type ) return -2;     // expected different type

    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==tag_id ) break;
    if ( i==line->n_fmt ) return -3;                               // the tag is not present in this record
    bcf_fmt_t *fmt = &line->d.fmt[i];
    if ( !fmt->p ) return -3;                                      // the tag was marked for removal

    if ( type==BCF_HT_STR )
    {
        int n = fmt->n*bcf_hdr_nsamples(hdr);
        if ( *ndst < n )
        {
            *dst  = realloc(*dst, n);
            if ( !*dst ) return -4;     // could not alloc
            *ndst = n;
        }
        memcpy(*dst,fmt->p,n);
        return n;
    }

    // Make sure the buffer is big enough
    int nsmpl = bcf_hdr_nsamples(hdr);
    int size1 = type==BCF_HT_INT ? sizeof(int32_t) : sizeof(float);
    if ( *ndst < fmt->n*nsmpl )
    {
        *ndst = fmt->n*nsmpl;
        *dst  = realloc(*dst, *ndst*size1);
        if ( !*dst ) return -4;     // could not alloc
    }

    #define BRANCH(type_t, convert, is_missing, is_vector_end, set_missing, set_vector_end, set_regular, out_type_t) { \
        out_type_t *tmp = (out_type_t *) *dst; \
        uint8_t *fmt_p = fmt->p; \
        for (i=0; i<nsmpl; i++) \
        { \
            for (j=0; j<fmt->n; j++) \
            { \
                type_t p = convert(fmt_p + j * sizeof(type_t)); \
                if ( is_missing ) set_missing; \
                else if ( is_vector_end ) { set_vector_end; break; } \
                else set_regular; \
                tmp++; \
            } \
            for (; j<fmt->n; j++) { set_vector_end; tmp++; } \
            fmt_p += fmt->size; \
        } \
    }
    switch (fmt->type) {
        case BCF_BT_INT8:  BRANCH(int8_t,  le_to_i8, p==bcf_int8_missing,  p==bcf_int8_vector_end,  *tmp=bcf_int32_missing, *tmp=bcf_int32_vector_end, *tmp=p, int32_t); break;
        case BCF_BT_INT16: BRANCH(int16_t, le_to_i16, p==bcf_int16_missing, p==bcf_int16_vector_end, *tmp=bcf_int32_missing, *tmp=bcf_int32_vector_end, *tmp=p, int32_t); break;
        case BCF_BT_INT32: BRANCH(int32_t, le_to_i32, p==bcf_int32_missing, p==bcf_int32_vector_end, *tmp=bcf_int32_missing, *tmp=bcf_int32_vector_end, *tmp=p, int32_t); break;
        case BCF_BT_FLOAT: BRANCH(uint32_t, le_to_u32, p==bcf_float_missing, p==bcf_float_vector_end, bcf_float_set_missing(*tmp), bcf_float_set_vector_end(*tmp), bcf_float_set(tmp, p), float); break;
        default: hts_log_error("Unexpected type %d at %s:%"PRIhts_pos, fmt->type, bcf_seqname_safe(hdr,line), line->pos+1); exit(1);
    }
    #undef BRANCH
    return nsmpl*fmt->n;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r9d, %r13d
movq %r8, 0x10(%rsp)
movq %rcx, 0x8(%rsp)
movq %rdx, %r12
movq %rsi, %r14
movq %rdi, %r15
xorl %esi, %esi
callq 0x2489c
pushq $-0x1
popq %rbp
testl %eax, %eax
js 0x307e5
movl %eax, %ebx
cmpl (%r15), %eax
jge 0x307e5
movq 0x10(%r15), %rax
movl %ebx, %ecx
shlq $0x4, %rcx
movq 0x8(%rax,%rcx), %rax
testq %rax, %rax
je 0x307e5
movq 0x10(%rax), %rax
movl %eax, %ecx
notl %ecx
testb $0xf, %cl
je 0x307e5
cmpb $0x47, (%r12)
pushq $-0x2
popq %rbp
jne 0x30488
cmpb $0x54, 0x1(%r12)
jne 0x30488
cmpb $0x0, 0x2(%r12)
je 0x30555
shrl $0x4, %eax
andl $0xf, %eax
cmpl %r13d, %eax
jne 0x307e5
testb $0x8, 0xbc(%r14)
jne 0x304ac
pushq $0x8
popq %rsi
movq %r14, %rdi
callq 0x2b198
movzbl 0x1c(%r14), %eax
movl %eax, %ecx
shll $0x5, %ecx
xorl %r12d, %r12d
pushq $-0x3
popq %rbp
cmpq %r12, %rcx
je 0x307e5
movq 0x98(%r14), %rdx
cmpl %ebx, (%rdx,%r12)
je 0x304d8
addq $0x20, %r12
jmp 0x304bc
shll $0x5, %eax
cmpl %r12d, %eax
je 0x307e5
movq 0x98(%r14), %rbx
movq 0x10(%rbx,%r12), %rsi
testq %rsi, %rsi
je 0x307e5
pushq $-0x4
popq %rbp
cmpl $0x3, %r13d
jne 0x30568
movslq 0x4(%rbx,%r12), %rax
movslq 0x8(%r15), %r14
imulq %rax, %r14
movq 0x8(%rsp), %r15
movq (%r15), %rdi
movq 0x10(%rsp), %rax
cmpl %r14d, (%rax)
jge 0x30545
movq %r14, %rsi
callq 0x4860
movq %rax, (%r15)
testq %rax, %rax
je 0x307e5
movq %rax, %rdi
movq 0x10(%rsp), %rax
movl %r14d, (%rax)
movq 0x10(%rbx,%r12), %rsi
movq %r14, %rdx
callq 0x43c0
movl %r14d, %ebp
jmp 0x307e5
andl $0xf0, %eax
cmpl $0x30, %eax
je 0x30497
jmp 0x307e5
movslq 0x8(%r15), %r13
movslq 0x4(%rbx,%r12), %rsi
imulq %r13, %rsi
movq 0x10(%rsp), %rax
cmpl %esi, (%rax)
jge 0x305a7
movq 0x10(%rsp), %rax
movl %esi, (%rax)
movq 0x8(%rsp), %rax
movq (%rax), %rdi
shlq $0x2, %rsi
callq 0x4860
movq 0x8(%rsp), %rcx
movq %rax, (%rcx)
testq %rax, %rax
je 0x307e5
movq %r13, %rsi
movl 0xc(%rbx,%r12), %r13d
leal -0x1(%r13), %eax
cmpl $0x4, %eax
ja 0x307f6
leaq 0x556c5(%rip), %rcx     # 0x85c88
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rbx,%r12), %rcx
xorl %edx, %edx
movq %rsi, %r15
testl %r15d, %r15d
movl $0x0, %esi
cmovgl %r15d, %esi
cmpl %esi, %edx
je 0x307dc
xorl %edi, %edi
movslq 0x4(%rbx,%r12), %r8
cmpq %r8, %rdi
jge 0x3063f
movzbl (%rcx,%rdi), %r8d
movl $0x80000000, %r9d       # imm = 0x80000000
cmpl $0x80, %r8d
je 0x3061f
cmpl $0x81, %r8d
je 0x3062b
movsbl %r8b, %r9d
movl %r9d, (%rax)
addq $0x4, %rax
incq %rdi
jmp 0x305f4
movl $0x80000001, (%rax)     # imm = 0x80000001
jmp 0x3063f
movl $0x80000001, (%rax)     # imm = 0x80000001
addq $0x4, %rax
incl %edi
cmpl 0x4(%rbx,%r12), %edi
jl 0x30633
movslq 0x8(%rbx,%r12), %rdi
addq %rdi, %rcx
incl %edx
jmp 0x305ea
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rbx,%r12), %rcx
xorl %edx, %edx
movq %rsi, %r15
testl %r15d, %r15d
movl $0x0, %esi
cmovgl %r15d, %esi
cmpl %esi, %edx
je 0x307dc
xorl %edi, %edi
movslq 0x4(%rbx,%r12), %r8
cmpq %r8, %rdi
jge 0x306b1
movl (%rcx,%rdi,4), %r8d
cmpl $0x80000001, %r8d       # imm = 0x80000001
je 0x3069d
movl %r8d, (%rax)
addq $0x4, %rax
incq %rdi
jmp 0x3067a
movl $0x80000001, (%rax)     # imm = 0x80000001
jmp 0x306b1
movl $0x80000001, (%rax)     # imm = 0x80000001
addq $0x4, %rax
incl %edi
cmpl 0x4(%rbx,%r12), %edi
jl 0x306a5
movslq 0x8(%rbx,%r12), %rdi
addq %rdi, %rcx
incl %edx
jmp 0x30670
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rbx,%r12), %rcx
xorl %edx, %edx
movq %rsi, %r15
testl %r15d, %r15d
movl $0x0, %esi
cmovgl %r15d, %esi
cmpl %esi, %edx
je 0x307dc
movl 0x4(%rbx,%r12), %edi
movl 0x7ee1a(%rip), %r10d    # 0xaf510
movl 0x7ee17(%rip), %r9d     # 0xaf514
testl %edi, %edi
movl $0x0, %r8d
cmovgl %edi, %r8d
xorl %r11d, %r11d
cmpq %r11, %r8
je 0x30736
movl (%rcx,%r11,4), %r14d
movl %r10d, %ebp
cmpl %r10d, %r14d
je 0x30725
movl %r14d, %ebp
cmpl %r9d, %r14d
je 0x30730
movl %ebp, (%rax)
addq $0x4, %rax
incq %r11
jmp 0x3070c
movl %r9d, (%rax)
movl %r11d, %r8d
movl 0x7edd7(%rip), %r9d     # 0xaf514
cmpl %edi, %r8d
jge 0x3074e
movl %r9d, (%rax)
addq $0x4, %rax
incl %r8d
jmp 0x3073d
movslq 0x8(%rbx,%r12), %rdi
addq %rdi, %rcx
incl %edx
jmp 0x306e2
movq 0x8(%rsp), %rax
movq (%rax), %rax
movq 0x10(%rbx,%r12), %rcx
xorl %edx, %edx
movq %rsi, %r15
testl %r15d, %r15d
movl $0x0, %esi
cmovgl %r15d, %esi
cmpl %esi, %edx
je 0x307dc
xorl %edi, %edi
movslq 0x4(%rbx,%r12), %r8
cmpq %r8, %rdi
jge 0x307c9
movzwl (%rcx,%rdi,2), %r8d
movl $0x80000000, %r9d       # imm = 0x80000000
cmpl $0x8000, %r8d           # imm = 0x8000
je 0x307a9
cmpl $0x8001, %r8d           # imm = 0x8001
je 0x307b5
movswl %r8w, %r9d
movl %r9d, (%rax)
addq $0x4, %rax
incq %rdi
jmp 0x3077e
movl $0x80000001, (%rax)     # imm = 0x80000001
jmp 0x307c9
movl $0x80000001, (%rax)     # imm = 0x80000001
addq $0x4, %rax
incl %edi
cmpl 0x4(%rbx,%r12), %edi
jl 0x307bd
movslq 0x8(%rbx,%r12), %rdi
addq %rdi, %rcx
incl %edx
jmp 0x30778
imull 0x4(%rbx,%r12), %r15d
movl %r15d, %ebp
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
movq %r14, %rsi
callq 0x27650
movq (%r14), %r9
incq %r9
leaq 0x56953(%rip), %rsi     # 0x87161
leaq 0x56352(%rip), %rdx     # 0x86b67
pushq $0x1
popq %rbp
movl %ebp, %edi
movl %r13d, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x8132
movl %ebp, %edi
callq 0x45f0