// File: /workspace/github_c_makefile_star2_O3/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, %ebp
movq %r8, 0x10(%rsp)
movq %rcx, %r15
movq %rdx, %r13
movq %rsi, 0x8(%rsp)
movq %rdi, %r12
xorl %esi, %esi
callq 0x2d3d9
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x40f68
movl %eax, %r14d
cmpl (%r12), %eax
jge 0x40f68
movq 0x10(%r12), %rax
movl %r14d, %ecx
shlq $0x4, %rcx
movq 0x8(%rax,%rcx), %rax
testq %rax, %rax
je 0x40f68
movq 0x10(%rax), %rax
movl %eax, %ecx
notl %ecx
testb $0xf, %cl
je 0x40f68
cmpb $0x47, (%r13)
jne 0x40beb
cmpb $0x54, 0x1(%r13)
jne 0x40beb
cmpb $0x0, 0x2(%r13)
je 0x40cd0
shrl $0x4, %eax
andl $0xf, %eax
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
cmpl %ebp, %eax
jne 0x40f68
movq 0x8(%rsp), %r13
testb $0x8, 0xbc(%r13)
jne 0x40c1a
movq %r13, %rdi
movl $0x8, %esi
callq 0x38183
movq 0x18(%r13), %rcx
shrq $0x20, %rcx
movl %ecx, %eax
andl $0xff, %eax
je 0x40c52
movq 0x98(%r13), %rdx
movzbl %cl, %esi
xorl %ecx, %ecx
cmpl %r14d, (%rdx)
je 0x40c56
incq %rcx
addq $0x20, %rdx
movl $0xfffffffd, %ebx       # imm = 0xFFFFFFFD
cmpq %rcx, %rsi
jne 0x40c37
jmp 0x40f68
xorl %ecx, %ecx
jmp 0x40c5b
movq 0x8(%rsp), %r13
movl $0xfffffffd, %ebx       # imm = 0xFFFFFFFD
cmpl %eax, %ecx
je 0x40f68
movq 0x98(%r13), %r13
movl %ecx, %eax
shlq $0x5, %rax
movq 0x10(%r13,%rax), %rsi
testq %rsi, %rsi
je 0x40f68
addq %rax, %r13
cmpl $0x3, %ebp
jne 0x40ce8
movslq 0x4(%r13), %rax
movslq 0x8(%r12), %rbx
imulq %rax, %rbx
movq (%r15), %rdi
movq 0x10(%rsp), %r14
cmpl %ebx, (%r14)
jge 0x40cc3
movq %rbx, %rsi
callq 0x4860
movq %rax, (%r15)
testq %rax, %rax
je 0x40dc8
movq %rax, %rdi
movl %ebx, (%r14)
movq 0x10(%r13), %rsi
movq %rbx, %rdx
callq 0x43c0
jmp 0x40f68
andl $0xf0, %eax
movl $0xfffffffe, %ebx       # imm = 0xFFFFFFFE
cmpl $0x30, %eax
je 0x40bfe
jmp 0x40f68
movslq 0x8(%r12), %r14
movslq 0x4(%r13), %rsi
imulq %r14, %rsi
movq 0x10(%rsp), %rax
cmpl %esi, (%rax)
jge 0x40d18
movl %esi, (%rax)
movq (%r15), %rdi
shlq $0x2, %rsi
callq 0x4860
movq %rax, (%r15)
testq %rax, %rax
je 0x40dc8
movl 0xc(%r13), %ebx
leal -0x1(%rbx), %eax
cmpl $0x4, %eax
ja 0x40f79
leaq 0x6a211(%rip), %rcx     # 0xaaf40
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x4(%r13), %ebx
testl %r14d, %r14d
jle 0x40f64
movq 0x10(%r13), %rax
movq (%r15), %rcx
xorl %edx, %edx
testl %ebx, %ebx
jle 0x40d8d
xorl %edi, %edi
xorl %esi, %esi
movzbl (%rax,%rsi), %r8d
movl $0x80000000, %r9d       # imm = 0x80000000
cmpl $0x80, %r8d
je 0x40d77
cmpl $0x81, %r8d
je 0x40d91
movsbl %r8b, %r9d
movl %r9d, (%rcx,%rsi,4)
incq %rsi
movslq 0x4(%r13), %rbx
addq $0x4, %rdi
cmpq %rbx, %rsi
jl 0x40d56
jmp 0x40d9c
xorl %esi, %esi
jmp 0x40db1
movl $0x80000001, (%rcx,%rsi,4) # imm = 0x80000001
movl 0x4(%r13), %ebx
addq %rdi, %rcx
jmp 0x40db1
movl $0x80000001, (%rcx)     # imm = 0x80000001
addq $0x4, %rcx
incl %esi
movl 0x4(%r13), %ebx
cmpl %ebx, %esi
jl 0x40da1
movslq 0x8(%r13), %rsi
addq %rsi, %rax
incl %edx
cmpl %r14d, %edx
jne 0x40d4e
jmp 0x40f64
movl $0xfffffffc, %ebx       # imm = 0xFFFFFFFC
jmp 0x40f68
movl 0x4(%r13), %ebx
testl %r14d, %r14d
jle 0x40f64
movq 0x10(%r13), %rax
movq (%r15), %rcx
xorl %edx, %edx
testl %ebx, %ebx
jle 0x40e13
xorl %edi, %edi
xorl %esi, %esi
movl (%rax,%rsi,4), %r8d
cmpl $0x80000001, %r8d       # imm = 0x80000001
je 0x40e17
movl %r8d, (%rcx,%rsi,4)
incq %rsi
movslq 0x4(%r13), %rbx
addq $0x4, %rdi
cmpq %rbx, %rsi
jl 0x40df0
jmp 0x40e22
xorl %esi, %esi
jmp 0x40e37
movl $0x80000001, (%rcx,%rsi,4) # imm = 0x80000001
movl 0x4(%r13), %ebx
addq %rdi, %rcx
jmp 0x40e37
movl $0x80000001, (%rcx)     # imm = 0x80000001
addq $0x4, %rcx
incl %esi
movl 0x4(%r13), %ebx
cmpl %ebx, %esi
jl 0x40e27
movslq 0x8(%r13), %rsi
addq %rsi, %rax
incl %edx
cmpl %r14d, %edx
jne 0x40de8
jmp 0x40f64
movl 0x4(%r13), %ebx
testl %r14d, %r14d
jle 0x40f64
movq 0x10(%r13), %rax
movq (%r15), %rcx
movl 0x8c6a8(%rip), %edx     # 0xcd510
movl 0x8c6a6(%rip), %esi     # 0xcd514
movslq 0x8(%r13), %rdi
xorl %r8d, %r8d
testl %ebx, %ebx
jle 0x40eae
movl 0x8c694(%rip), %r11d    # 0xcd514
xorl %r10d, %r10d
xorl %r9d, %r9d
movl (%rax,%r9,4), %r15d
movl %edx, %ebp
cmpl %edx, %r15d
je 0x40e99
movl %r15d, %ebp
cmpl %r11d, %r15d
je 0x40eb3
movl %ebp, (%rcx,%r9,4)
incq %r9
addq $-0x4, %r10
cmpq %r9, %rbx
jne 0x40e86
subq %r10, %rcx
jmp 0x40ecd
xorl %r9d, %r9d
jmp 0x40eba
movl %r11d, (%rcx,%r9,4)
subq %r10, %rcx
movl %ebx, %r10d
subl %r9d, %r10d
jle 0x40ecd
movl %esi, (%rcx)
addq $0x4, %rcx
decl %r10d
jne 0x40ec2
addq %rdi, %rax
incl %r8d
cmpl %r14d, %r8d
jne 0x40e75
jmp 0x40f64
movl 0x4(%r13), %ebx
testl %r14d, %r14d
jle 0x40f64
movq 0x10(%r13), %rax
movq (%r15), %rcx
xorl %edx, %edx
testl %ebx, %ebx
jle 0x40f2e
xorl %edi, %edi
xorl %esi, %esi
movzwl (%rax,%rsi,2), %r8d
movl $0x80000000, %r9d       # imm = 0x80000000
cmpl $0x8000, %r8d           # imm = 0x8000
je 0x40f18
cmpl $0x8001, %r8d           # imm = 0x8001
je 0x40f32
movswl %r8w, %r9d
movl %r9d, (%rcx,%rsi,4)
incq %rsi
movslq 0x4(%r13), %rbx
addq $0x4, %rdi
cmpq %rbx, %rsi
jl 0x40ef7
jmp 0x40f3d
xorl %esi, %esi
jmp 0x40f52
movl $0x80000001, (%rcx,%rsi,4) # imm = 0x80000001
movl 0x4(%r13), %ebx
addq %rdi, %rcx
jmp 0x40f52
movl $0x80000001, (%rcx)     # imm = 0x80000001
addq $0x4, %rcx
incl %esi
movl 0x4(%r13), %ebx
cmpl %ebx, %esi
jl 0x40f42
movslq 0x8(%r13), %rsi
addq %rsi, %rax
incl %edx
cmpl %r14d, %edx
jne 0x40eef
imull %r14d, %ebx
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
movq 0x8(%rsp), %r14
movq %r14, %rsi
callq 0x318ad
movq (%r14), %r9
incq %r9
leaq 0x6b46f(%rip), %rsi     # 0xac405
leaq 0x6ae71(%rip), %rdx     # 0xabe0e
movl $0x1, %edi
movl %ebx, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x942d
movl $0x1, %edi
callq 0x45f0