// File: /workspace/github_c_makefile_star2_O3/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
cmpw $0x0, 0x1a(%rsi)
je 0x72eef
xorl %eax, %eax
movl $0x0, (%r15,%rax,4)
incq %rax
movzwl 0x1a(%rbx), %ecx
cmpq %rcx, %rax
jb 0x72edb
testb $0x4, %bpl
je 0x72fec
movq %rbx, %rdi
movl $0x4, %esi
callq 0x14860
leaq 0x60ec2(%rip), %rdx     # 0xd3dcf
movq %r14, %rdi
xorl %esi, %esi
callq 0x15e30
movl %eax, %r12d
leaq 0x60107(%rip), %rdx     # 0xd3028
movq %r14, %rdi
xorl %esi, %esi
callq 0x15e30
movl %r12d, %ecx
orl %eax, %ecx
js 0x72fec
movq 0x18(%rbx), %r8
testw %r8w, %r8w
je 0x72fec
movq 0x90(%rbx), %r9
movzwl %r8w, %ecx
shll $0x3, %ecx
leaq (%rcx,%rcx,4), %r10
xorl %r11d, %r11d
movl $0xffffffff, %edx       # imm = 0xFFFFFFFF
xorl %edi, %edi
xorl %ecx, %ecx
xorl %esi, %esi
movl (%r9,%r11), %r13d
cmpl %r12d, %r13d
jne 0x72f74
movl 0x8(%r9,%r11), %edx
jmp 0x72f88
cmpl %eax, %r13d
jne 0x72f88
movq 0x10(%r9,%r11), %rsi
movl 0x20(%r9,%r11), %edi
movl 0x4(%r9,%r11), %ecx
addq $0x28, %r11
cmpq %r11, %r10
jne 0x72f64
testl %edx, %edx
js 0x72fec
testq %rsi, %rsi
je 0x72fec
shrl $0x10, %r8d
decl %r8d
cmpl %r8d, %edi
jne 0x73102
cmpl $0x1, %ecx
je 0x73292
cmpl $0x2, %ecx
je 0x73271
cmpl $0x3, %ecx
jne 0x73320
testl %edi, %edi
jle 0x732b3
movl %edi, %ecx
xorl %edi, %edi
xorl %eax, %eax
movl (%rsi,%rdi,4), %r8d
movl %r8d, 0x4(%r15,%rdi,4)
incq %rdi
addl %r8d, %eax
cmpq %rdi, %rcx
jne 0x72fd3
jmp 0x732b5
testb $0x8, %bpl
jne 0x72ff9
xorl %ebp, %ebp
jmp 0x732c5
leaq 0x61b4c(%rip), %rdx     # 0xd4b4c
xorl %ebp, %ebp
movq %r14, %rdi
xorl %esi, %esi
callq 0x15e30
testl %eax, %eax
js 0x732c5
movl %eax, %r12d
movq %rbx, %rdi
movl $0x8, %esi
callq 0x14860
movq 0x18(%rbx), %rdx
movq %rdx, %rcx
shrq $0x20, %rcx
testb %cl, %cl
je 0x732c5
movq 0x98(%rbx), %rax
movzbl %cl, %ecx
addq $0x10, %rax
cmpl %r12d, -0x10(%rax)
je 0x73059
addq $0x20, %rax
decq %rcx
jne 0x73045
jmp 0x732c5
movl -0x4(%rax), %ecx
cmpl $0x1, %ecx
je 0x731e7
cmpl $0x2, %ecx
je 0x7314d
cmpl $0x3, %ecx
jne 0x73320
movq %rdx, %rcx
shrq $0x28, %rcx
movl $0x1, %ebp
je 0x732c5
movq (%rax), %rdi
movl -0xc(%rax), %r8d
xorl %esi, %esi
testl %r8d, %r8d
jle 0x730f0
movl -0x8(%rax), %ecx
imull %esi, %ecx
movslq %ecx, %rdx
movl (%rdi,%rdx), %ecx
cmpl $0x80000001, %ecx       # imm = 0x80000001
je 0x730ec
addq %rdi, %rdx
movl $0x1, %r9d
cmpl $0x2, %ecx
jb 0x730d5
sarl %ecx
movzwl 0x1a(%rbx), %r8d
cmpl %r8d, %ecx
jg 0x732d6
movslq %ecx, %rcx
incl -0x4(%r15,%rcx,4)
movl -0xc(%rax), %r8d
movslq %r8d, %rcx
cmpq %rcx, %r9
jge 0x730ec
movl (%rdx,%r9,4), %ecx
incq %r9
cmpl $0x80000001, %ecx       # imm = 0x80000001
jne 0x730b4
movq 0x18(%rbx), %rdx
incl %esi
movq %rdx, %rcx
shrq $0x28, %rcx
cmpl %ecx, %esi
jb 0x73092
jmp 0x732c5
cmpb $0x0, 0x82043(%rip)     # 0xf514c
jne 0x72ff2
movq 0x18(%r14), %rax
movslq 0x10(%rbx), %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rcx
movq (%rbx), %r8
incq %r8
leaq 0x5feff(%rip), %rsi     # 0xd302b
leaq 0x5ff04(%rip), %rdx     # 0xd3037
xorl %ebp, %ebp
movl $0x3, %edi
xorl %eax, %eax
callq 0x157b0
movb $0x1, 0x82004(%rip)     # 0xf514c
jmp 0x732c5
movq %rdx, %rcx
shrq $0x28, %rcx
movl $0x1, %ebp
je 0x732c5
movq (%rax), %rdi
movl -0xc(%rax), %ecx
xorl %esi, %esi
testl %ecx, %ecx
jle 0x731d4
movl -0x8(%rax), %edx
imull %esi, %edx
movslq %edx, %rdx
movzwl (%rdi,%rdx), %r9d
cmpl $0x8001, %r9d           # imm = 0x8001
je 0x731d0
addq %rdi, %rdx
movl $0x1, %r8d
cmpw $0x2, %r9w
jb 0x731b7
movswl %r9w, %r9d
shrl %r9d
movswl %r9w, %ecx
movzwl 0x1a(%rbx), %r10d
cmpl %ecx, %r10d
jl 0x732d6
movswq %r9w, %rcx
incl -0x4(%r15,%rcx,4)
movl -0xc(%rax), %ecx
movslq %ecx, %r9
cmpq %r9, %r8
jge 0x731d0
movzwl (%rdx,%r8,2), %r9d
incq %r8
cmpl $0x8001, %r9d           # imm = 0x8001
jne 0x7318b
movq 0x18(%rbx), %rdx
incl %esi
movq %rdx, %r8
shrq $0x28, %r8
cmpl %r8d, %esi
jb 0x73167
jmp 0x732c5
movq %rdx, %rcx
shrq $0x28, %rcx
movl $0x1, %ebp
je 0x732c5
movq (%rax), %rdi
movl -0xc(%rax), %ecx
xorl %esi, %esi
testl %ecx, %ecx
jle 0x73261
movl -0x8(%rax), %edx
imull %esi, %edx
movslq %edx, %rdx
movb (%rdi,%rdx), %r9b
cmpb $-0x7f, %r9b
je 0x7325d
addq %rdi, %rdx
movl $0x1, %r8d
cmpb $0x2, %r9b
jb 0x73248
sarb %r9b
movsbl %r9b, %ecx
movzwl 0x1a(%rbx), %r10d
cmpl %ecx, %r10d
jl 0x732d6
movsbq %r9b, %rcx
incl -0x4(%r15,%rcx,4)
movl -0xc(%rax), %ecx
movslq %ecx, %r9
cmpq %r9, %r8
jge 0x7325d
movb (%rdx,%r8), %r9b
incq %r8
cmpb $-0x7f, %r9b
jne 0x73221
movq 0x18(%rbx), %rdx
incl %esi
movq %rdx, %r8
shrq $0x28, %r8
cmpl %r8d, %esi
jb 0x73201
jmp 0x732c5
testl %edi, %edi
jle 0x732b3
movl %edi, %ecx
xorl %edi, %edi
xorl %eax, %eax
movswl (%rsi,%rdi,2), %r8d
movl %r8d, 0x4(%r15,%rdi,4)
incq %rdi
addl %r8d, %eax
cmpq %rdi, %rcx
jne 0x7327b
jmp 0x732b5
testl %edi, %edi
jle 0x732b3
movl %edi, %ecx
xorl %edi, %edi
xorl %eax, %eax
movsbl (%rsi,%rdi), %r8d
movl %r8d, 0x4(%r15,%rdi,4)
incq %rdi
addl %r8d, %eax
cmpq %rdi, %rcx
jne 0x7329c
jmp 0x732b5
xorl %eax, %eax
subl %eax, %edx
jl 0x73346
movl %edx, (%r15)
movl $0x1, %ebp
movl %ebp, %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 %esi, %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 0x5fd28(%rip), %rsi     # 0xd302b
leaq 0x5fd9d(%rip), %rdx     # 0xd30a7
movl $0x1, %edi
xorl %eax, %eax
callq 0x157b0
movl $0x1, %edi
callq 0x14620
movq 0x18(%r14), %rax
movslq 0x10(%rbx), %rdx
shlq $0x4, %rdx
movq (%rax,%rdx), %r8
movq (%rbx), %r9
incq %r9
leaq 0x5fcee(%rip), %rsi     # 0xd302b
leaq 0x5ea10(%rip), %rdx     # 0xd1d54
jmp 0x7330a
movq 0x18(%r14), %rax
movslq 0x10(%rbx), %rcx
shlq $0x4, %rcx
movq (%rax,%rcx), %rcx
movq (%rbx), %r8
incq %r8
leaq 0x5fcc8(%rip), %rsi     # 0xd302b
leaq 0x5fd1c(%rip), %rdx     # 0xd3086
movl $0x1, %edi
xorl %eax, %eax
callq 0x157b0
jmp 0x73316