// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/vcfutils.c
// Function: bcf_calc_ac
int bcf_calc_ac(const bcf_hdr_t *header, bcf1_t *line, int *ac, int which)
{
    int i;
    for (i=0; i<line->n_allele; i++) ac[i]=0;

    // Use INFO/AC,AN field only when asked
    if ( which&BCF_UN_INFO )
    {
        bcf_unpack(line, BCF_UN_INFO);
        int an_id = bcf_hdr_id2int(header, BCF_DT_ID, "AN");
        int ac_id = bcf_hdr_id2int(header, BCF_DT_ID, "AC");
        int i, an=-1, ac_len=0, ac_type=0;
        uint8_t *ac_ptr=NULL;
        if ( an_id>=0 && ac_id>=0 )
        {
            for (i=0; i<line->n_info; i++)
            {
                bcf_info_t *z = &line->d.info[i];
                if ( z->key == an_id ) an = z->v1.i;
                else if ( z->key == ac_id ) { ac_ptr = z->vptr; ac_len = z->len; ac_type = z->type; }
            }
        }
        if ( an>=0 && ac_ptr )
        {
            if ( ac_len != line->n_allele - 1 )
            {
                static int warned = 0;
                if ( !warned )
                {
                    hts_log_warning("Incorrect number of AC fields at %s:%"PRIhts_pos". (This message is printed only once.)\n",
                            header->id[BCF_DT_CTG][line->rid].key, line->pos+1);
                    warned = 1;
                }
                return 0;
            }
            int nac = 0;
            #define BRANCH_INT(type_t, convert) {        \
                for (i=0; i<ac_len; i++)        \
                {                               \
                    type_t val = convert(ac_ptr + i * sizeof(type_t)); \
                    ac[i+1] = val;             \
                    nac += val;                \
                }                               \
            }
            switch (ac_type) {
                case BCF_BT_INT8:  BRANCH_INT(int8_t,  le_to_i8); break;
                case BCF_BT_INT16: BRANCH_INT(int16_t, le_to_i16); break;
                case BCF_BT_INT32: BRANCH_INT(int32_t, le_to_i32); break;
                default: hts_log_error("Unexpected type %d at %s:%"PRIhts_pos, ac_type, header->id[BCF_DT_CTG][line->rid].key, line->pos+1); exit(1); break;
            }
            #undef BRANCH_INT
            if ( an<nac )
            {
                hts_log_error("Incorrect AN/AC counts at %s:%"PRIhts_pos, header->id[BCF_DT_CTG][line->rid].key, line->pos+1);
                exit(1);
            }
            ac[0] = an - nac;
            return 1;
        }
    }

    // Split genotype fields only when asked
    if ( which&BCF_UN_FMT )
    {
        int i, gt_id = bcf_hdr_id2int(header,BCF_DT_ID,"GT");
        if ( gt_id<0 ) return 0;
        bcf_unpack(line, BCF_UN_FMT);
        bcf_fmt_t *fmt_gt = NULL;
        for (i=0; i<(int)line->n_fmt; i++)
            if ( line->d.fmt[i].id==gt_id ) { fmt_gt = &line->d.fmt[i]; break; }
        if ( !fmt_gt ) return 0;
        #define BRANCH_INT(type_t, convert, vector_end) { \
            for (i=0; i<line->n_sample; i++) \
            { \
                uint8_t *p = (fmt_gt->p + i*fmt_gt->size); \
                int ial; \
                for (ial=0; ial<fmt_gt->n; ial++) \
                { \
                    int32_t val = convert(&p[ial * sizeof(type_t)]); \
                    if ( val==vector_end ) break; /* smaller ploidy */ \
                    if ( bcf_gt_is_missing(val) ) continue; /* missing allele */ \
                    if ( val>>1 > line->n_allele ) \
                    { \
                        hts_log_error("Incorrect allele (\"%d\") in %s at %s:%"PRIhts_pos, (val>>1)-1, header->samples[i], header->id[BCF_DT_CTG][line->rid].key, line->pos+1); \
                        exit(1); \
                    } \
                    ac[(val>>1)-1]++; \
                } \
            }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
xorl %eax, %eax
movzwl 0x1a(%rbx), %ecx
cmpq %rcx, %rax
jae 0x5cf2b
andl $0x0, (%r15,%rax,4)
incq %rax
jmp 0x5cf18
testb $0x4, %bpl
je 0x5d015
pushq $0x4
popq %rsi
movq %rbx, %rdi
callq 0x14890
leaq 0x4db9c(%rip), %rdx     # 0xaaae3
xorl %r12d, %r12d
movq %r14, %rdi
xorl %esi, %esi
callq 0x15ee0
movl %eax, %r13d
leaq 0x4cdfa(%rip), %rdx     # 0xa9d58
movq %r14, %rdi
xorl %esi, %esi
callq 0x15ee0
movl %r13d, %ecx
orl %eax, %ecx
js 0x5d015
movq 0x18(%rbx), %rdi
movzwl %di, %ecx
imulq $0x28, %rcx, %r8
pushq $-0x1
popq %rcx
xorl %r9d, %r9d
xorl %edx, %edx
xorl %esi, %esi
cmpq %r9, %r8
je 0x5cfbe
movq 0x90(%rbx), %r10
movl (%r10,%r9), %r11d
cmpl %r13d, %r11d
jne 0x5cfa4
movl 0x8(%r10,%r9), %ecx
jmp 0x5cfb8
cmpl %eax, %r11d
jne 0x5cfb8
movq 0x10(%r10,%r9), %rdx
movl 0x20(%r10,%r9), %esi
movl 0x4(%r10,%r9), %r12d
addq $0x28, %r9
jmp 0x5cf88
testl %ecx, %ecx
js 0x5d015
testq %rdx, %rdx
je 0x5d015
shrl $0x10, %edi
decl %edi
cmpl %edi, %esi
jne 0x5d105
cmpl $0x1, %r12d
je 0x5d243
cmpl $0x2, %r12d
je 0x5d223
cmpl $0x3, %r12d
jne 0x5d31f
xorl %edi, %edi
testl %esi, %esi
cmovlel %edi, %esi
xorl %eax, %eax
cmpq %rdi, %rsi
je 0x5d263
movl (%rdx,%rdi,4), %r8d
movl %r8d, 0x4(%r15,%rdi,4)
incq %rdi
addl %r8d, %eax
jmp 0x5cffb
testb $0x8, %bpl
jne 0x5d023
xorl %r12d, %r12d
jmp 0x5d26e
leaq 0x4e84a(%rip), %rdx     # 0xab874
xorl %r12d, %r12d
movq %r14, %rdi
xorl %esi, %esi
callq 0x15ee0
testl %eax, %eax
js 0x5d26e
movl %eax, %ebp
pushq $0x8
popq %rsi
movq %rbx, %rdi
callq 0x14890
movq 0x18(%rbx), %rsi
movq %rsi, %rax
shrq $0x20, %rax
movzbl %al, %ecx
shll $0x5, %ecx
addq $0x20, %rcx
xorl %r12d, %r12d
xorl %edi, %edi
leaq 0x20(%rdi), %rax
cmpq %rax, %rcx
je 0x5d26e
movq 0x98(%rbx), %rdx
cmpl %ebp, (%rdx,%rdi)
movq %rax, %rdi
jne 0x5d066
movl -0x14(%rdx,%rax), %ecx
cmpl $0x1, %ecx
je 0x5d1be
cmpl $0x2, %ecx
je 0x5d14f
cmpl $0x3, %ecx
jne 0x5d2f9
xorl %edi, %edi
pushq $0x1
popq %r12
shrq $0x28, %rsi
cmpl %esi, %edi
jae 0x5d26e
movl -0x18(%rdx,%rax), %ecx
imull %edi, %ecx
movslq %ecx, %rsi
addq -0x10(%rdx,%rax), %rsi
xorl %r8d, %r8d
movslq -0x1c(%rdx,%rax), %rcx
cmpq %rcx, %r8
jge 0x5d0fd
movl (%rsi,%r8,4), %ecx
cmpl $0x80000001, %ecx       # imm = 0x80000001
je 0x5d0fd
cmpl $0x2, %ecx
jb 0x5d0f8
sarl %ecx
movzwl 0x1a(%rbx), %r9d
cmpl %r9d, %ecx
jg 0x5d280
movslq %ecx, %rcx
incl -0x4(%r15,%rcx,4)
incq %r8
jmp 0x5d0c5
incl %edi
movq 0x18(%rbx), %rsi
jmp 0x5d0a7
cmpb $0x0, 0x770b0(%rip)     # 0xd41bc
jne 0x5d01b
movq 0x18(%r14), %rax
movslq 0x10(%rbx), %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rcx
movq (%rbx), %r8
incq %r8
leaq 0x4cc2c(%rip), %rsi     # 0xa9d5b
leaq 0x4cc31(%rip), %rdx     # 0xa9d67
xorl %r12d, %r12d
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x15830
movb $0x1, 0x77072(%rip)     # 0xd41bc
jmp 0x5d26e
xorl %edi, %edi
pushq $0x1
popq %r12
shrq $0x28, %rsi
cmpl %esi, %edi
jae 0x5d26e
movl -0x18(%rdx,%rax), %ecx
imull %edi, %ecx
movslq %ecx, %rsi
addq -0x10(%rdx,%rax), %rsi
xorl %r8d, %r8d
movslq -0x1c(%rdx,%rax), %rcx
cmpq %rcx, %r8
jge 0x5d1b6
movzwl (%rsi,%r8,2), %ecx
cmpw $0x8001, %cx            # imm = 0x8001
je 0x5d1b6
cmpw $0x2, %cx
jb 0x5d1b1
movswl %cx, %r9d
shrl %r9d
movswl %r9w, %ecx
movzwl 0x1a(%rbx), %r10d
cmpl %ecx, %r10d
jl 0x5d280
movswq %r9w, %rcx
incl -0x4(%r15,%rcx,4)
incq %r8
jmp 0x5d173
incl %edi
movq 0x18(%rbx), %rsi
jmp 0x5d155
xorl %edi, %edi
pushq $0x1
popq %r12
shrq $0x28, %rsi
cmpl %esi, %edi
jae 0x5d26e
movl -0x18(%rdx,%rax), %ecx
imull %edi, %ecx
movslq %ecx, %rsi
addq -0x10(%rdx,%rax), %rsi
xorl %r8d, %r8d
movslq -0x1c(%rdx,%rax), %rcx
cmpq %rcx, %r8
jge 0x5d21b
movb (%rsi,%r8), %r9b
cmpb $-0x7f, %r9b
je 0x5d21b
cmpb $0x2, %r9b
jb 0x5d216
sarb %r9b
movsbl %r9b, %ecx
movzwl 0x1a(%rbx), %r10d
cmpl %ecx, %r10d
jl 0x5d280
movsbq %r9b, %rcx
incl -0x4(%r15,%rcx,4)
incq %r8
jmp 0x5d1e2
incl %edi
movq 0x18(%rbx), %rsi
jmp 0x5d1c4
xorl %edi, %edi
testl %esi, %esi
cmovlel %edi, %esi
xorl %eax, %eax
cmpq %rdi, %rsi
je 0x5d263
movswl (%rdx,%rdi,2), %r8d
movl %r8d, 0x4(%r15,%rdi,4)
incq %rdi
addl %r8d, %eax
jmp 0x5d22c
xorl %edi, %edi
testl %esi, %esi
cmovlel %edi, %esi
xorl %eax, %eax
cmpq %rdi, %rsi
je 0x5d263
movsbl (%rdx,%rdi), %r8d
movl %r8d, 0x4(%r15,%rdi,4)
incq %rdi
addl %r8d, %eax
jmp 0x5d24c
subl %eax, %ecx
jl 0x5d2c7
movl %ecx, (%r15)
pushq $0x1
popq %r12
movl %r12d, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
decl %ecx
movq 0x18(%r14), %rax
movq 0x40(%r14), %rdx
movl %edi, %esi
movq (%rdx,%rsi,8), %r8
movslq 0x10(%rbx), %rdx
shlq $0x4, %rdx
movq (%rax,%rdx), %r9
movq (%rbx), %rax
incq %rax
movq %rax, (%rsp)
leaq 0x4caae(%rip), %rsi     # 0xa9d5b
leaq 0x4cb23(%rip), %rdx     # 0xa9dd7
pushq $0x1
popq %rbx
movl %ebx, %edi
xorl %eax, %eax
callq 0x15830
movl %ebx, %edi
callq 0x14650
movq 0x18(%r14), %rax
movslq 0x10(%rbx), %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rcx
movq (%rbx), %r8
incq %r8
leaq 0x4ca77(%rip), %rsi     # 0xa9d5b
leaq 0x4cacb(%rip), %rdx     # 0xa9db6
pushq $0x1
popq %rbx
movl %ebx, %edi
xorl %eax, %eax
callq 0x15830
jmp 0x5d2c0
movq 0x18(%r14), %rax
movslq 0x10(%rbx), %rdx
shlq $0x4, %rdx
movq (%rax,%rdx), %r8
movq (%rbx), %r9
incq %r9
leaq 0x4ca45(%rip), %rsi     # 0xa9d5b
leaq 0x4b760(%rip), %rdx     # 0xa8a7d
jmp 0x5d2b4
movq 0x18(%r14), %rax
movslq 0x10(%rbx), %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %r8
movq (%rbx), %r9
incq %r9
leaq 0x4ca1f(%rip), %rsi     # 0xa9d5b
leaq 0x4b73a(%rip), %rdx     # 0xa8a7d
pushq $0x1
popq %rbx
movl %ebx, %edi
movl %r12d, %ecx
jmp 0x5d2b9