// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
movl %ecx, %ebp
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
cmpw $0x0, 0x1a(%rsi)
je 0x74262
xorl %eax, %eax
movl $0x0, (%r15,%rax,4)
incq %rax
movzwl 0x1a(%rbx), %ecx
cmpq %rcx, %rax
jb 0x7424e
testb $0x4, %bpl
je 0x74425
movq %rbx, %rdi
movl $0x4, %esi
callq 0x14860
leaq 0x61b03(%rip), %rdx     # 0xd5d83
xorl %r13d, %r13d
movq %r14, %rdi
xorl %esi, %esi
callq 0x15e40
movl %eax, %r12d
leaq 0x60d61(%rip), %rdx     # 0xd4ff8
movq %r14, %rdi
xorl %esi, %esi
callq 0x15e40
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %r12d, %edx
orl %eax, %edx
js 0x742fd
movzwl 0x18(%rbx), %edx
testq %rdx, %rdx
je 0x74301
movq 0x90(%rbx), %rdi
shll $0x3, %edx
leaq (%rdx,%rdx,4), %r8
xorl %r9d, %r9d
xorl %esi, %esi
xorl %r13d, %r13d
xorl %edx, %edx
movl (%rdi,%r9), %r10d
cmpl %r12d, %r10d
jne 0x742de
movl 0x8(%rdi,%r9), %ecx
jmp 0x742f2
cmpl %eax, %r10d
jne 0x742f2
movq 0x10(%rdi,%r9), %rdx
movl 0x20(%rdi,%r9), %esi
movl 0x4(%rdi,%r9), %r13d
addq $0x28, %r9
cmpq %r9, %r8
jne 0x742ce
jmp 0x74308
xorl %edx, %edx
jmp 0x74306
xorl %edx, %edx
xorl %r13d, %r13d
xorl %esi, %esi
movq %r14, 0x10(%rsp)
testl %ecx, %ecx
sets %al
testq %rdx, %rdx
sete %r14b
orb %al, %r14b
jne 0x74417
movzwl 0x1a(%rbx), %eax
decl %eax
cmpl %eax, %esi
jne 0x74371
cmpl $0x1, %r13d
je 0x743e3
cmpl $0x2, %r13d
je 0x743c2
cmpl $0x3, %r13d
jne 0x746f0
testl %esi, %esi
jle 0x74404
movl %esi, %esi
xorl %edi, %edi
xorl %eax, %eax
movl (%rdx,%rdi,4), %r8d
movl %r8d, 0x4(%r15,%rdi,4)
incq %rdi
addl %r8d, %eax
cmpq %rdi, %rsi
jne 0x74358
jmp 0x74406
xorl %r12d, %r12d
cmpb $0x0, 0x82dd1(%rip)     # 0xf714c
jne 0x74417
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movslq 0x10(%rbx), %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rcx
movq (%rbx), %r8
incq %r8
leaq 0x60c58(%rip), %rsi     # 0xd4ffb
leaq 0x60c5d(%rip), %rdx     # 0xd5007
xorl %r12d, %r12d
movl $0x3, %edi
xorl %eax, %eax
callq 0x157b0
movb $0x1, 0x82d8c(%rip)     # 0xf714c
jmp 0x74417
testl %esi, %esi
jle 0x74404
movl %esi, %esi
xorl %edi, %edi
xorl %eax, %eax
movswl (%rdx,%rdi,2), %r8d
movl %r8d, 0x4(%r15,%rdi,4)
incq %rdi
addl %r8d, %eax
cmpq %rdi, %rsi
jne 0x743cc
jmp 0x74406
testl %esi, %esi
jle 0x74404
movl %esi, %esi
xorl %edi, %edi
xorl %eax, %eax
movsbl (%rdx,%rdi), %r8d
movl %r8d, 0x4(%r15,%rdi,4)
incq %rdi
addl %r8d, %eax
cmpq %rdi, %rsi
jne 0x743ed
jmp 0x74406
xorl %eax, %eax
subl %eax, %ecx
jl 0x74693
movl %ecx, (%r15)
movl $0x1, %r12d
testb %r14b, %r14b
movq 0x10(%rsp), %r14
je 0x74637
xorl %r12d, %r12d
testb $0x8, %bpl
je 0x74637
leaq 0x62673(%rip), %rdx     # 0xd6aac
xorl %r12d, %r12d
movq %r14, %rdi
xorl %esi, %esi
callq 0x15e40
testl %eax, %eax
js 0x74637
movl %eax, %ebp
movq %rbx, %rdi
movl $0x8, %esi
callq 0x14860
movq 0x18(%rbx), %rcx
shrq $0x20, %rcx
xorl %r12d, %r12d
testb %cl, %cl
je 0x74483
movq 0x98(%rbx), %rax
movzbl %cl, %ecx
cmpl %ebp, (%rax)
je 0x74485
addq $0x20, %rax
decq %rcx
jne 0x74476
xorl %eax, %eax
testq %rax, %rax
je 0x74637
movl 0xc(%rax), %ecx
cmpl $0x1, %ecx
je 0x745bf
cmpl $0x2, %ecx
je 0x74531
cmpl $0x3, %ecx
jne 0x746ca
movq 0x18(%rbx), %rcx
shrq $0x28, %rcx
movl $0x1, %r12d
je 0x74637
movq 0x10(%rax), %rsi
xorl %edx, %edx
cmpl $0x0, 0x4(%rax)
jle 0x7451e
movl 0x8(%rax), %ecx
imull %edx, %ecx
movslq %ecx, %rdi
addq %rsi, %rdi
xorl %r8d, %r8d
movl (%rdi,%r8,4), %r9d
cmpl $0x80000001, %r9d       # imm = 0x80000001
je 0x7451e
cmpl $0x2, %r9d
jb 0x74509
movl %r9d, %ecx
sarl %ecx
movzwl 0x1a(%rbx), %r10d
cmpl %r10d, %ecx
jg 0x74649
movslq %ecx, %rcx
incl -0x4(%r15,%rcx,4)
cmpl $0x80000001, %r9d       # imm = 0x80000001
je 0x7451e
incq %r8
movslq 0x4(%rax), %rcx
cmpq %rcx, %r8
jl 0x744db
incl %edx
movq 0x18(%rbx), %rcx
shrq $0x28, %rcx
cmpl %ecx, %edx
jb 0x744c6
jmp 0x74637
movq 0x18(%rbx), %rcx
shrq $0x28, %rcx
movl $0x1, %r12d
je 0x74637
movq 0x10(%rax), %rsi
xorl %edx, %edx
cmpl $0x0, 0x4(%rax)
jle 0x745af
movl 0x8(%rax), %ecx
imull %edx, %ecx
movslq %ecx, %rdi
addq %rsi, %rdi
xorl %r8d, %r8d
movzwl (%rdi,%r8,2), %r9d
cmpl $0x8001, %r9d           # imm = 0x8001
je 0x745af
cmpw $0x2, %r9w
jb 0x74597
movswl %r9w, %r10d
shrl %r10d
movswl %r10w, %ecx
movzwl 0x1a(%rbx), %r11d
cmpl %ecx, %r11d
jl 0x74649
movswq %r10w, %rcx
incl -0x4(%r15,%rcx,4)
movzwl %r9w, %ecx
cmpl $0x8001, %ecx           # imm = 0x8001
je 0x745af
incq %r8
movslq 0x4(%rax), %rcx
cmpq %rcx, %r8
jl 0x74560
incl %edx
movq 0x18(%rbx), %rcx
shrq $0x28, %rcx
cmpl %ecx, %edx
jb 0x7454b
jmp 0x74637
movq 0x18(%rbx), %rcx
shrq $0x28, %rcx
movl $0x1, %r12d
je 0x74637
movq 0x10(%rax), %rsi
xorl %edx, %edx
cmpl $0x0, 0x4(%rax)
jle 0x74629
movl 0x8(%rax), %ecx
imull %edx, %ecx
movslq %ecx, %rdi
addq %rsi, %rdi
xorl %r8d, %r8d
movb (%rdi,%r8), %r9b
cmpb $-0x7f, %r9b
je 0x74629
cmpb $0x2, %r9b
jb 0x74617
movl %r9d, %r10d
sarb %r10b
movsbl %r10b, %ecx
movzwl 0x1a(%rbx), %r11d
cmpl %ecx, %r11d
jl 0x74649
movsbq %r10b, %rcx
incl -0x4(%r15,%rcx,4)
cmpb $-0x7f, %r9b
je 0x74629
incq %r8
movslq 0x4(%rax), %rcx
cmpq %rcx, %r8
jl 0x745ea
incl %edx
movq 0x18(%rbx), %rcx
shrq $0x28, %rcx
cmpl %ecx, %edx
jb 0x745d5
movl %r12d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
decl %ecx
movq 0x18(%r14), %rax
movq 0x40(%r14), %rsi
movl %edx, %edx
movq (%rsi,%rdx,8), %r8
movslq 0x10(%rbx), %rdx
shlq $0x4, %rdx
movq (%rax,%rdx), %r9
movq (%rbx), %rax
incq %rax
movq %rax, (%rsp)
leaq 0x60985(%rip), %rsi     # 0xd4ffb
leaq 0x609fa(%rip), %rdx     # 0xd5077
movl $0x1, %edi
xorl %eax, %eax
callq 0x157b0
movl $0x1, %edi
callq 0x14620
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movslq 0x10(%rbx), %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rcx
movq (%rbx), %r8
incq %r8
leaq 0x60946(%rip), %rsi     # 0xd4ffb
leaq 0x6099a(%rip), %rdx     # 0xd5056
movl $0x1, %edi
xorl %eax, %eax
callq 0x157b0
jmp 0x74689
movq 0x18(%r14), %rax
movslq 0x10(%rbx), %rdx
shlq $0x4, %rdx
movq (%rax,%rdx), %r8
movq (%rbx), %r9
incq %r9
leaq 0x60914(%rip), %rsi     # 0xd4ffb
leaq 0x5f636(%rip), %rdx     # 0xd3d24
jmp 0x7467d
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movslq 0x10(%rbx), %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %r8
movq (%rbx), %r9
incq %r9
leaq 0x608e9(%rip), %rsi     # 0xd4ffb
leaq 0x5f60b(%rip), %rdx     # 0xd3d24
movl $0x1, %edi
movl %r13d, %ecx
jmp 0x74682