// File: /workspace/github_c_makefile_star2_O3/samtools[P]htslib/test/test_view.c
// Function: main
int main(int argc, char *argv[])
{
    htsFile *in, *out;
    char moder[8];
    char modew[800];
    int c, exit_code = EXIT_SUCCESS;
    hts_opt *in_opts = NULL, *out_opts = NULL;
    char *out_fn = "-";

    struct opts opts;
    opts.fn_ref = NULL;
    opts.flag = 0;
    opts.clevel = -1;
    opts.ignore_sam_err = 0;
    opts.nreads = 0;
    opts.extra_hdr_nuls = 0;
    opts.benchmark = 0;
    opts.nthreads = 0; // shared pool
    opts.multi_reg = 0;
    opts.index = NULL;
    opts.min_shift = 0;

    while ((c = getopt(argc, argv, "DSIt:i:bzCfFul:o:N:BZ:@:Mx:m:p:v")) >= 0) {
        switch (c) {
        case 'D': opts.flag |= READ_CRAM; break;
        case 'S': opts.flag |= READ_COMPRESSED; break;
        case 'I': opts.ignore_sam_err = 1; break;
        case 't': opts.fn_ref = optarg; break;
        case 'i': if (hts_opt_add(&in_opts, optarg)) return 1; break;
        case 'b': opts.flag |= WRITE_BINARY_COMP; break;
        case 'z': opts.flag |= WRITE_COMPRESSED; break;
        case 'C': opts.flag |= WRITE_CRAM; break;
        case 'f': opts.flag |= WRITE_FASTQ; break;
        case 'F': opts.flag |= WRITE_FASTA; break;
        case 'u': opts.flag |= WRITE_UNCOMPRESSED; break; // eg u-BAM not SAM
        case 'l': opts.clevel = atoi(optarg); break;
        case 'o': if (hts_opt_add(&out_opts, optarg)) return 1; break;
        case 'N': opts.nreads = atoi(optarg); break;
        case 'B': opts.benchmark = 1; break;
        case 'Z': opts.extra_hdr_nuls = atoi(optarg); break;
        case 'M': opts.multi_reg = 1; break;
        case '@': opts.nthreads = atoi(optarg); break;
        case 'x': opts.index = optarg; break;
        case 'm': opts.min_shift = atoi(optarg); break;
        case 'p': out_fn = optarg; break;
        case 'v': hts_verbose++; break;
        }
    }
    if (argc == optind) {
        fprintf(stderr, "Usage: test_view [-DSI] [-t fn_ref] [-i option=value] [-bC] [-l level] [-o option=value] [-N num_reads] [-B] [-Z hdr_nuls] [-@ num_threads] [-x index_fn] [-m min_shift] [-p out] [-v] <in.bam>|<in.sam>|<in.cram> [region]\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "-D: read CRAM format (mode 'c')\n");
        fprintf(stderr, "-S: read compressed BCF, BAM, FAI (mode 'b')\n");
        fprintf(stderr, "-I: ignore SAM parsing errors\n");
        fprintf(stderr, "-t: fn_ref: load CRAM references from the specified fasta file instead of @SQ headers when writing a CRAM file\n");
        fprintf(stderr, "-i: option=value: set an option for CRAM input\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "-b: write binary compressed BCF, BAM, FAI (mode 'b')\n");
        fprintf(stderr, "-z: write text compressed VCF.gz, SAM.gz or FASTQ.gz (mode 'z')\n");
        fprintf(stderr, "-C: write CRAM format (mode 'c')\n");
        fprintf(stderr, "-f: write FASTQ format (mode 'f')\n");
        fprintf(stderr, "-l 0-9: set zlib compression level\n");
        fprintf(stderr, "-o option=value: set an option for CRAM output\n");
        fprintf(stderr, "-N: num_reads: limit the output to the first num_reads reads\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "-B: enable benchmarking\n");
        fprintf(stderr, "-M: use hts_itr_multi iterator\n");
        fprintf(stderr, "-Z hdr_nuls: append specified number of null bytes to the SAM header\n");
        fprintf(stderr, "-@ num_threads: use thread pool with specified number of threads\n\n");
        fprintf(stderr, "-x fn: write index to fn\n");
        fprintf(stderr, "-m min_shift: specifies BAI/CSI bin size; 0 is BAI(BAM) or TBI(VCF), 14 is CSI default\n");
        fprintf(stderr, "-p out_fn: output to out_fn instead of stdout\n");
        fprintf(stderr, "-v: increase verbosity\n");
        fprintf(stderr, "The region list entries should be specified as 'reg:beg-end', with intervals of a region being disjunct and sorted by the starting coordinate.\n");
        return 1;
    }
    strcpy(moder, "r");
    if (opts.flag & READ_CRAM) strcat(moder, "c");
    else if ((opts.flag & READ_COMPRESSED) == 0) strcat(moder, "b");

    in = hts_open(argv[optind], moder);
    if (in == NULL) {
        fprintf(stderr, "Error opening \"%s\"\n", argv[optind]);
        return EXIT_FAILURE;
    }

    strcpy(modew, "w");
    if (opts.clevel >= 0 && opts.clevel <= 9)
        snprintf(modew + 1, sizeof(modew) - 1, "%d", opts.clevel);
    if (opts.flag & WRITE_CRAM) strcat(modew, "c");
    else if (opts.flag & WRITE_BINARY_COMP) strcat(modew, "b");
    else if (opts.flag & WRITE_COMPRESSED) strcat(modew, "z");
    else if (opts.flag & WRITE_UNCOMPRESSED) strcat(modew, "bu");
    if (opts.flag & WRITE_FASTQ) strcat(modew, "f");
    else if (opts.flag & WRITE_FASTA) strcat(modew, "F");
    out = hts_open(out_fn, modew);
    if (out == NULL) {
        fprintf(stderr, "Error opening standard output\n");
        return EXIT_FAILURE;
    }

    // Process any options; currently cram only.
    if (hts_opt_apply(in, in_opts))
        return EXIT_FAILURE;
    hts_opt_free(in_opts);

    if (hts_opt_apply(out, out_opts))
        return EXIT_FAILURE;
    hts_opt_free(out_opts);

    // Create and share the thread pool
    htsThreadPool p = {NULL, 0};
    if (opts.nthreads > 0) {
        p.pool = hts_tpool_init(opts.nthreads);
        if (!p.pool) {
            fprintf(stderr, "Error creating thread pool\n");
            exit_code = 1;
        } else {
            hts_set_opt(in,  HTS_OPT_THREAD_POOL, &p);
            hts_set_opt(out, HTS_OPT_THREAD_POOL, &p);
        }
    }

    int ret;
    switch (hts_get_format(in)->category) {
    case sequence_data:
        ret = sam_loop(argc, argv, optind, &opts, in, out);
        break;

    case variant_data:
        ret = vcf_loop(argc, argv, optind, &opts, in, out);
        break;

    default:
        fprintf(stderr, "Unsupported or unknown category of data in input file\n");
        return EXIT_FAILURE;
    }

    if (ret != 0)
        exit_code = EXIT_FAILURE;

    ret = hts_close(out);
    if (ret < 0) {
        fprintf(stderr, "Error closing output.\n");
        exit_code = EXIT_FAILURE;
    }
    ret = hts_close(in);
    if (ret < 0) {
        fprintf(stderr, "Error closing input.\n");
        exit_code = EXIT_FAILURE;
    }

    if (p.pool)
        hts_tpool_destroy(p.pool);

    if (fclose(stdout) != 0 && errno != EBADF) {
        fprintf(stderr, "Error closing standard output.\n");
        exit_code = EXIT_FAILURE;
    }

    return exit_code;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x3d8, %rsp            # imm = 0x3D8
movq %rsi, %rbx
movl %edi, %ebp
xorl %eax, %eax
movq %rax, 0x50(%rsp)
movq %rax, 0x48(%rsp)
leaq 0xa1632(%rip), %rdx     # 0xa8229
callq 0x40e0
testl %eax, %eax
js 0x6e06
movl $0xffffffff, 0x1c(%rsp) # imm = 0xFFFFFFFF
movq $0x0, 0x38(%rsp)
leaq 0xa441e(%rip), %rcx     # 0xab03a
movq %rcx, 0x20(%rsp)
leaq 0xa13dc(%rip), %r15     # 0xa8004
leaq 0xa15fa(%rip), %r12     # 0xa8229
leaq 0xa141e(%rip), %r14     # 0xa8054
movq $0x0, 0x30(%rsp)
movl $0x0, 0xc(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x18(%rsp)
movl $0x0, 0x10(%rsp)
xorl %r13d, %r13d
movq $0x0, 0x40(%rsp)
movq $0x0, 0x28(%rsp)
leal -0x62(%rax), %ecx
cmpl $0x18, %ecx
ja 0x6c96
movslq (%r14,%rcx,4), %rax
addq %r14, %rax
jmpq *%rax
orl $0x2, %r13d
jmp 0x6def
leal -0x40(%rax), %ecx
cmpl $0x13, %ecx
ja 0x6cbf
movslq (%r15,%rcx,4), %rax
addq %r15, %rax
jmpq *%rax
movq 0xc8312(%rip), %rax     # 0xcefc0
movq (%rax), %rdi
callq 0x4810
movl %eax, 0xc(%rsp)
jmp 0x6def
cmpl $0x5a, %eax
jne 0x6def
movq 0xc82f1(%rip), %rax     # 0xcefc0
movq (%rax), %rdi
callq 0x4810
movl %eax, 0x8(%rsp)
jmp 0x6def
orl $0x20, %r13d
jmp 0x6def
movq 0xc82d0(%rip), %rax     # 0xcefc0
movq (%rax), %rax
movq %rax, 0x30(%rsp)
jmp 0x6def
orl $0x10, %r13d
jmp 0x6def
movq 0xc82b3(%rip), %rax     # 0xcefc0
movq (%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x6def
orl $0x40, %r13d
jmp 0x6def
leaq 0xc87d6(%rip), %rax     # 0xcf500
incl (%rax)
jmp 0x6def
movq 0xc8288(%rip), %rax     # 0xcefc0
movq (%rax), %rsi
leaq 0x50(%rsp), %rdi
jmp 0x6d93
movq 0xc8277(%rip), %rax     # 0xcefc0
movq (%rax), %rax
movq %rax, 0x40(%rsp)
jmp 0x6def
movq 0xc8263(%rip), %rax     # 0xcefc0
movq (%rax), %rdi
callq 0x4810
movl %eax, 0x1c(%rsp)
jmp 0x6def
movq 0xc824b(%rip), %rax     # 0xcefc0
movq (%rax), %rdi
callq 0x4810
movq %rax, 0x38(%rsp)
jmp 0x6def
movq 0xc8235(%rip), %rax     # 0xcefc0
movq (%rax), %rsi
leaq 0x48(%rsp), %rdi
callq 0xa31b
testl %eax, %eax
je 0x6def
jmp 0x70e5
orl $0x1, %r13d
jmp 0x6def
orl $0x80, %r13d
jmp 0x6def
movl $0x1, %eax
movq %rax, 0x28(%rsp)
jmp 0x6def
movq 0xc81fd(%rip), %rax     # 0xcefc0
movq (%rax), %rdi
callq 0x4810
movl %eax, 0x10(%rsp)
jmp 0x6def
orl $0x4, %r13d
jmp 0x6def
orl $0x8, %r13d
jmp 0x6def
movl $0x1, 0x14(%rsp)
jmp 0x6def
movl $0x1, 0x18(%rsp)
movl %ebp, %edi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x40e0
testl %eax, %eax
jns 0x6c7c
jmp 0x6e69
movq $0x0, 0x28(%rsp)
leaq 0xa4224(%rip), %rax     # 0xab03a
movq %rax, 0x20(%rsp)
movl $0xffffffff, 0x1c(%rsp) # imm = 0xFFFFFFFF
movq $0x0, 0x40(%rsp)
xorl %r13d, %r13d
movl $0x0, 0x10(%rsp)
movl $0x0, 0x18(%rsp)
movl $0x0, 0x8(%rsp)
movl $0x0, 0x14(%rsp)
movl $0x0, 0xc(%rsp)
movq $0x0, 0x30(%rsp)
movq $0x0, 0x38(%rsp)
movq 0x38(%rsp), %rax
movl %eax, 0xa8(%rsp)
movq 0x30(%rsp), %rax
movq %rax, 0xa0(%rsp)
movl 0xc(%rsp), %eax
movl %eax, 0x98(%rsp)
movl 0x14(%rsp), %eax
movl %eax, 0x9c(%rsp)
movl 0x8(%rsp), %eax
movl %eax, 0x90(%rsp)
movl 0x18(%rsp), %eax
movl %eax, 0x94(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x8c(%rsp)
movl 0x1c(%rsp), %r12d
movl %r12d, 0x84(%rsp)
movl %r13d, 0x80(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x28(%rsp), %rax
movl %eax, 0x88(%rsp)
movq 0xc80f5(%rip), %rax     # 0xcefe0
movslq (%rax), %r14
cmpl %ebp, %r14d
je 0x70cf
movw $0x72, 0x58(%rsp)
movw $0x63, %r15w
testb $0x4, %r13b
jne 0x6f14
movw $0x62, %r15w
testb $0x1, %r13b
jne 0x6f24
leaq 0x58(%rsp), %rdi
callq 0x41d0
movw %r15w, 0x58(%rsp,%rax)
movq (%rbx,%r14,8), %rdi
leaq 0x58(%rsp), %rsi
callq 0xa314
testq %rax, %rax
je 0x70d6
movq %rax, %r14
movw $0x77, 0xb0(%rsp)
cmpl $0x9, %r12d
ja 0x6f6c
leaq 0xb1(%rsp), %rdi
leaq 0xb1945(%rip), %rdx     # 0xb88a2
movl $0x31f, %esi            # imm = 0x31F
movl %r12d, %ecx
xorl %eax, %eax
callq 0x4830
testb $0x8, %r13b
jne 0x6fa5
testb $0x2, %r13b
jne 0x6fbe
testb $0x20, %r13b
jne 0x6fd7
testb $0x10, %r13b
je 0x6fee
leaq 0xb0(%rsp), %rdi
callq 0x41d0
movw $0x7562, 0xb0(%rsp,%rax) # imm = 0x7562
movb $0x0, 0xb2(%rsp,%rax)
jmp 0x6fee
leaq 0xb0(%rsp), %rdi
callq 0x41d0
movw $0x63, 0xb0(%rsp,%rax)
jmp 0x6fee
leaq 0xb0(%rsp), %rdi
callq 0x41d0
movw $0x62, 0xb0(%rsp,%rax)
jmp 0x6fee
leaq 0xb0(%rsp), %rdi
callq 0x41d0
movw $0x7a, 0xb0(%rsp,%rax)
movw $0x66, %r15w
testb $0x40, %r13b
jne 0x7003
movw $0x46, %r15w
testb %r13b, %r13b
jns 0x7019
leaq 0xb0(%rsp), %rdi
callq 0x41d0
movw %r15w, 0xb0(%rsp,%rax)
leaq 0xb0(%rsp), %rsi
movq 0x20(%rsp), %rdi
callq 0xa314
testq %rax, %rax
je 0x70e0
movq %rax, %r12
movq 0x50(%rsp), %rsi
movq %r14, %rdi
callq 0xa181
movl $0x1, %r15d
testl %eax, %eax
jne 0x7198
movq 0x50(%rsp), %rdi
callq 0xb288
movq 0x48(%rsp), %rsi
movq %r12, %rdi
callq 0xa181
testl %eax, %eax
jne 0x7198
movq 0x48(%rsp), %rdi
callq 0xb288
xorps %xmm0, %xmm0
movaps %xmm0, 0x60(%rsp)
movl 0x98(%rsp), %edi
testl %edi, %edi
jle 0x70f0
callq 0x2ab49
movq %rax, 0x60(%rsp)
testq %rax, %rax
je 0x71c7
xorl %r15d, %r15d
leaq 0x60(%rsp), %r13
movq %r14, %rdi
movl $0x66, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0xaca2
movq %r12, %rdi
movl $0x66, %esi
movq %r13, %rdx
xorl %eax, %eax
callq 0xaca2
jmp 0x70f3
callq 0x4dc5
jmp 0x70e5
movq %rbx, %rdi
callq 0x4d96
jmp 0x70e5
callq 0x4d74
movl $0x1, %r15d
jmp 0x7198
xorl %r15d, %r15d
movq %r14, %rdi
callq 0xb833
movl (%rax), %eax
cmpl $0x2, %eax
je 0x712b
cmpl $0x1, %eax
jne 0x71e1
movq 0xc7ece(%rip), %rax     # 0xcefe0
movl (%rax), %edx
leaq 0x78(%rsp), %rcx
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %r8
movq %r12, %r9
callq 0x649c
jmp 0x7149
movq 0xc7eae(%rip), %rax     # 0xcefe0
movl (%rax), %edx
leaq 0x78(%rsp), %rcx
movl %ebp, %edi
movq %rbx, %rsi
movq %r14, %r8
movq %r12, %r9
callq 0x6944
testl %eax, %eax
movl $0x1, %eax
cmovnel %eax, %r15d
movq %r12, %rdi
callq 0xb576
testl %eax, %eax
js 0x71ad
movq %r14, %rdi
callq 0xb576
testl %eax, %eax
js 0x71ba
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x717b
callq 0x2b57b
movq 0xc7e2e(%rip), %rax     # 0xcefb0
movq (%rax), %rdi
callq 0x44c0
testl %eax, %eax
je 0x7198
callq 0x4050
cmpl $0x9, (%rax)
jne 0x71d7
movl %r15d, %eax
addq $0x3d8, %rsp            # imm = 0x3D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x4cec
movl $0x1, %r15d
jmp 0x7160
callq 0x4d0e
movl $0x1, %r15d
jmp 0x716c
callq 0x4cca
movl $0x1, %r15d
jmp 0x70f3
callq 0x4d30
jmp 0x70e5
callq 0x4d52
jmp 0x70e5
nop