// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/vcf.c
// Function: bcf_format_gt_v2
int bcf_format_gt_v2(const bcf_hdr_t *hdr, bcf_fmt_t *fmt, int isample, kstring_t *str)
{
    uint32_t e = 0;
    int ploidy = 1, anyunphased = 0;
    int32_t val0 = 0;
    size_t pos = str ? str->l : 0;

    #define BRANCH(type_t, convert, missing, vector_end) { \
        uint8_t *ptr = fmt->p + isample*fmt->size; \
        int i; \
        for (i=0; i<fmt->n; i++, ptr += sizeof(type_t)) \
        { \
            type_t val = convert(ptr); \
            if ( val == vector_end ) break; \
            if (!i) { val0 = val; } \
            if (i) { \
                e |= kputc("/|"[val & 1], str) < 0; \
                anyunphased |= !(val & 1); \
            } \
            if (!(val >> 1)) e |= kputc('.', str) < 0; \
            else e |= kputw((val >> 1) - 1, str) < 0; \
        } \
        if (i == 0) e |= kputc('.', str) < 0; \
        ploidy = i; \
    }
    switch (fmt->type) {
        case BCF_BT_INT8:  BRANCH(int8_t,  le_to_i8,  bcf_int8_missing,
            bcf_int8_vector_end); break;
        case BCF_BT_INT16: BRANCH(int16_t, le_to_i16, bcf_int16_missing,
            bcf_int16_vector_end); break;
        case BCF_BT_INT32: BRANCH(int32_t, le_to_i32, bcf_int32_missing,
            bcf_int32_vector_end); break;
        case BCF_BT_NULL:  e |= kputc('.', str) < 0; break;
        default: hts_log_error("Unexpected type %d", fmt->type); return -2;
    }
    #undef BRANCH

    if (hdr && get_hdr_aux(hdr)->version >= VCF44) {
        //output which supports prefixed phasing

        /* update 1st allele's phasing if required and append rest to it.
        use prefixed phasing only when it is a must. i.e. without which the
        inferred value will be incorrect */
        if (val0 & 1) {
            /* 1st one is phased, if ploidy is > 1 and an unphased allele exists
             need to specify explicitly */
            e |= (ploidy > 1 && anyunphased) ?
                    (kinsert_char('|', pos, str) < 0) :
                        (ploidy <= 1 && !((val0 >> 1)) ? //|. needs explicit o/p
                            (kinsert_char('|', pos, str) < 0) :
                            0);
        } else {
            /* 1st allele is unphased, if ploidy is = 1 or allele is '.' or
             ploidy > 1 and no other unphased allele exist, need to specify
             explicitly */
            e |= ((ploidy <= 1 && val0 != 0) || (ploidy > 1 && !anyunphased)) ?
                    (kinsert_char('/', pos, str) < 0) :
                    0;
        }
    }
    return e == 0 ? 0 : -1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, %rbx
movq %rsi, 0x10(%rsp)
movq %rdi, %r14
testq %rcx, %rcx
je 0x2c1c1
movq (%rbx), %rax
jmp 0x2c1c3
xorl %eax, %eax
movq 0x10(%rsp), %rcx
movl 0xc(%rcx), %ecx
cmpq $0x3, %rcx
ja 0x2c48e
movq %rax, 0x20(%rsp)
leaq 0x59a67(%rip), %rax     # 0x85c48
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
movq %rbx, %r12
jmpq *%rcx
pushq $0x2e
popq %rdi
movq %rbx, %rsi
callq 0x25f76
movl %eax, %ebp
shrl $0x1f, %ebp
pushq $0x1
popq %r13
xorl %r15d, %r15d
movl $0x0, 0x4(%rsp)
jmp 0x2c44f
movq %r14, 0x8(%rsp)
movq 0x10(%rsp), %rax
imull 0x8(%rax), %edx
movslq %edx, %rcx
addq 0x10(%rax), %rcx
movq %rcx, 0x18(%rsp)
xorl %r13d, %r13d
xorl %r15d, %r15d
movl $0x0, 0x4(%rsp)
xorl %ebp, %ebp
movq 0x10(%rsp), %rax
cmpl 0x4(%rax), %r13d
jge 0x2c432
movq 0x18(%rsp), %rax
movswl (%rax,%r13,2), %r14d
cmpl $0xffff8001, %r14d      # imm = 0xFFFF8001
je 0x2c432
testl %r13d, %r13d
cmovel %r14d, %r15d
je 0x2c293
movl %r14d, %ebx
andl $0x1, %ebx
leaq 0x5af0e(%rip), %rax     # 0x87185
movsbl (%rbx,%rax), %edi
movq %r12, %rsi
callq 0x25f76
shrl $0x1f, %eax
orl %eax, %ebp
xorl $0x1, %ebx
orl 0x4(%rsp), %ebx
movl %ebx, 0x4(%rsp)
cmpw $0x1, %r14w
ja 0x2c2aa
pushq $0x2e
popq %rdi
movq %r12, %rbx
movq %r12, %rsi
callq 0x25f76
jmp 0x2c2be
sarl %r14d
decl %r14d
movl %r14d, %edi
movq %r12, %rbx
movq %r12, %rsi
callq 0x22eac
shrl $0x1f, %eax
orl %eax, %ebp
incq %r13
jmp 0x2c23b
movq %r14, 0x8(%rsp)
movq 0x10(%rsp), %rax
imull 0x8(%rax), %edx
movslq %edx, %rcx
addq 0x10(%rax), %rcx
movq %rcx, 0x18(%rsp)
xorl %r13d, %r13d
xorl %r15d, %r15d
movl $0x0, 0x4(%rsp)
xorl %ebp, %ebp
movq 0x10(%rsp), %rax
cmpl 0x4(%rax), %r13d
jge 0x2c432
movq 0x18(%rsp), %rax
movl (%rax,%r13,4), %r14d
movl $0x80000001, %eax       # imm = 0x80000001
cmpq %rax, %r14
je 0x2c432
testl %r13d, %r13d
cmovel %r14d, %r15d
je 0x2c34d
movl %r14d, %ebx
andl $0x1, %ebx
leaq 0x5ae54(%rip), %rax     # 0x87185
movsbl (%rbx,%rax), %edi
movq %r12, %rsi
callq 0x25f76
shrl $0x1f, %eax
orl %eax, %ebp
xorl $0x1, %ebx
orl 0x4(%rsp), %ebx
movl %ebx, 0x4(%rsp)
cmpl $0x1, %r14d
ja 0x2c363
pushq $0x2e
popq %rdi
movq %r12, %rbx
movq %r12, %rsi
callq 0x25f76
jmp 0x2c377
sarl %r14d
decl %r14d
movl %r14d, %edi
movq %r12, %rbx
movq %r12, %rsi
callq 0x22eac
shrl $0x1f, %eax
orl %eax, %ebp
incq %r13
jmp 0x2c2f5
movq %r14, 0x8(%rsp)
movq 0x10(%rsp), %rax
imull 0x8(%rax), %edx
movslq %edx, %rcx
addq 0x10(%rax), %rcx
movq %rcx, 0x18(%rsp)
xorl %r13d, %r13d
xorl %r15d, %r15d
movl $0x0, 0x4(%rsp)
xorl %ebp, %ebp
movq 0x10(%rsp), %rax
cmpl 0x4(%rax), %r13d
jge 0x2c432
movq 0x18(%rsp), %rax
movsbl (%rax,%r13), %r14d
cmpl $-0x7f, %r14d
je 0x2c432
testl %r13d, %r13d
cmovel %r14d, %r15d
je 0x2c3fb
movl %r14d, %ebx
andl $0x1, %ebx
leaq 0x5ada6(%rip), %rax     # 0x87185
movsbl (%rbx,%rax), %edi
movq %r12, %rsi
callq 0x25f76
shrl $0x1f, %eax
orl %eax, %ebp
xorl $0x1, %ebx
orl 0x4(%rsp), %ebx
movl %ebx, 0x4(%rsp)
cmpb $0x1, %r14b
ja 0x2c411
pushq $0x2e
popq %rdi
movq %r12, %rbx
movq %r12, %rsi
callq 0x25f76
jmp 0x2c425
sarl %r14d
decl %r14d
movl %r14d, %edi
movq %r12, %rbx
movq %r12, %rsi
callq 0x22eac
shrl $0x1f, %eax
orl %eax, %ebp
incq %r13
jmp 0x2c3ae
testl %r13d, %r13d
jne 0x2c44a
pushq $0x2e
popq %rdi
movq %rbx, %rsi
callq 0x25f76
shrl $0x1f, %eax
orl %eax, %ebp
xorl %r13d, %r13d
movq 0x8(%rsp), %r14
testq %r14, %r14
je 0x2c4db
movq 0x28(%r14), %rax
cmpl $0x3d18a0, 0x38(%rax)   # imm = 0x3D18A0
jl 0x2c4db
testb $0x1, %r15b
jne 0x2c4ab
xorl %ecx, %ecx
testl %r15d, %r15d
sete %cl
xorl %eax, %eax
cmpl $0x0, 0x4(%rsp)
setne %al
cmpl $0x2, %r13d
cmovael %eax, %ecx
xorl %eax, %eax
testb %cl, %cl
jne 0x2c4d9
pushq $0x2f
jmp 0x2c4c8
leaq 0x5acf3(%rip), %rsi     # 0x87188
leaq 0x5a500(%rip), %rdx     # 0x8699c
pushq $0x1
popq %rdi
xorl %eax, %eax
callq 0x8132
pushq $-0x2
popq %rax
jmp 0x2c4e1
cmpl $0x2, %r13d
jb 0x2c4b8
cmpl $0x0, 0x4(%rsp)
jne 0x2c4c6
xorl %eax, %eax
cmpl $0x1, %r13d
ja 0x2c4d9
cmpl $0x1, %r15d
ja 0x2c4d9
pushq $0x7c
popq %rdi
movq 0x20(%rsp), %rsi
movq %rbx, %rdx
callq 0x308d9
shrl $0x1f, %eax
orl %eax, %ebp
xorl %eax, %eax
negl %ebp
sbbl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq