// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/test/test-vcf-api.c
// Function: bcf_to_vcf
void bcf_to_vcf(char *fname)
{
    htsFile *fp    = hts_open(fname,"rb");
    if (!fp) error("Failed to open \"%s\" : %s", fname, strerror(errno));
    bcf_hdr_t *hdr = bcf_hdr_read(fp);
    if (!hdr) error("bcf_hdr_read : %s", strerror(errno));
    bcf1_t *rec    = bcf_init1();
    if (!rec) error("bcf_init1 : %s", strerror(errno));

    char *gz_fname = (char*) malloc(strlen(fname)+4);
    if (!gz_fname) error("malloc : %s", strerror(errno));
    snprintf(gz_fname,strlen(fname)+4,"%s.gz",fname);
    htsFile *out   = hts_open(gz_fname,"wg");
    if (!out) error("Couldn't open \"%s\" : %s\n", gz_fname, strerror(errno));

    bcf_hdr_t *hdr_out = bcf_hdr_dup(hdr);
    if (!bcf_hdr_get_hrec(hdr_out, BCF_HL_STR,"ID","BB","unused"))
        error("Missing header ##unused=<ID=BB, ...>");
    bcf_hdr_remove(hdr_out,BCF_HL_STR,"BB");
    if (bcf_hdr_get_hrec(hdr_out, BCF_HL_STR,"ID","BB","unused"))
        error("Got pointer to deleted header ##unused=<ID=BB, ...>");

    if (!bcf_hdr_get_hrec(hdr_out,BCF_HL_GEN,"unused","unformatted text 1",NULL))
        error("Missing header ##unused=unformatted text 1");
    bcf_hdr_remove(hdr_out,BCF_HL_GEN,"unused");
    if (bcf_hdr_get_hrec(hdr_out,BCF_HL_GEN,"unused","unformatted text 1",NULL))
        error("Got pointer to deleted header ##unused=unformatted text 1");

    if (!bcf_hdr_get_hrec(hdr_out,BCF_HL_FLT,"ID","Flt",NULL))
        error("Missing header ##FILTER=<ID=Flt, ...>");
    bcf_hdr_remove(hdr_out,BCF_HL_FLT,"Flt");
    if (bcf_hdr_get_hrec(hdr_out,BCF_HL_FLT,"ID","Flt",NULL))
        error("Got pointer to deleted header ##FILTER=<ID=Flt, ...>");

    if (!bcf_hdr_get_hrec(hdr_out,BCF_HL_INFO,"ID","UI",NULL))
        error("Missing header ##INFO=<ID=UI, ...>");
    bcf_hdr_remove(hdr_out,BCF_HL_INFO,"UI");
    if (bcf_hdr_get_hrec(hdr_out,BCF_HL_INFO,"ID","UI",NULL))
        error("Got pointer to deleted header ##INFO=<ID=UI, ...>");

    if (!bcf_hdr_get_hrec(hdr_out,BCF_HL_FMT,"ID","UF",NULL))
        error("Missing header ##INFO=<ID=UF, ...>");
    bcf_hdr_remove(hdr_out,BCF_HL_FMT,"UF");
    if (bcf_hdr_get_hrec(hdr_out,BCF_HL_FMT,"ID","UF",NULL))
        error("Got pointer to deleted header ##INFO=<ID=UF, ...>");

    if (!bcf_hdr_get_hrec(hdr_out,BCF_HL_CTG,"ID","Unused",NULL))
        error("Missing header ##contig=<ID=Unused,length=1>");
    bcf_hdr_remove(hdr_out,BCF_HL_CTG,"Unused");
    if (bcf_hdr_get_hrec(hdr_out,BCF_HL_FMT,"ID","Unused",NULL))
        error("Got pointer to header ##contig=<ID=Unused,length=1>");

    if ( bcf_hdr_write(out, hdr_out)!=0 ) error("Failed to write to %s\n", fname);
    int r;
    while ((r = bcf_read1(fp, hdr, rec)) >= 0)
    {
        if ( bcf_write1(out, hdr_out, rec)!=0 ) error("Failed to write to %s\n", fname);

        // Test problems caused by bcf1_sync: the data block
        // may be realloced, also the unpacked structures must
        // get updated.
        check0(bcf_unpack(rec, BCF_UN_STR));
        check0(bcf_update_id(hdr, rec, 0));
        check0(bcf_update_format_int32(hdr, rec, "GQ", NULL, 0));

        bcf1_t *dup = bcf_dup(rec);     // force bcf1_sync call
        if ( bcf_write1(out, hdr_out, dup)!=0 ) error("Failed to write to %s\n", fname);
        bcf_destroy1(dup);

        check0(bcf_update_alleles_str(hdr_out, rec, "G,A"));
        int32_t tmpi = 99;
        check0(bcf_update_info_int32(hdr_out, rec, "DP", &tmpi, 1));
        int32_t tmpia[] = {9,9,9};
        check0(bcf_update_format_int32(hdr_out, rec, "DP", tmpia, 3));

        if ( bcf_write1(out, hdr_out, rec)!=0 ) error("Failed to write to %s\n", fname);
    }
    if (r < -1) error("bcf_read1");

    bcf_destroy1(rec);
    bcf_hdr_destroy(hdr);
    bcf_hdr_destroy(hdr_out);
    int ret;
    if ( (ret=hts_close(fp)) )
    {
        fprintf(stderr,"hts_close(%s): non-zero status %d\n",fname,ret);
        exit(ret);
    }
    if ( (ret=hts_close(out)) )
    {
        fprintf(stderr,"hts_close(%s): non-zero status %d\n",gz_fname,ret);
        exit(ret);
    }


    // read gzip, write stdout
    htsFile *gz_in = hts_open(gz_fname, "r");
    if ( !gz_in )
    {
        fprintf(stderr,"Could not read: %s\n", gz_fname);
        exit(1);
    }

    kstring_t line = {0,0,0};
    while ( hts_getline(gz_in, KS_SEP_LINE, &line)>0 )
    {
        kputc('\n',&line);
        fwrite(line.s,1,line.l,stdout);
    }

    if ( (ret=hts_close(gz_in)) )
    {
        fprintf(stderr,"hts_close(%s): non-zero status %d\n",gz_fname,ret);
        exit(ret);
    }
    free(line.s);
    free(gz_fname);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %r15
leaq 0xa4379(%rip), %rsi     # 0xab6fb
callq 0xbbc0
testq %rax, %rax
je 0x79b3
movq %rax, %rbx
movq %rax, %rdi
callq 0x30c97
testq %rax, %rax
je 0x79cb
movq %rax, %r12
movq %rbx, 0x28(%rsp)
callq 0x31d1e
testq %rax, %rax
je 0x79e0
movq %rax, %r13
movq %r15, %rdi
callq 0x41c0
movq %rax, %rbx
addq $0x4, %rbx
movq %rbx, %rdi
callq 0x46a0
testq %rax, %rax
je 0x79f5
movq %rax, %r14
leaq 0xa4335(%rip), %rdx     # 0xab71c
movq %rax, %rdi
movq %rbx, %rsi
movq %r15, 0x18(%rsp)
movq %r15, %rcx
xorl %eax, %eax
callq 0x4820
leaq 0xa431f(%rip), %rsi     # 0xab722
movq %r14, 0x20(%rsp)
movq %r14, %rdi
callq 0xbbc0
testq %rax, %rax
je 0x7a0d
movq %rax, %rbp
movq %r12, %rdi
callq 0x3f0c0
movq %rax, %r14
leaq 0xa4310(%rip), %rdx     # 0xab73e
leaq 0xa430c(%rip), %rcx     # 0xab741
leaq 0xa4308(%rip), %r8      # 0xab744
movq %rax, %rdi
movl $0x4, %esi
callq 0x2f4d1
testq %rax, %rax
je 0x7a2f
leaq 0xa42e8(%rip), %rbx     # 0xab741
movq %r14, %rdi
movl $0x4, %esi
movq %rbx, %rdx
callq 0x2fdeb
leaq 0xa42ce(%rip), %rdx     # 0xab73e
leaq 0xa42cd(%rip), %r8      # 0xab744
movq %r14, %rdi
movl $0x4, %esi
movq %rbx, %rcx
callq 0x2f4d1
testq %rax, %rax
jne 0x7a38
leaq 0xa42ad(%rip), %rdx     # 0xab744
leaq 0xa4358(%rip), %rcx     # 0xab7f6
movq %r14, %rdi
movl $0x5, %esi
xorl %r8d, %r8d
callq 0x2f4d1
testq %rax, %rax
je 0x7a41
leaq 0xa4286(%rip), %rbx     # 0xab744
movq %r14, %rdi
movl $0x5, %esi
movq %rbx, %rdx
callq 0x2fdeb
leaq 0xa4321(%rip), %rcx     # 0xab7f6
movq %r14, %rdi
movl $0x5, %esi
movq %rbx, %rdx
xorl %r8d, %r8d
callq 0x2f4d1
testq %rax, %rax
jne 0x7a4a
leaq 0xa4246(%rip), %rdx     # 0xab73e
leaq 0xa430a(%rip), %rcx     # 0xab809
movq %r14, %rdi
xorl %esi, %esi
xorl %r8d, %r8d
callq 0x2f4d1
testq %rax, %rax
je 0x7a53
leaq 0xa42ed(%rip), %rbx     # 0xab809
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x2fdeb
leaq 0xa420e(%rip), %rdx     # 0xab73e
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x2f4d1
testq %rax, %rax
jne 0x7a5c
leaq 0xa41ee(%rip), %rdx     # 0xab73e
leaq 0xa4311(%rip), %rcx     # 0xab868
movq %r14, %rdi
movl $0x1, %esi
xorl %r8d, %r8d
callq 0x2f4d1
testq %rax, %rax
je 0x7a65
leaq 0xa42f1(%rip), %rbx     # 0xab868
movq %r14, %rdi
movl $0x1, %esi
movq %rbx, %rdx
callq 0x2fdeb
leaq 0xa41b0(%rip), %rdx     # 0xab73e
movq %r14, %rdi
movl $0x1, %esi
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x2f4d1
testq %rax, %rax
jne 0x7a6e
leaq 0xa418d(%rip), %rdx     # 0xab73e
leaq 0xa4308(%rip), %rcx     # 0xab8c0
movq %r14, %rdi
movl $0x2, %esi
xorl %r8d, %r8d
callq 0x2f4d1
testq %rax, %rax
je 0x7a77
leaq 0xa42e8(%rip), %rbx     # 0xab8c0
movq %r14, %rdi
movl $0x2, %esi
movq %rbx, %rdx
callq 0x2fdeb
leaq 0xa414f(%rip), %rdx     # 0xab73e
movq %r14, %rdi
movl $0x2, %esi
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x2f4d1
testq %rax, %rax
jne 0x7a80
leaq 0xa412c(%rip), %rdx     # 0xab73e
leaq 0xa3920(%rip), %rcx     # 0xaaf39
movq %r14, %rdi
movl $0x3, %esi
xorl %r8d, %r8d
callq 0x2f4d1
testq %rax, %rax
je 0x7a89
leaq 0xa3900(%rip), %rbx     # 0xaaf39
movq %r14, %rdi
movl $0x3, %esi
movq %rbx, %rdx
callq 0x2fdeb
leaq 0xa40ee(%rip), %rdx     # 0xab73e
movq %r14, %rdi
movl $0x2, %esi
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x2f4d1
testq %rax, %rax
jne 0x7a92
movq %rbp, %rdi
movq %r14, %rsi
callq 0x3196a
testl %eax, %eax
movq 0x28(%rsp), %rbx
jne 0x7940
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x322f9
testl %eax, %eax
js 0x77e6
leaq 0xa3c86(%rip), %rbx     # 0xab327
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x33c66
testl %eax, %eax
jne 0x7940
movq %r13, %rdi
movl $0x1, %esi
callq 0x3a803
testl %eax, %eax
jne 0x799e
movq %r12, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x427c1
testl %eax, %eax
jne 0x798e
movq %r12, %rdi
movq %r13, %rsi
leaq 0xa3d85(%rip), %rdx     # 0xab473
xorl %ecx, %ecx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x4168f
testl %eax, %eax
jne 0x797e
movq %r13, %rdi
callq 0x33c47
movq %rax, %r15
movq %rbp, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x33c66
testl %eax, %eax
jne 0x7940
movq %r15, %rdi
callq 0x31ec9
movq %r14, %rdi
movq %r13, %rsi
leaq 0xa3b43(%rip), %rdx     # 0xab27f
callq 0x4263b
testl %eax, %eax
jne 0x796e
movl $0x63, 0x34(%rsp)
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
leaq 0x34(%rsp), %rcx
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x40f50
testl %eax, %eax
jne 0x795e
movabsq $0x900000009, %rax      # imm = 0x900000009
movq %rax, (%rsp)
movl $0x9, 0x8(%rsp)
movq %r14, %rdi
movq %r13, %rsi
movq %rbx, %rdx
movq %rsp, %rcx
movl $0x3, %r8d
movl $0x1, %r9d
callq 0x4168f
testl %eax, %eax
jne 0x794e
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x33c66
testl %eax, %eax
jne 0x7940
movq 0x28(%rsp), %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x322f9
testl %eax, %eax
jns 0x76a1
movq 0x28(%rsp), %rbx
cmpl $-0x1, %eax
jne 0x7a9b
movq %r13, %rdi
callq 0x31ec9
movq %r12, %rdi
callq 0x30af4
movq %r14, %rdi
callq 0x30af4
movq %rbx, %rdi
callq 0xce22
testl %eax, %eax
jne 0x7aa9
movq %rbp, %rdi
callq 0xce22
testl %eax, %eax
jne 0x7ab5
leaq 0xa7d16(%rip), %rsi     # 0xaf544
movq 0x20(%rsp), %rbp
movq %rbp, %rdi
callq 0xbbc0
testq %rax, %rax
je 0x7ac1
movq %rax, %rbx
xorps %xmm0, %xmm0
movq %rsp, %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
movq %rax, %rdi
movl $0x2, %esi
callq 0xd40a
testl %eax, %eax
jle 0x790f
xorl %r12d, %r12d
movq 0xca749(%rip), %r13     # 0xd1fc0
movq %rsp, %r14
movq (%rsp), %rcx
leaq 0x2(%rcx), %rax
cmpq %rax, 0x8(%rsp)
jae 0x78c2
movq %rax, %rcx
shrq $0x3e, %rcx
movq %rax, %r15
shrq %r15
testq %rcx, %rcx
cmovneq %r12, %r15
addq %rax, %r15
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x4860
testq %rax, %rax
je 0x78e0
movq %rax, 0x10(%rsp)
movq %r15, 0x8(%rsp)
movq (%rsp), %rcx
jmp 0x78c7
movq 0x10(%rsp), %rax
leaq 0x1(%rcx), %rdx
movq %rdx, (%rsp)
movb $0xa, (%rax,%rcx)
movq (%rsp), %rax
movq 0x10(%rsp), %rcx
movb $0x0, (%rcx,%rax)
movq (%rsp), %rdx
movq 0x10(%rsp), %rdi
movq (%r13), %rcx
movl $0x1, %esi
callq 0x49b0
movq %rbx, %rdi
movl $0x2, %esi
movq %r14, %rdx
callq 0xd40a
testl %eax, %eax
jg 0x787a
movq %rbx, %rdi
callq 0xce22
testl %eax, %eax
jne 0x7ac9
movq 0x10(%rsp), %rdi
callq 0x45c0
movq %rbp, %rdi
callq 0x45c0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xa38ef(%rip), %rdi     # 0xab236
movq 0x18(%rsp), %rsi
jmp 0x79ac
leaq 0xa2734(%rip), %rdi     # 0xaa089
leaq 0xa40e6(%rip), %rsi     # 0xaba42
jmp 0x79ac
leaq 0xa2724(%rip), %rdi     # 0xaa089
leaq 0xa40a0(%rip), %rsi     # 0xaba0c
jmp 0x79ac
leaq 0xa2714(%rip), %rdi     # 0xaa089
leaq 0xa4064(%rip), %rsi     # 0xab9e0
jmp 0x79ac
leaq 0xa2704(%rip), %rdi     # 0xaa089
leaq 0xa401b(%rip), %rsi     # 0xab9a7
jmp 0x79ac
leaq 0xa26f4(%rip), %rdi     # 0xaa089
leaq 0xa3ff0(%rip), %rsi     # 0xab98c
jmp 0x79ac
leaq 0xa26e4(%rip), %rdi     # 0xaa089
leaq 0xa3fcd(%rip), %rsi     # 0xab979
xorl %eax, %eax
callq 0x602c
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0xa2689(%rip), %rdi     # 0xaa04f
movq %r15, %rsi
jmp 0x7a25
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0xa3d20(%rip), %rdi     # 0xab6fe
jmp 0x7a08
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0xa2687(%rip), %rdi     # 0xaa07a
jmp 0x7a08
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0xa3d08(%rip), %rdi     # 0xab710
movq %rax, %rsi
jmp 0x79ac
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0xa3d05(%rip), %rdi     # 0xab725
movq 0x20(%rsp), %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x602c
leaq 0xa3d15(%rip), %rdi     # 0xab74b
jmp 0x7aa2
leaq 0xa3d31(%rip), %rdi     # 0xab770
jmp 0x7aa2
leaq 0xa3d5c(%rip), %rdi     # 0xab7a4
jmp 0x7aa2
leaq 0xa3d7e(%rip), %rdi     # 0xab7cf
jmp 0x7aa2
leaq 0xa3db3(%rip), %rdi     # 0xab80d
jmp 0x7aa2
leaq 0xa3dd0(%rip), %rdi     # 0xab833
jmp 0x7aa2
leaq 0xa3dff(%rip), %rdi     # 0xab86b
jmp 0x7aa2
leaq 0xa3e19(%rip), %rdi     # 0xab88e
jmp 0x7aa2
leaq 0xa3e45(%rip), %rdi     # 0xab8c3
jmp 0x7aa2
leaq 0xa3e5f(%rip), %rdi     # 0xab8e6
jmp 0x7aa2
leaq 0xa3e88(%rip), %rdi     # 0xab918
jmp 0x7aa2
leaq 0xa3eac(%rip), %rdi     # 0xab945
jmp 0x7aa2
leaq 0xa3fd8(%rip), %rdi     # 0xaba7a
xorl %eax, %eax
callq 0x602c
movq 0x18(%rsp), %rdi
movl %eax, %esi
callq 0x4a07
movq 0x20(%rsp), %rdi
movl %eax, %esi
callq 0x4a2e
movq %rbp, %rdi
callq 0x4a7c
movq %rbp, %rdi
movl %eax, %esi
callq 0x4a55