// File: /workspace/github_c_makefile_star2_O1/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, %r13
movq %rcx, 0x10(%rsp)
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
xorl %esi, %esi
callq 0x2e585
movl $0xffffffff, %r10d      # imm = 0xFFFFFFFF
testl %eax, %eax
js 0x41e3e
movl %eax, %ebx
cmpl (%r12), %eax
jge 0x41e3e
movq 0x10(%r12), %rax
movl %ebx, %ecx
shlq $0x4, %rcx
movq 0x8(%rax,%rcx), %rax
testq %rax, %rax
je 0x41e3e
movq 0x10(%rax), %rax
movl %eax, %ecx
notl %ecx
testb $0xf, %cl
je 0x41e3e
cmpb $0x47, (%r14)
jne 0x41abc
cmpb $0x54, 0x1(%r14)
jne 0x41abc
cmpb $0x0, 0x2(%r14)
je 0x41ba1
shrl $0x4, %eax
andl $0xf, %eax
movl $0xfffffffe, %r10d      # imm = 0xFFFFFFFE
cmpl %ebp, %eax
jne 0x41e3e
testb $0x8, 0xbc(%r15)
jne 0x41ae7
movq %r15, %rdi
movl $0x8, %esi
callq 0x38e9d
movq 0x18(%r15), %rcx
shrq $0x20, %rcx
movl %ecx, %eax
andl $0xff, %eax
je 0x41b18
movq 0x98(%r15), %rdx
movzbl %cl, %esi
xorl %ecx, %ecx
cmpl %ebx, (%rdx)
je 0x41b1a
incq %rcx
addq $0x20, %rdx
cmpq %rcx, %rsi
jne 0x41b04
movl %eax, %ecx
jmp 0x41b1a
xorl %ecx, %ecx
movl $0xfffffffd, %r10d      # imm = 0xFFFFFFFD
cmpl %eax, %ecx
je 0x41e3e
movq 0x98(%r15), %r14
movl %ecx, %eax
shlq $0x5, %rax
cmpq $0x0, 0x10(%r14,%rax)
je 0x41e3e
addq %rax, %r14
cmpl $0x3, %ebp
jne 0x41bba
movslq 0x4(%r14), %rax
movslq 0x8(%r12), %rcx
imulq %rax, %rcx
movq %r13, %r15
cmpl %ecx, (%r13)
movq 0x10(%rsp), %r13
jge 0x41b86
movq (%r13), %rdi
movq %rcx, %rsi
movq %rcx, %rbx
callq 0x4860
movq %rax, (%r13)
testq %rax, %rax
je 0x41ca5
movl %ebx, (%r15)
movq %rbx, %rcx
movq (%r13), %rdi
movq 0x10(%r14), %rsi
movslq %ecx, %rdx
movq %rcx, %rbx
callq 0x43c0
movq %rbx, %r10
jmp 0x41e3e
andl $0xf0, %eax
movl $0xfffffffe, %r10d      # imm = 0xFFFFFFFE
cmpl $0x30, %eax
je 0x41ad0
jmp 0x41e3e
movslq 0x8(%r12), %r10
movslq 0x4(%r14), %rsi
imulq %r10, %rsi
movq %r13, %rax
cmpl %esi, (%r13)
movq %r10, 0x8(%rsp)
movq 0x10(%rsp), %r13
jge 0x41bfb
movl %esi, (%rax)
movq (%r13), %rdi
shlq $0x2, %rsi
callq 0x4860
movq 0x8(%rsp), %r10
movq %rax, (%r13)
testq %rax, %rax
je 0x41ca5
movl 0xc(%r14), %ebx
leal -0x1(%rbx), %eax
cmpl $0x4, %eax
ja 0x41e50
leaq 0x6c382(%rip), %rcx     # 0xadf94
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
testl %r10d, %r10d
jle 0x41e39
movq 0x10(%r14), %rax
movq (%r13), %rcx
xorl %edx, %edx
cmpl $0x0, 0x4(%r14)
jle 0x41c7c
xorl %esi, %esi
movzbl (%rax,%rsi), %edi
cmpl $0x80, %edi
je 0x41c55
cmpl $0x81, %edi
jne 0x41c5c
movl $0x80000001, (%rcx)     # imm = 0x80000001
xorl %edi, %edi
jmp 0x41c69
movl $0x80000000, %edi       # imm = 0x80000000
jmp 0x41c60
movsbl %dil, %edi
movl %edi, (%rcx)
addq $0x4, %rcx
movb $0x1, %dil
testb %dil, %dil
je 0x41c8c
incq %rsi
movslq 0x4(%r14), %rdi
cmpq %rdi, %rsi
jl 0x41c37
jmp 0x41c8c
xorl %esi, %esi
jmp 0x41c8c
movl $0x80000001, (%rcx)     # imm = 0x80000001
addq $0x4, %rcx
incl %esi
cmpl 0x4(%r14), %esi
jl 0x41c80
movslq 0x8(%r14), %rsi
addq %rsi, %rax
incl %edx
cmpl %r10d, %edx
jne 0x41c2e
jmp 0x41e39
movl $0xfffffffc, %r10d      # imm = 0xFFFFFFFC
jmp 0x41e3e
testl %r10d, %r10d
jle 0x41e39
movq 0x10(%r14), %rax
movq (%r13), %rcx
xorl %edx, %edx
cmpl $0x0, 0x4(%r14)
jle 0x41cfb
xorl %esi, %esi
movl (%rax,%rsi,4), %edi
cmpl $0x80000001, %edi       # imm = 0x80000001
jne 0x41cdf
movl $0x80000001, (%rcx)     # imm = 0x80000001
jmp 0x41ce5
movl %edi, (%rcx)
addq $0x4, %rcx
cmpl $0x80000001, %edi       # imm = 0x80000001
je 0x41d0b
incq %rsi
movslq 0x4(%r14), %rdi
cmpq %rdi, %rsi
jl 0x41ccc
jmp 0x41d0b
xorl %esi, %esi
jmp 0x41d0b
movl $0x80000001, (%rcx)     # imm = 0x80000001
addq $0x4, %rcx
incl %esi
cmpl 0x4(%r14), %esi
jl 0x41cff
movslq 0x8(%r14), %rsi
addq %rsi, %rax
incl %edx
cmpl %r10d, %edx
jne 0x41cc3
jmp 0x41e39
testl %r10d, %r10d
jle 0x41e39
movq 0x10(%r14), %rax
movq (%r13), %rcx
movl 0x4(%r14), %edx
movl 0x8d7d1(%rip), %esi     # 0xcf510
movl 0x8d7cf(%rip), %edi     # 0xcf514
movslq 0x8(%r14), %r8
xorl %r9d, %r9d
testl %edx, %edx
jle 0x41d8b
movl 0x8d7bd(%rip), %r11d    # 0xcf514
xorl %r10d, %r10d
movl (%rax,%r10,4), %ebp
movl %esi, %ebx
cmpl %esi, %ebp
je 0x41d72
movl %ebp, %ebx
cmpl %r11d, %ebp
jne 0x41d72
movl %r11d, (%rcx)
xorl %ebx, %ebx
jmp 0x41d7a
movl %ebx, (%rcx)
addq $0x4, %rcx
movb $0x1, %bl
testb %bl, %bl
je 0x41d8e
incq %r10
cmpq %r10, %rdx
jne 0x41d5a
movl %edx, %r10d
jmp 0x41d8e
xorl %r10d, %r10d
cmpl %edx, %r10d
jge 0x41da4
movl %edx, %r11d
subl %r10d, %r11d
movl %edi, (%rcx)
addq $0x4, %rcx
decl %r11d
jne 0x41d99
addq %r8, %rax
incl %r9d
movq 0x8(%rsp), %r10
cmpl %r10d, %r9d
jne 0x41d4c
jmp 0x41e39
testl %r10d, %r10d
jle 0x41e39
movq 0x10(%r14), %rax
movq (%r13), %rcx
xorl %edx, %edx
cmpl $0x0, 0x4(%r14)
jle 0x41e15
xorl %esi, %esi
movzwl (%rax,%rsi,2), %edi
cmpl $0x8000, %edi           # imm = 0x8000
je 0x41def
cmpl $0x8001, %edi           # imm = 0x8001
jne 0x41df6
movl $0x80000001, (%rcx)     # imm = 0x80000001
xorl %edi, %edi
jmp 0x41e02
movl $0x80000000, %edi       # imm = 0x80000000
jmp 0x41df9
movswl %di, %edi
movl %edi, (%rcx)
addq $0x4, %rcx
movb $0x1, %dil
testb %dil, %dil
je 0x41e25
incq %rsi
movslq 0x4(%r14), %rdi
cmpq %rdi, %rsi
jl 0x41dd1
jmp 0x41e25
xorl %esi, %esi
jmp 0x41e25
movl $0x80000001, (%rcx)     # imm = 0x80000001
addq $0x4, %rcx
incl %esi
cmpl 0x4(%r14), %esi
jl 0x41e19
movslq 0x8(%r14), %rsi
addq %rsi, %rax
incl %edx
cmpl %r10d, %edx
jne 0x41dc8
imull 0x4(%r14), %r10d
movl %r10d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
movq %r15, %rsi
callq 0x32a62
movq (%r15), %r9
incq %r9
leaq 0x6d5ed(%rip), %rsi     # 0xaf455
leaq 0x6cfef(%rip), %rdx     # 0xaee5e
movl $0x1, %edi
movl %ebx, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x9774
movl $0x1, %edi
callq 0x45f0