// File: /workspace/github_c_makefile_star2_O1/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, %r14
leaq 0xa639a(%rip), %rsi     # 0xad6fb
callq 0xbee7
testq %rax, %rax
je 0x7996
movq %rax, %r15
movq %rax, %rdi
callq 0x31e8f
testq %rax, %rax
je 0x79ae
movq %rax, 0x28(%rsp)
callq 0x32e93
testq %rax, %rax
je 0x79c3
movq %rax, %r13
movq %r14, %rdi
callq 0x41c0
leaq 0x4(%rax), %rdi
callq 0x46a0
testq %rax, %rax
je 0x79d8
movq %rax, %rbx
movq %r14, %rdi
callq 0x41c0
leaq 0x4(%rax), %rsi
leaq 0xa6353(%rip), %rdx     # 0xad71c
movq %rbx, %rdi
movq %r14, 0x18(%rsp)
movq %r14, %rcx
xorl %eax, %eax
callq 0x4820
leaq 0xa6340(%rip), %rsi     # 0xad722
movq %rbx, 0x20(%rsp)
movq %rbx, %rdi
callq 0xbee7
testq %rax, %rax
je 0x79f0
movq %rax, %rbp
movq 0x28(%rsp), %rdi
callq 0x3feb9
movq %rax, %r14
leaq 0xa632f(%rip), %rdx     # 0xad73e
leaq 0xa632b(%rip), %rcx     # 0xad741
leaq 0xa6327(%rip), %r8      # 0xad744
movq %rax, %rdi
movl $0x4, %esi
callq 0x30650
testq %rax, %rax
je 0x7a12
leaq 0xa6307(%rip), %rbx     # 0xad741
movq %r14, %rdi
movl $0x4, %esi
movq %rbx, %rdx
callq 0x30f91
leaq 0xa62ed(%rip), %rdx     # 0xad73e
leaq 0xa62ec(%rip), %r8      # 0xad744
movq %r14, %rdi
movl $0x4, %esi
movq %rbx, %rcx
callq 0x30650
testq %rax, %rax
jne 0x7a1b
leaq 0xa62cc(%rip), %rdx     # 0xad744
leaq 0xa6377(%rip), %rcx     # 0xad7f6
movq %r14, %rdi
movl $0x5, %esi
xorl %r8d, %r8d
callq 0x30650
testq %rax, %rax
je 0x7a24
leaq 0xa62a5(%rip), %rbx     # 0xad744
movq %r14, %rdi
movl $0x5, %esi
movq %rbx, %rdx
callq 0x30f91
leaq 0xa6340(%rip), %rcx     # 0xad7f6
movq %r14, %rdi
movl $0x5, %esi
movq %rbx, %rdx
xorl %r8d, %r8d
callq 0x30650
testq %rax, %rax
jne 0x7a2d
leaq 0xa6265(%rip), %rdx     # 0xad73e
leaq 0xa6329(%rip), %rcx     # 0xad809
movq %r14, %rdi
xorl %esi, %esi
xorl %r8d, %r8d
callq 0x30650
testq %rax, %rax
je 0x7a36
leaq 0xa630c(%rip), %rbx     # 0xad809
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x30f91
leaq 0xa622d(%rip), %rdx     # 0xad73e
movq %r14, %rdi
xorl %esi, %esi
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x30650
testq %rax, %rax
jne 0x7a3f
leaq 0xa620d(%rip), %rdx     # 0xad73e
leaq 0xa6330(%rip), %rcx     # 0xad868
movq %r14, %rdi
movl $0x1, %esi
xorl %r8d, %r8d
callq 0x30650
testq %rax, %rax
je 0x7a48
leaq 0xa6310(%rip), %rbx     # 0xad868
movq %r14, %rdi
movl $0x1, %esi
movq %rbx, %rdx
callq 0x30f91
leaq 0xa61cf(%rip), %rdx     # 0xad73e
movq %r14, %rdi
movl $0x1, %esi
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x30650
testq %rax, %rax
jne 0x7a51
leaq 0xa61ac(%rip), %rdx     # 0xad73e
leaq 0xa6327(%rip), %rcx     # 0xad8c0
movq %r14, %rdi
movl $0x2, %esi
xorl %r8d, %r8d
callq 0x30650
testq %rax, %rax
je 0x7a5a
leaq 0xa6307(%rip), %rbx     # 0xad8c0
movq %r14, %rdi
movl $0x2, %esi
movq %rbx, %rdx
callq 0x30f91
leaq 0xa616e(%rip), %rdx     # 0xad73e
movq %r14, %rdi
movl $0x2, %esi
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x30650
testq %rax, %rax
jne 0x7a63
leaq 0xa614b(%rip), %rdx     # 0xad73e
leaq 0xa593f(%rip), %rcx     # 0xacf39
movq %r14, %rdi
movl $0x3, %esi
xorl %r8d, %r8d
callq 0x30650
testq %rax, %rax
je 0x7a6c
leaq 0xa591f(%rip), %rbx     # 0xacf39
movq %r14, %rdi
movl $0x3, %esi
movq %rbx, %rdx
callq 0x30f91
leaq 0xa610d(%rip), %rdx     # 0xad73e
movq %r14, %rdi
movl $0x2, %esi
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x30650
testq %rax, %rax
jne 0x7a75
movq %rbp, %rdi
movq %r14, %rsi
callq 0x32ad4
testl %eax, %eax
movq 0x28(%rsp), %rbx
jne 0x7923
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x3346e
testl %eax, %eax
js 0x77cb
leaq 0xa5ca5(%rip), %r12     # 0xad327
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x34dc3
testl %eax, %eax
jne 0x7923
movq %r13, %rdi
movl $0x1, %esi
callq 0x3b4fd
testl %eax, %eax
jne 0x7981
movq %rbx, %rdi
movq %r13, %rsi
xorl %edx, %edx
callq 0x43615
testl %eax, %eax
jne 0x7971
movq %rbx, %rdi
movq %r15, %rbx
movq %r13, %rsi
leaq 0xa5da1(%rip), %rdx     # 0xad473
xorl %ecx, %ecx
xorl %r8d, %r8d
movl $0x1, %r9d
callq 0x42483
testl %eax, %eax
jne 0x7961
movq %r13, %rdi
callq 0x34da4
movq %rax, %r15
movq %rbp, %rdi
movq %r14, %rsi
movq %rax, %rdx
callq 0x34dc3
testl %eax, %eax
jne 0x7923
movq %r15, %rdi
callq 0x33036
movq %r14, %rdi
movq %r13, %rsi
leaq 0xa5b5f(%rip), %rdx     # 0xad27f
callq 0x4348f
testl %eax, %eax
jne 0x7951
movl $0x63, 0x34(%rsp)
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
leaq 0x34(%rsp), %rcx
movl $0x1, %r8d
movl $0x1, %r9d
callq 0x41ced
testl %eax, %eax
jne 0x7941
movq %rbx, %r15
movabsq $0x900000009, %rax      # imm = 0x900000009
movq %rax, (%rsp)
movl $0x9, 0x8(%rsp)
movq %r14, %rdi
movq %r13, %rsi
movq %r12, %rdx
movq %rsp, %rcx
movl $0x3, %r8d
movl $0x1, %r9d
callq 0x42483
testl %eax, %eax
movq 0x28(%rsp), %rbx
jne 0x7931
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x34dc3
testl %eax, %eax
jne 0x7923
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
callq 0x3346e
testl %eax, %eax
jns 0x7682
cmpl $-0x1, %eax
jne 0x7a7e
movq %r13, %rdi
callq 0x33036
movq %rbx, %rdi
callq 0x31cf6
movq %r14, %rdi
callq 0x31cf6
movq %r15, %rdi
callq 0xd151
testl %eax, %eax
jne 0x7a8c
movq %rbp, %rdi
callq 0xd151
testl %eax, %eax
jne 0x7a98
leaq 0xa9d86(%rip), %rsi     # 0xb1599
movq 0x20(%rsp), %rbp
movq %rbp, %rdi
callq 0xbee7
testq %rax, %rax
je 0x7aa4
movq %rax, %rbx
xorps %xmm0, %xmm0
movq %rsp, %rdx
movaps %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
movq %rax, %rdi
movl $0x2, %esi
callq 0xd731
testl %eax, %eax
jle 0x78f2
xorl %r12d, %r12d
movq 0xcc764(%rip), %r13     # 0xd3fc0
movq %rsp, %r14
movq (%rsp), %rax
addq $0x2, %rax
cmpq %rax, 0x8(%rsp)
jae 0x78a1
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 0x78c3
movq %rax, 0x10(%rsp)
movq %r15, 0x8(%rsp)
movq (%rsp), %rax
movq 0x10(%rsp), %rcx
leaq 0x1(%rax), %rdx
movq %rdx, (%rsp)
movb $0xa, (%rcx,%rax)
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 0xd731
testl %eax, %eax
jg 0x785f
movq %rbx, %rdi
callq 0xd151
testl %eax, %eax
jne 0x7aac
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 0xa590c(%rip), %rdi     # 0xad236
movq 0x18(%rsp), %rsi
jmp 0x798f
leaq 0xa4751(%rip), %rdi     # 0xac089
leaq 0xa6103(%rip), %rsi     # 0xada42
jmp 0x798f
leaq 0xa4741(%rip), %rdi     # 0xac089
leaq 0xa60bd(%rip), %rsi     # 0xada0c
jmp 0x798f
leaq 0xa4731(%rip), %rdi     # 0xac089
leaq 0xa6081(%rip), %rsi     # 0xad9e0
jmp 0x798f
leaq 0xa4721(%rip), %rdi     # 0xac089
leaq 0xa6038(%rip), %rsi     # 0xad9a7
jmp 0x798f
leaq 0xa4711(%rip), %rdi     # 0xac089
leaq 0xa600d(%rip), %rsi     # 0xad98c
jmp 0x798f
leaq 0xa4701(%rip), %rdi     # 0xac089
leaq 0xa5fea(%rip), %rsi     # 0xad979
xorl %eax, %eax
callq 0x600c
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0xa46a6(%rip), %rdi     # 0xac04f
movq %r14, %rsi
jmp 0x7a08
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0xa5d3d(%rip), %rdi     # 0xad6fe
jmp 0x79eb
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0xa46a4(%rip), %rdi     # 0xac07a
jmp 0x79eb
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0xa5d25(%rip), %rdi     # 0xad710
movq %rax, %rsi
jmp 0x798f
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0xa5d22(%rip), %rdi     # 0xad725
movq 0x20(%rsp), %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x600c
leaq 0xa5d32(%rip), %rdi     # 0xad74b
jmp 0x7a85
leaq 0xa5d4e(%rip), %rdi     # 0xad770
jmp 0x7a85
leaq 0xa5d79(%rip), %rdi     # 0xad7a4
jmp 0x7a85
leaq 0xa5d9b(%rip), %rdi     # 0xad7cf
jmp 0x7a85
leaq 0xa5dd0(%rip), %rdi     # 0xad80d
jmp 0x7a85
leaq 0xa5ded(%rip), %rdi     # 0xad833
jmp 0x7a85
leaq 0xa5e1c(%rip), %rdi     # 0xad86b
jmp 0x7a85
leaq 0xa5e36(%rip), %rdi     # 0xad88e
jmp 0x7a85
leaq 0xa5e62(%rip), %rdi     # 0xad8c3
jmp 0x7a85
leaq 0xa5e7c(%rip), %rdi     # 0xad8e6
jmp 0x7a85
leaq 0xa5ea5(%rip), %rdi     # 0xad918
jmp 0x7a85
leaq 0xa5ec9(%rip), %rdi     # 0xad945
jmp 0x7a85
leaq 0xa5ff5(%rip), %rdi     # 0xada7a
xorl %eax, %eax
callq 0x600c
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