// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/vcf.c
// Function: bcf_write
int bcf_write(htsFile *hfp, bcf_hdr_t *h, bcf1_t *v)
{
    if ( h->dirty ) {
        if (bcf_hdr_sync(h) < 0) return -1;
    }
    if ( bcf_hdr_nsamples(h)!=v->n_sample )
    {
        hts_log_error("Broken VCF record, the number of columns at %s:%"PRIhts_pos" does not match the number of samples (%d vs %d)",
            bcf_seqname_safe(h,v), v->pos+1, v->n_sample, bcf_hdr_nsamples(h));
        return -1;
    }

    if ( hfp->format.format == vcf || hfp->format.format == text_format )
        return vcf_write(hfp,h,v);

    if ( v->errcode & ~BCF_ERR_LIMITS ) // todo: unsure about the other BCF_ERR_LIMITS branches in vcf_parse_format_alloc4()
    {
        // vcf_parse1() encountered a new contig or tag, undeclared in the
        // header.  At this point, the header must have been printed,
        // proceeding would lead to a broken BCF file. Errors must be checked
        // and cleared by the caller before we can proceed.
        char errdescription[1024] = "";
        hts_log_error("Unchecked error (%d %s) at %s:%"PRIhts_pos, v->errcode, bcf_strerror(v->errcode, errdescription, sizeof(errdescription)), bcf_seqname_safe(h,v), v->pos+1);
        return -1;
    }
    bcf1_sync(v);   // check if the BCF record was modified

    if ( v->unpacked & BCF_IS_64BIT )
    {
        hts_log_error("Data at %s:%"PRIhts_pos" contains 64-bit values not representable in BCF. Please use VCF instead", bcf_seqname_safe(h,v), v->pos+1);
        return -1;
    }

    BGZF *fp = hfp->fp.bgzf;
    uint8_t x[32];
    u32_to_le(v->shared.l + 24, x); // to include six 32-bit integers
    u32_to_le(v->indiv.l, x + 4);
    i32_to_le(v->rid, x + 8);
    u32_to_le(v->pos, x + 12);
    u32_to_le(v->rlen, x + 16);
    float_to_le(v->qual, x + 20);
    u16_to_le(v->n_info, x + 24);
    u16_to_le(v->n_allele, x + 26);
    u32_to_le((uint32_t)v->n_fmt<<24 | (v->n_sample & 0xffffff), x + 28);
    if ( bgzf_write(fp, x, 32) != 32 ) return -1;
    if ( bgzf_write(fp, v->shared.s, v->shared.l) != v->shared.l ) return -1;
    if ( bgzf_write(fp, v->indiv.s, v->indiv.l) != v->indiv.l ) return -1;

    if (hfp->idx) {
        if (bgzf_idx_push(fp, hfp->idx, v->rid, v->pos, v->pos + v->rlen,
                          bgzf_tell(fp), 1) < 0)
            return -1;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x418, %rsp            # imm = 0x418
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
cmpl $0x0, 0x54(%rsi)
pushq $-0x1
popq %rbx
je 0x27424
movq %r12, %rdi
callq 0x2276e
testl %eax, %eax
js 0x27495
movl 0x8(%r12), %ebp
movq 0x18(%r14), %r13
shrq $0x28, %r13
cmpl %r13d, %ebp
jne 0x27463
movl 0x4c(%r15), %eax
cmpl $0x8, %eax
je 0x27444
cmpl $0x2, %eax
jne 0x274a9
movq %r15, %rdi
movq %r12, %rsi
movq %r14, %rdx
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x27666
movq %r12, %rdi
movq %r14, %rsi
callq 0x27650
movq (%r14), %r8
incq %r8
movl %ebp, (%rsp)
leaq 0x5f362(%rip), %rsi     # 0x867e0
leaq 0x5f365(%rip), %rdx     # 0x867ea
pushq $0x1
popq %rdi
movq %rax, %rcx
movl %r13d, %r9d
xorl %eax, %eax
callq 0x8132
movl %ebx, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl 0xcc(%r14), %ebp
testl $0xfffffff7, %ebp       # imm = 0xFFFFFFF7
je 0x27515
leaq 0x10(%rsp), %r15
movl $0x400, %edx            # imm = 0x400
movq %r15, %rdi
xorl %esi, %esi
callq 0x4250
movl $0x400, %edx            # imm = 0x400
movl %ebp, %edi
movq %r15, %rsi
callq 0x277a1
movq %rax, %r15
movq %r12, %rdi
movq %r14, %rsi
callq 0x27650
movq (%r14), %rcx
incq %rcx
movq %rcx, (%rsp)
leaq 0x5f2e6(%rip), %rsi     # 0x867e0
leaq 0x5f34c(%rip), %rdx     # 0x8684d
pushq $0x1
popq %rdi
movl %ebp, %ecx
movq %r15, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x8132
jmp 0x27495
movq %r14, %rdi
callq 0x26ee1
testb $0x40, 0xbf(%r14)
jne 0x2761f
movq 0x38(%r15), %r12
movl 0x20(%r14), %eax
addl $0x18, %eax
leaq 0x10(%rsp), %rsi
movl %eax, (%rsi)
movl 0x38(%r14), %eax
movl %eax, 0x4(%rsi)
movl 0x10(%r14), %eax
movl %eax, 0x8(%rsi)
movdqu (%r14), %xmm0
pshufd $0xe8, %xmm0, %xmm0     # xmm0 = xmm0[0,2,2,3]
movq %xmm0, 0xc(%rsi)
movss 0x14(%r14), %xmm0
movss %xmm0, 0x14(%rsi)
movq 0x18(%r14), %rax
movw %ax, 0x18(%rsi)
movl %eax, %ecx
shrl $0x10, %ecx
movw %cx, 0x1a(%rsi)
movq %rax, %rcx
shrq $0x8, %rcx
andl $0xff000000, %ecx       # imm = 0xFF000000
shrq $0x28, %rax
orl %ecx, %eax
movl %eax, 0x1c(%rsi)
pushq $0x20
popq %rdx
movq %r12, %rdi
callq 0x6be34
pushq $-0x1
popq %rbx
cmpq $0x20, %rax
jne 0x27495
movq 0x20(%r14), %rdx
movq 0x30(%r14), %rsi
movq %r12, %rdi
callq 0x6be34
cmpq 0x20(%r14), %rax
jne 0x27495
movq 0x38(%r14), %rdx
movq 0x48(%r14), %rsi
movq %r12, %rdi
callq 0x6be34
cmpq 0x38(%r14), %rax
jne 0x27495
movq 0x68(%r15), %rsi
testq %rsi, %rsi
je 0x27618
movl 0x10(%r14), %edx
movq (%r14), %rcx
movq 0x8(%r14), %r8
addq %rcx, %r8
movq 0x18(%r12), %rax
shlq $0x10, %rax
movzwl 0x10(%r12), %r9d
orq %rax, %r9
movl $0x1, (%rsp)
movq %r12, %rdi
callq 0x69824
testl %eax, %eax
js 0x27495
xorl %ebx, %ebx
jmp 0x27495
movq %r12, %rdi
movq %r14, %rsi
callq 0x27650
movq (%r14), %r8
incq %r8
leaq 0x5f1a9(%rip), %rsi     # 0x867e0
leaq 0x5f231(%rip), %rdx     # 0x8686f
pushq $0x1
popq %rdi
movq %rax, %rcx
xorl %eax, %eax
callq 0x8132
jmp 0x27495