// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/test/test-bcf-sr.c
// Function: main
int main(int argc, char *argv[])
{
    static struct option loptions[] =
    {
        {"help",no_argument,NULL,'h'},
        {"output-fmt",required_argument,NULL,'O'},
        {"pair",required_argument,NULL,'p'},
        {"regions",required_argument,NULL,'r'},
        {"targets",required_argument,NULL,'t'},
        {"no-index",no_argument,NULL,1000},
        {"args",no_argument,NULL,1001},
        {"usefptr",no_argument,NULL,'u'},
        {NULL,0,NULL,0}
    };

    int c, pair = 0, use_index = 1, use_fofn = 1, usefptr = 0;
    enum htsExactFormat out_fmt = text_format; // for original pos + alleles
    const char *out_fn = NULL, *regions = NULL, *targets = NULL;
    htsFile **htsfp = NULL;
    while ((c = getopt_long(argc, argv, "o:O:p:r:t:hu", loptions, NULL)) >= 0)
    {
        switch (c)
        {
            case 'o':
                out_fn = optarg;
                break;
            case 'O':
                if (!strcasecmp(optarg, "vcf"))          out_fmt = vcf;
                else if (!strcasecmp(optarg, "bcf"))     out_fmt = bcf;
                else if (!strcasecmp(optarg, "summary")) out_fmt = text_format;
                else error("Unknown output format \"%s\"\n", optarg);
                break;
            case 'p':
                if ( !strcmp(optarg,"snps") )            pair |= BCF_SR_PAIR_SNPS;
                else if ( !strcmp(optarg,"snp+ref") )    pair |= BCF_SR_PAIR_SNPS|BCF_SR_PAIR_SNP_REF;
                else if ( !strcmp(optarg,"snps+ref") )   pair |= BCF_SR_PAIR_SNPS|BCF_SR_PAIR_SNP_REF;
                else if ( !strcmp(optarg,"indels") )     pair |= BCF_SR_PAIR_INDELS;
                else if ( !strcmp(optarg,"indel+ref") )  pair |= BCF_SR_PAIR_INDELS|BCF_SR_PAIR_INDEL_REF;
                else if ( !strcmp(optarg,"indels+ref") ) pair |= BCF_SR_PAIR_INDELS|BCF_SR_PAIR_INDEL_REF;
                else if ( !strcmp(optarg,"both") )       pair |= BCF_SR_PAIR_BOTH;
                else if ( !strcmp(optarg,"both+ref") )   pair |= BCF_SR_PAIR_BOTH_REF;
                else if ( !strcmp(optarg,"any") )        pair |= BCF_SR_PAIR_ANY;
                else if ( !strcmp(optarg,"all") )        pair |= BCF_SR_PAIR_ANY;
                else if ( !strcmp(optarg,"some") )       pair |= BCF_SR_PAIR_SOME;
                else if ( !strcmp(optarg,"exact") )      pair  = BCF_SR_PAIR_EXACT;
                else error("The --pair logic \"%s\" not recognised.\n", optarg);
                break;
            case 'r':
                regions = optarg;
                break;
            case 't':
                targets = optarg;
                break;
            case 1000:
                use_index = 0;
                break;
            case 1001:
                use_fofn = 0;
                break;
            case 'u':
                usefptr = 1;    //use htsfile interface instead of fname i/f
                break;
            case 'h':
                usage(EXIT_SUCCESS);
            default: usage(EXIT_FAILURE);
        }
    }
    if ( !pair ) pair = BCF_SR_PAIR_EXACT;
    if ( optind == argc ) usage(EXIT_FAILURE);

    int i, nvcf;
    char **vcfs = NULL;
    if (use_fofn) {
        vcfs = hts_readlist(argv[optind], 1, &nvcf);
        if ( !vcfs ) error("Could not parse %s\n", argv[optind]);
    } else {
        vcfs = &argv[optind];
        nvcf = argc - optind;
    }

    bcf_srs_t *sr = bcf_sr_init();
    if (!sr) error("bcf_sr_init() failed\n");
    bcf_sr_set_opt(sr, BCF_SR_PAIR_LOGIC, pair);
    if (use_index) {
        bcf_sr_set_opt(sr, BCF_SR_REQUIRE_IDX);
    } else {
        bcf_sr_set_opt(sr, BCF_SR_ALLOW_NO_IDX);
    }

    if (regions)
    {
        if (bcf_sr_set_regions(sr, regions, 0) != 0)
            error("Failed to set regions\n");
    }

    if (targets)
    {
        if (bcf_sr_set_targets(sr, targets, 0, 0) != 0)
            error("Failed to set targets\n");
    }

    if (usefptr && !(htsfp = malloc(sizeof(htsFile*) * nvcf))) {
        error("Failed to allocate memory\n");
    }

    for (i=0; i<nvcf; i++) {
        if (!usefptr) {
            if ( !bcf_sr_add_reader(sr,vcfs[i]) ) {
                error("Failed to open %s: %s\n", vcfs[i],
                    bcf_sr_strerror(sr->errnum));
            }
        } else {    //use htsfile i/f
            if (!(htsfp[i] = hts_open(vcfs[i], "r"))) {
                error("Failed to open %s: %s\n", vcfs[i],
                    bcf_sr_strerror(sr->errnum));
            }
            /*with name, index can be anywhere, named as anything
              w/o name it has to be along with file with default naming*/

            const char *idxname = strstr(vcfs[i], HTS_IDX_DELIM);
            idxname += idxname ? sizeof(HTS_IDX_DELIM) - 1 : 0;
            if ( !bcf_sr_add_hreader(sr, htsfp[i], 1, idxname) ) {
                error("Failed to add reader %s: %s\n", vcfs[i],
                    bcf_sr_strerror(sr->errnum));
            }
        }
    }

    if (!sr->readers || sr->nreaders < 1)
        error("No readers set, even though one was added\n");

    if (out_fmt == text_format) {
        FILE *out = stdout;
        if (out_fn)
        {
            out = fopen(out_fn, "w");
            if (!out) error("Couldn't open \"%s\" for writing: %s\n",
                            out_fn, strerror(errno));
        }
        write_summary_format(sr, out);
        if (out_fn)
        {
            if (fclose(out) != 0)
                error("Error on closing %s : %s\n",
                      out_fn, strerror(errno));
        }
    } else {
        const char *fmt_type = out_fmt == vcf ? "VCF" : "BCF";

        bcf_hdr_t *hdr = bcf_sr_get_header(sr, 0);
        if (!hdr) error("%s output, but don't have a header\n", fmt_type);

        if (!out_fn) { out_fn = "-"; }
        vcfFile *vcf_out = vcf_open(out_fn, out_fmt == vcf ? "w" : "wb");
        if (!vcf_out) error("Couldn't open \"%s\" for writing: %s\n",
                            out_fn, strerror(errno));
        write_vcf_bcf_format(sr, hdr, vcf_out, fmt_type);
        if (vcf_close(vcf_out) != 0)
            error("Error on closing \"%s\"\n", out_fn);
    }

    if (sr->errnum) error("Synced reader error: %s\n",
                          bcf_sr_strerror(sr->errnum));

    bcf_sr_destroy(sr);
    if (use_fofn)
    {
        for (i=0; i<nvcf; i++)
            free(vcfs[i]);
        free(vcfs);
    }
    if (usefptr) {
        //files are closed along with sr destroy
        free(htsfp);
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rsi, %r15
movl %edi, %ebp
leaq 0xa8fd6(%rip), %rdx     # 0xaf355
leaq 0xd018a(%rip), %rcx     # 0xd6510
xorl %r8d, %r8d
callq 0x4890
testl %eax, %eax
js 0x66c2
movq $0x0, (%rsp)
movl $0x2, 0x10(%rsp)
movl $0x1, 0x8(%rsp)
leaq 0xa8c4f(%rip), %r12     # 0xaf004
leaq 0xa8f99(%rip), %r13     # 0xaf355
leaq 0xd014d(%rip), %rbx     # 0xd6510
movl $0x1, 0x24(%rsp)
movl $0x0, 0xc(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x28(%rsp)
movq $0x0, 0x18(%rsp)
cmpl $0x3e7, %eax            # imm = 0x3E7
jg 0x641a
leal -0x68(%rax), %ecx
cmpl $0xd, %ecx
ja 0x643d
movslq (%r12,%rcx,4), %rax
addq %r12, %rax
jmpq *%rax
movq 0xcfbb3(%rip), %rax     # 0xd5fc0
movq (%rax), %rax
movq %rax, 0x18(%rsp)
jmp 0x6628
cmpl $0x3e8, %eax            # imm = 0x3E8
je 0x65f6
cmpl $0x3e9, %eax            # imm = 0x3E9
jne 0x6a3d
movl $0x0, 0x24(%rsp)
jmp 0x6628
cmpl $0x4f, %eax
jne 0x6a3d
movq 0xcfb73(%rip), %rax     # 0xd5fc0
movq (%rax), %r14
movq %r14, %rdi
leaq 0xa9e29(%rip), %rsi     # 0xb0283
callq 0x4520
testl %eax, %eax
je 0x6616
movq %r14, %rdi
leaq 0xa9e17(%rip), %rsi     # 0xb0288
callq 0x4520
testl %eax, %eax
je 0x6620
movq %r14, %rdi
leaq 0xa8eda(%rip), %rsi     # 0xaf362
callq 0x4520
movl $0x2, 0x10(%rsp)
testl %eax, %eax
je 0x6628
jmp 0x6a71
movq 0xcfb17(%rip), %rax     # 0xd5fc0
movq (%rax), %r14
movq %r14, %rdi
leaq 0xa8ed0(%rip), %rsi     # 0xaf386
callq 0x46f0
testl %eax, %eax
je 0x6609
movq %r14, %rdi
leaq 0xa8ebe(%rip), %rsi     # 0xaf38b
callq 0x46f0
testl %eax, %eax
je 0x6600
movq %r14, %rdi
leaq 0xa8eaf(%rip), %rsi     # 0xaf393
callq 0x46f0
testl %eax, %eax
je 0x6600
movq %r14, %rdi
leaq 0xa8ea1(%rip), %rsi     # 0xaf39c
callq 0x46f0
testl %eax, %eax
je 0x664e
movq %r14, %rdi
leaq 0xa8e91(%rip), %rsi     # 0xaf3a3
callq 0x46f0
testl %eax, %eax
je 0x6645
movq %r14, %rdi
leaq 0xa8e84(%rip), %rsi     # 0xaf3ad
callq 0x46f0
testl %eax, %eax
je 0x6645
movq %r14, %rdi
leaq 0xa8e78(%rip), %rsi     # 0xaf3b8
callq 0x46f0
testl %eax, %eax
je 0x6657
movq %r14, %rdi
leaq 0xa8e66(%rip), %rsi     # 0xaf3bd
callq 0x46f0
testl %eax, %eax
je 0x6669
movq %r14, %rdi
leaq 0xa8e58(%rip), %rsi     # 0xaf3c6
callq 0x46f0
testl %eax, %eax
je 0x6660
movq %r14, %rdi
leaq 0xa9964(%rip), %rsi     # 0xafee9
callq 0x46f0
testl %eax, %eax
je 0x6660
movq %r14, %rdi
leaq 0xa8e2e(%rip), %rsi     # 0xaf3ca
callq 0x46f0
testl %eax, %eax
je 0x6672
movq %r14, %rdi
leaq 0xa8e1c(%rip), %rsi     # 0xaf3cf
callq 0x46f0
movl $0x40, %ecx
movq %rcx, (%rsp)
testl %eax, %eax
je 0x6628
jmp 0x6afd
movl $0x1, 0xc(%rsp)
jmp 0x6628
movq 0xcf9e5(%rip), %rax     # 0xd5fc0
movq (%rax), %rax
movq %rax, 0x30(%rsp)
jmp 0x6628
movq 0xcf9d4(%rip), %rax     # 0xd5fc0
movq (%rax), %rax
movq %rax, 0x28(%rsp)
jmp 0x6628
movl $0x0, 0x8(%rsp)
jmp 0x6628
movq (%rsp), %rax
orl $0x11, %eax
jmp 0x6610
movq (%rsp), %rax
orl $0x1, %eax
movq %rax, (%rsp)
jmp 0x6628
movl $0x8, 0x10(%rsp)
jmp 0x6628
movl $0x9, 0x10(%rsp)
movl %ebp, %edi
movq %r15, %rsi
movq %r13, %rdx
movq %rbx, %rcx
xorl %r8d, %r8d
callq 0x4890
testl %eax, %eax
jns 0x63ee
jmp 0x667b
movq (%rsp), %rax
orl $0x22, %eax
jmp 0x6610
movq (%rsp), %rax
orl $0x2, %eax
jmp 0x6610
movq (%rsp), %rax
orl $0x3, %eax
jmp 0x6610
movq (%rsp), %rax
orl $0x4, %eax
jmp 0x6610
movq (%rsp), %rax
orl $0x33, %eax
jmp 0x6610
movq (%rsp), %rax
orl $0x8, %eax
jmp 0x6610
cmpl $0x0, 0x8(%rsp)
sete %r12b
cmpl $0x0, 0xc(%rsp)
sete 0x8(%rsp)
movq (%rsp), %rax
testl %eax, %eax
movl $0x40, %r14d
cmovnel %eax, %r14d
movq 0xcf93b(%rip), %rax     # 0xd5fe0
movl (%rax), %eax
subl %eax, %ebp
je 0x6a3d
cmpl $0x0, 0x24(%rsp)
je 0x6722
movq 0x30(%rsp), %r13
movq 0x28(%rsp), %rbp
jmp 0x66f7
movq 0xcf917(%rip), %rax     # 0xd5fe0
movl (%rax), %eax
cmpl %ebp, %eax
je 0x6a3d
movl $0x40, %r14d
movl $0x2, 0x10(%rsp)
movb $0x1, 0x8(%rsp)
xorl %r12d, %r12d
xorl %r13d, %r13d
xorl %ebp, %ebp
movq $0x0, 0x18(%rsp)
cltq
movq (%r15,%rax,8), %rdi
leaq 0x14(%rsp), %rdx
movl $0x1, %esi
callq 0xb53f
testq %rax, %rax
je 0x6a7d
movq %rax, %rbx
movl $0x0, 0xc(%rsp)
jmp 0x673c
cltq
leaq (%r15,%rax,8), %rbx
movl %ebp, 0x14(%rsp)
movb $0x1, %al
movl %eax, 0xc(%rsp)
movq 0x30(%rsp), %r13
movq 0x28(%rsp), %rbp
callq 0x2a285
testq %rax, %rax
je 0x6a57
movq %rax, %r15
movq %rax, %rdi
movl $0x1, %esi
movl %r14d, %edx
xorl %eax, %eax
callq 0x28b91
movzbl %r12b, %esi
addl %esi, %esi
movq %r15, %rdi
xorl %eax, %eax
callq 0x28b91
testq %rbp, %rbp
je 0x6789
movq %r15, %rdi
movq %rbp, %rsi
xorl %edx, %edx
callq 0x28d4f
testl %eax, %eax
jne 0x6a94
testq %r13, %r13
je 0x67a5
movq %r15, %rdi
movq %r13, %rsi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x296b8
testl %eax, %eax
jne 0x6a9d
movslq 0x14(%rsp), %r14
movb 0x8(%rsp), %bpl
testb %bpl, %bpl
je 0x67be
movq $0x0, (%rsp)
jmp 0x67d8
leaq (,%r14,8), %rdi
callq 0x46b0
movq %rax, (%rsp)
testq %rax, %rax
je 0x6aa6
testl %r14d, %r14d
jle 0x6874
xorl %r12d, %r12d
leaq 0xa8c9b(%rip), %r13     # 0xaf486
movq (%rbx,%r12,8), %rsi
testb %bpl, %bpl
je 0x6805
movq %r15, %rdi
callq 0x297cc
testl %eax, %eax
jne 0x6863
jmp 0x69f1
movq %rsi, %rdi
leaq 0xabbbb(%rip), %rsi     # 0xb23ca
callq 0x9c34
movq %rax, %rbp
movq (%rsp), %rax
movq %rbp, (%rax,%r12,8)
movq (%rbx,%r12,8), %r14
testq %rbp, %rbp
je 0x6a20
movq %r14, %rdi
movq %r13, %rsi
callq 0x40d0
testq %rax, %rax
movl $0x7, %ecx
cmoveq %rax, %rcx
addq %rax, %rcx
movq %r15, %rdi
movq %rbp, %rsi
movl $0x1, %edx
callq 0x2985f
testl %eax, %eax
movb 0x8(%rsp), %bpl
je 0x6a07
incq %r12
movslq 0x14(%rsp), %rax
cmpq %rax, %r12
jl 0x67eb
movq 0x28(%r15), %rax
testq %rax, %rax
je 0x6a4e
cmpl $0x0, 0x30(%r15)
jle 0x6a4e
movl 0x10(%rsp), %edx
cmpl $0x2, %edx
jne 0x68ee
movq 0x18(%rsp), %rdi
testq %rdi, %rdi
je 0x697d
leaq 0xaad47(%rip), %rsi     # 0xb15f1
callq 0x45c0
testq %rax, %rax
je 0x6ae0
movq %rax, %r14
movq %r15, %rdi
movq %rax, %rsi
callq 0x60fa
movq %r14, %rdi
callq 0x44b0
testl %eax, %eax
je 0x698f
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0xa8c11(%rip), %rdi     # 0xaf4fa
jmp 0x6af3
cmpl $0x8, %edx
leaq 0xa930d(%rip), %rcx     # 0xafc05
leaq 0xa9372(%rip), %r13     # 0xafc71
cmoveq %rcx, %r13
movq 0x18(%rax), %rbp
testq %rbp, %rbp
je 0x6ab4
movq 0x18(%rsp), %rax
testq %rax, %rax
leaq 0xab3bb(%rip), %r12     # 0xb1cda
cmovneq %rax, %r12
cmpl $0x8, %edx
leaq 0xaacc4(%rip), %rax     # 0xb15f1
leaq 0xa8c04(%rip), %rsi     # 0xaf538
cmoveq %rax, %rsi
movq %r12, %rdi
callq 0x9c34
testq %rax, %rax
je 0x6ac5
movq %rax, %r14
movq %r15, %rdi
movq %rbp, %rsi
movq %rax, %rdx
movq %r13, %rcx
callq 0x62b6
movq %r14, %rdi
callq 0xae96
testl %eax, %eax
movb 0x8(%rsp), %bpl
je 0x698f
leaq 0xa8bc6(%rip), %rdi     # 0xaf53b
movq %r12, %rsi
jmp 0x6abe
movq 0xcf62c(%rip), %rax     # 0xd5fb0
movq (%rax), %rsi
movq %r15, %rdi
callq 0x60fa
movl 0x20(%r15), %edi
testl %edi, %edi
jne 0x6a60
movq %r15, %rdi
callq 0x2a2e0
cmpb $0x0, 0xc(%rsp)
jne 0x69d2
cmpl $0x0, 0x14(%rsp)
jle 0x69ca
xorl %r14d, %r14d
movq (%rbx,%r14,8), %rdi
callq 0x45d0
incq %r14
movslq 0x14(%rsp), %rax
cmpq %rax, %r14
jl 0x69b4
movq %rbx, %rdi
callq 0x45d0
testb %bpl, %bpl
jne 0x69e0
movq (%rsp), %rdi
callq 0x45d0
xorl %eax, %eax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx,%r12,8), %rbx
movl 0x20(%r15), %edi
callq 0x28b14
leaq 0xa8a6a(%rip), %rdi     # 0xaf46f
jmp 0x6a1b
movq (%rbx,%r12,8), %rbx
movl 0x20(%r15), %edi
callq 0x28b14
leaq 0xa8a73(%rip), %rdi     # 0xaf48e
movq %rbx, %rsi
jmp 0x6a33
movl 0x20(%r15), %edi
callq 0x28b14
leaq 0xa8a3f(%rip), %rdi     # 0xaf46f
movq %r14, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x5f2c
movl $0x1, %edi
callq 0x5fc6
xorl %edi, %edi
callq 0x5fc6
leaq 0xa8a56(%rip), %rdi     # 0xaf4ab
jmp 0x6aad
leaq 0xa89b2(%rip), %rdi     # 0xaf410
jmp 0x6aad
callq 0x28b14
leaq 0xa8ae6(%rip), %rdi     # 0xaf552
movq %rax, %rsi
jmp 0x6abe
leaq 0xa88f2(%rip), %rdi     # 0xaf36a
movq %r14, %rsi
jmp 0x6abe
movq 0xcf55c(%rip), %rax     # 0xd5fe0
movslq (%rax), %rax
movq (%r15,%rax,8), %rsi
leaq 0xa896a(%rip), %rdi     # 0xaf3fc
jmp 0x6abe
leaq 0xa898b(%rip), %rdi     # 0xaf426
jmp 0x6aad
leaq 0xa8999(%rip), %rdi     # 0xaf43d
jmp 0x6aad
leaq 0xa89a7(%rip), %rdi     # 0xaf454
xorl %eax, %eax
callq 0x5f2c
leaq 0xa8a59(%rip), %rdi     # 0xaf514
movq %r13, %rsi
xorl %eax, %eax
callq 0x5f2c
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0xa89fe(%rip), %rdi     # 0xaf4d6
movq %r12, %rsi
jmp 0x6a33
callq 0x4050
movl (%rax), %edi
callq 0x4140
leaq 0xa89e3(%rip), %rdi     # 0xaf4d6
movq 0x18(%rsp), %rsi
jmp 0x6a33
leaq 0xa88d1(%rip), %rdi     # 0xaf3d5
jmp 0x6a78
nopl (%rax)