// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x470, %rsp            # imm = 0x470
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x18(%rbp), %rax
cmpl $0x0, 0x54(%rax)
je 0x4313d
movq -0x18(%rbp), %rdi
callq 0x3ae50
cmpl $0x0, %eax
jge 0x4313b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43514
jmp 0x4313d
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x20(%rbp), %rcx
movq 0x18(%rcx), %rcx
shrq $0x28, %rcx
cmpl %ecx, %eax
je 0x431ae
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x43520
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq (%rax), %r8
addq $0x1, %r8
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x28, %rax
movl %eax, %r9d
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl $0x1, %edi
leaq 0xc49c3(%rip), %rsi     # 0x107b54
leaq 0xc49c6(%rip), %rdx     # 0x107b5e
movl %eax, (%rsp)
movb $0x0, %al
callq 0x9d90
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43514
movq -0x10(%rbp), %rax
cmpl $0x8, 0x4c(%rax)
je 0x431c2
movq -0x10(%rbp), %rax
cmpl $0x2, 0x4c(%rax)
jne 0x431db
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
callq 0x43570
movl %eax, -0x4(%rbp)
jmp 0x43514
movq -0x20(%rbp), %rax
movl 0xcc(%rax), %eax
andl $-0x9, %eax
cmpl $0x0, %eax
je 0x43288
leaq -0x420(%rbp), %rdi
xorl %esi, %esi
movl $0x400, %edx            # imm = 0x400
callq 0x4240
movq -0x20(%rbp), %rax
movl 0xcc(%rax), %eax
movl %eax, -0x45c(%rbp)
movq -0x20(%rbp), %rax
movl 0xcc(%rax), %edi
leaq -0x420(%rbp), %rsi
movl $0x400, %edx            # imm = 0x400
callq 0x43770
movq %rax, -0x458(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x43520
movl -0x45c(%rbp), %ecx
movq -0x458(%rbp), %r8
movq %rax, %r9
movq -0x20(%rbp), %rax
movq (%rax), %rax
addq $0x1, %rax
movl $0x1, %edi
leaq 0xc48ea(%rip), %rsi     # 0x107b54
leaq 0xc4950(%rip), %rdx     # 0x107bc1
movq %rax, (%rsp)
movb $0x0, %al
callq 0x9d90
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43514
movq -0x20(%rbp), %rdi
callq 0x42700
movq -0x20(%rbp), %rax
movl 0xbc(%rax), %eax
andl $0x40000000, %eax       # imm = 0x40000000
cmpl $0x0, %eax
je 0x432e6
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x43520
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq (%rax), %r8
addq $0x1, %r8
movl $0x1, %edi
leaq 0xc4888(%rip), %rsi     # 0x107b54
leaq 0xc4910(%rip), %rdx     # 0x107be3
movb $0x0, %al
callq 0x9d90
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43514
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movq %rax, -0x428(%rbp)
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rax
addq $0x18, %rax
movl %eax, %edi
leaq -0x450(%rbp), %rsi
callq 0x40b90
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rax
movl %eax, %edi
leaq -0x450(%rbp), %rsi
addq $0x4, %rsi
callq 0x40b90
movq -0x20(%rbp), %rax
movl 0x10(%rax), %edi
leaq -0x450(%rbp), %rsi
addq $0x8, %rsi
callq 0x43890
movq -0x20(%rbp), %rax
movq (%rax), %rax
movl %eax, %edi
leaq -0x450(%rbp), %rsi
addq $0xc, %rsi
callq 0x40b90
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movl %eax, %edi
leaq -0x450(%rbp), %rsi
addq $0x10, %rsi
callq 0x40b90
movq -0x20(%rbp), %rax
movss 0x14(%rax), %xmm0
leaq -0x450(%rbp), %rdi
addq $0x14, %rdi
callq 0x438c0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
andq $0xffff, %rax           # imm = 0xFFFF
leaq -0x450(%rbp), %rsi
addq $0x18, %rsi
movzwl %ax, %edi
callq 0x438f0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x10, %rax
andq $0xffff, %rax           # imm = 0xFFFF
leaq -0x450(%rbp), %rsi
addq $0x1a, %rsi
movzwl %ax, %edi
callq 0x438f0
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x20, %rax
andq $0xff, %rax
movl %eax, %edi
shll $0x18, %edi
movq -0x20(%rbp), %rax
movq 0x18(%rax), %rax
shrq $0x28, %rax
andl $0xffffff, %eax         # imm = 0xFFFFFF
orl %eax, %edi
leaq -0x450(%rbp), %rsi
addq $0x1c, %rsi
callq 0x40b90
movq -0x428(%rbp), %rdi
leaq -0x450(%rbp), %rsi
movl $0x20, %edx
callq 0xdb250
cmpq $0x20, %rax
je 0x43436
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43514
movq -0x428(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x30(%rax), %rsi
movq -0x20(%rbp), %rax
movq 0x20(%rax), %rdx
callq 0xdb250
movq -0x20(%rbp), %rcx
cmpq 0x20(%rcx), %rax
je 0x43468
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43514
movq -0x428(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x48(%rax), %rsi
movq -0x20(%rbp), %rax
movq 0x38(%rax), %rdx
callq 0xdb250
movq -0x20(%rbp), %rcx
cmpq 0x38(%rcx), %rax
je 0x43497
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43514
movq -0x10(%rbp), %rax
cmpq $0x0, 0x68(%rax)
je 0x4350d
movq -0x428(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rsi
movq -0x20(%rbp), %rax
movl 0x10(%rax), %edx
movq -0x20(%rbp), %rax
movq (%rax), %rcx
movq -0x20(%rbp), %rax
movq (%rax), %r8
movq -0x20(%rbp), %rax
addq 0x8(%rax), %r8
movq -0x428(%rbp), %rax
movq 0x18(%rax), %r9
shlq $0x10, %r9
movq -0x428(%rbp), %rax
movl 0x10(%rax), %eax
andl $0xffff, %eax           # imm = 0xFFFF
cltq
orq %rax, %r9
movl $0x1, (%rsp)
callq 0xd7160
cmpl $0x0, %eax
jge 0x4350b
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0x43514
jmp 0x4350d
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x470, %rsp            # imm = 0x470
popq %rbp
retq