// File: /workspace/github_c_makefile_star2_O1/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 %rbx
subq $0x418, %rsp            # imm = 0x418
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r15
cmpl $0x0, 0x54(%rsi)
je 0x3278f
movq %r14, %rdi
callq 0x2bc46
testl %eax, %eax
js 0x32836
movl 0x8(%r14), %eax
movq 0x18(%rbx), %r9
shrq $0x28, %r9
cmpl %r9d, %eax
jne 0x327cd
movl 0x4c(%r15), %eax
cmpl $0x8, %eax
je 0x327b2
cmpl $0x2, %eax
jne 0x3284b
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x32aa6
testq %rbx, %rbx
je 0x327d7
movl 0x10(%rbx), %ecx
jmp 0x327dc
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testq %r14, %r14
sete %dl
testl %ecx, %ecx
sets %sil
orb %dl, %sil
jne 0x32803
cmpl %ecx, 0x4(%r14)
jle 0x32803
movq 0x18(%r14), %rdx
movl %ecx, %ecx
shlq $0x4, %rcx
movq (%rdx,%rcx), %rdx
jmp 0x32805
xorl %edx, %edx
testq %rdx, %rdx
leaq 0x7d150(%rip), %rcx     # 0xaf95f
cmovneq %rdx, %rcx
movq (%rbx), %r8
incq %r8
movl %eax, (%rsp)
leaq 0x7c2bd(%rip), %rsi     # 0xaeae0
leaq 0x7c2c0(%rip), %rdx     # 0xaeaea
movl $0x1, %edi
xorl %eax, %eax
callq 0x9774
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movl %ebp, %eax
addq $0x418, %rsp            # imm = 0x418
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl 0xcc(%rbx), %ebp
testl $0xfffffff7, %ebp       # imm = 0xFFFFFFF7
je 0x3288d
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 0x32cd9
testq %rbx, %rbx
je 0x3298f
movl 0x10(%rbx), %ecx
jmp 0x32994
movq %rbx, %rdi
callq 0x31cd3
testb $0x40, 0xbf(%rbx)
jne 0x329f9
movq 0x38(%r15), %r14
movl 0x20(%rbx), %eax
addl $0x18, %eax
leaq 0x10(%rsp), %rsi
movl %eax, (%rsi)
movl 0x38(%rbx), %eax
movl %eax, 0x4(%rsi)
movl 0x10(%rbx), %eax
movl %eax, 0x8(%rsi)
movl (%rbx), %eax
movl %eax, 0xc(%rsi)
movl 0x8(%rbx), %eax
movl %eax, 0x10(%rsi)
movss 0x14(%rbx), %xmm0
movss %xmm0, 0x14(%rsi)
movq 0x18(%rbx), %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)
movl $0x20, %edx
movq %r14, %rdi
callq 0x8eb43
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpq $0x20, %rax
jne 0x3283b
movq 0x20(%rbx), %rdx
movq 0x30(%rbx), %rsi
movq %r14, %rdi
callq 0x8eb43
cmpq 0x20(%rbx), %rax
jne 0x3283b
movq 0x38(%rbx), %rdx
movq 0x48(%rbx), %rsi
movq %r14, %rdi
callq 0x8eb43
cmpq 0x38(%rbx), %rax
jne 0x3283b
movq 0x68(%r15), %rsi
testq %rsi, %rsi
je 0x32988
movl 0x10(%rbx), %edx
movq (%rbx), %rcx
movq 0x8(%rbx), %r8
addq %rcx, %r8
movq 0x18(%r14), %rax
shlq $0x10, %rax
movzwl 0x10(%r14), %r9d
orq %rax, %r9
movl $0x1, (%rsp)
movq %r14, %rdi
callq 0x8bddc
testl %eax, %eax
js 0x3283b
xorl %ebp, %ebp
jmp 0x3283b
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
testq %r14, %r14
sete %dl
testl %ecx, %ecx
sets %sil
orb %dl, %sil
jne 0x329bb
cmpl %ecx, 0x4(%r14)
jle 0x329bb
movq 0x18(%r14), %rdx
movl %ecx, %ecx
shlq $0x4, %rcx
movq (%rdx,%rcx), %rcx
jmp 0x329bd
xorl %ecx, %ecx
testq %rcx, %rcx
leaq 0x7cf98(%rip), %r9      # 0xaf95f
cmovneq %rcx, %r9
movq (%rbx), %rcx
incq %rcx
movq %rcx, (%rsp)
leaq 0x7c104(%rip), %rsi     # 0xaeae0
leaq 0x7c16a(%rip), %rdx     # 0xaeb4d
movl $0x1, %edi
movl %ebp, %ecx
movq %rax, %r8
xorl %eax, %eax
callq 0x9774
jmp 0x32836
testq %rbx, %rbx
je 0x32a03
movl 0x10(%rbx), %eax
jmp 0x32a08
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
testq %r14, %r14
sete %cl
testl %eax, %eax
sets %dl
orb %cl, %dl
jne 0x32a2d
cmpl %eax, 0x4(%r14)
jle 0x32a2d
movq 0x18(%r14), %rcx
movl %eax, %eax
shlq $0x4, %rax
movq (%rcx,%rax), %rax
jmp 0x32a2f
xorl %eax, %eax
testq %rax, %rax
leaq 0x7cf26(%rip), %rcx     # 0xaf95f
cmovneq %rax, %rcx
movq (%rbx), %r8
incq %r8
leaq 0x7c096(%rip), %rsi     # 0xaeae0
leaq 0x7c11e(%rip), %rdx     # 0xaeb6f
movl $0x1, %edi
xorl %eax, %eax
callq 0x9774
jmp 0x32836