// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/hts.c
// Function: hts_set_opt
int hts_set_opt(htsFile *fp, enum hts_fmt_option opt, ...) {
    int r;
    va_list args;

    switch (opt) {
    case HTS_OPT_NTHREADS: {
        va_start(args, opt);
        int nthreads = va_arg(args, int);
        va_end(args);
        return hts_set_threads(fp, nthreads);
    }

    case HTS_OPT_BLOCK_SIZE: {
        hFILE *hf = hts_hfile(fp);

        if (hf) {
            va_start(args, opt);
            if (hfile_set_blksize(hf, va_arg(args, int)) != 0)
                hts_log_warning("Failed to change block size");
            va_end(args);
        }
        else {
            // To do - implement for vcf/bcf.
            hts_log_warning("Cannot change block size for this format");
        }

        return 0;
    }

    case HTS_OPT_THREAD_POOL: {
        va_start(args, opt);
        htsThreadPool *p = va_arg(args, htsThreadPool *);
        va_end(args);
        return hts_set_thread_pool(fp, p);
    }

    case HTS_OPT_CACHE_SIZE: {
        va_start(args, opt);
        int cache_size = va_arg(args, int);
        va_end(args);
        hts_set_cache_size(fp, cache_size);
        return 0;
    }

    case FASTQ_OPT_CASAVA:
    case FASTQ_OPT_RNUM:
    case FASTQ_OPT_NAME2:
        if (fp->format.format == fastq_format ||
            fp->format.format == fasta_format)
            return fastq_state_set(fp, opt);
        return 0;

    case FASTQ_OPT_AUX:
        if (fp->format.format == fastq_format ||
            fp->format.format == fasta_format) {
            va_start(args, opt);
            char *list = va_arg(args, char *);
            va_end(args);
            return fastq_state_set(fp, opt, list);
        }
        return 0;

    case FASTQ_OPT_BARCODE:
        if (fp->format.format == fastq_format ||
            fp->format.format == fasta_format) {
            va_start(args, opt);
            char *bc = va_arg(args, char *);
            va_end(args);
            return fastq_state_set(fp, opt, bc);
        }
        return 0;

    // Options below here flow through to cram_set_voption
    case HTS_OPT_COMPRESSION_LEVEL: {
        va_start(args, opt);
        int level = va_arg(args, int);
        va_end(args);
        if (fp->is_bgzf)
            fp->fp.bgzf->compress_level = level;
        else if (fp->format.format == cram)
            return cram_set_option(fp->fp.cram, opt, level);
        return 0;
    }

    case HTS_OPT_FILTER: {
        va_start(args, opt);
        char *expr = va_arg(args, char *);
        va_end(args);
        return hts_set_filter_expression(fp, expr);
    }

    case HTS_OPT_PROFILE: {
        va_start(args, opt);
        enum hts_profile_option prof = va_arg(args, int);
        va_end(args);
        if (fp->is_bgzf) {
            switch (prof) {
#ifdef HAVE_LIBDEFLATE
            case HTS_PROFILE_FAST:    fp->fp.bgzf->compress_level =  2; break;
            case HTS_PROFILE_NORMAL:  fp->fp.bgzf->compress_level = -1; break;
            case HTS_PROFILE_SMALL:   fp->fp.bgzf->compress_level = 10; break;
            case HTS_PROFILE_ARCHIVE: fp->fp.bgzf->compress_level = 12; break;
#else
            case HTS_PROFILE_FAST:    fp->fp.bgzf->compress_level =  1; break;
            case HTS_PROFILE_NORMAL:  fp->fp.bgzf->compress_level = -1; break;
            case HTS_PROFILE_SMALL:   fp->fp.bgzf->compress_level =  8; break;
            case HTS_PROFILE_ARCHIVE: fp->fp.bgzf->compress_level =  9; break;
#endif
            }
        } // else CRAM manages this in its own way
        break;
    }

    default:
        break;
    }

    if (fp->format.format != cram)
        return 0;

    va_start(args, opt);
    r = cram_set_voption(fp->fp.cram, opt, args);
    va_end(args);

    return r;
}

// Assembly:
pushq %rbx
subq $0xd0, %rsp
movq %rdx, 0x30(%rsp)
movq %rcx, 0x38(%rsp)
movq %r8, 0x40(%rsp)
movq %r9, 0x48(%rsp)
testb %al, %al
je 0x11b96
movaps %xmm0, 0x50(%rsp)
movaps %xmm1, 0x60(%rsp)
movaps %xmm2, 0x70(%rsp)
movaps %xmm3, 0x80(%rsp)
movaps %xmm4, 0x90(%rsp)
movaps %xmm5, 0xa0(%rsp)
movaps %xmm6, 0xb0(%rsp)
movaps %xmm7, 0xc0(%rsp)
leal -0x64(%rsi), %eax
movabsq $0x3000000010, %rbx     # imm = 0x3000000010
cmpl $0x6, %eax
ja 0x11bf3
leaq 0x65c4d(%rip), %rcx     # 0x777fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbx, (%rsp)
pushq $0x10
popq %rcx
cmpq $0x28, %rcx
ja 0x11e4d
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x11e5b
leal -0x3e8(%rsi), %eax
cmpl $0x4, %eax
ja 0x12046
leaq 0x65c0f(%rip), %rcx     # 0x77818
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x4c(%rdi), %eax
andl $-0x2, %eax
cmpl $0x10, %eax
jne 0x12074
xorl %eax, %eax
addq $0xd0, %rsp
popq %rbx
jmp 0x2300e
movl 0x4c(%rdi), %eax
cmpl $0x11, %eax
ja 0x11ff8
movl $0x3010c, %ecx          # imm = 0x3010C
btl %eax, %ecx
jae 0x11f1b
cmpl $0x0, 0x54(%rdi)
movq 0x38(%rdi), %rdi
jne 0x11f2d
jmp 0x11f35
movl 0x4c(%rdi), %eax
andl $-0x2, %eax
cmpl $0x10, %eax
jne 0x12074
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbx, (%rsp)
pushq $0x10
popq %rcx
cmpq $0x28, %rcx
ja 0x11fad
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x11fbb
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbx, (%rsp)
pushq $0x10
popq %rcx
cmpq $0x28, %rcx
ja 0x11e18
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x11e26
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbx, (%rsp)
pushq $0x10
popq %rcx
cmpq $0x28, %rcx
ja 0x11e33
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x11e41
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbx, (%rsp)
pushq $0x10
popq %rcx
cmpq $0x28, %rcx
ja 0x11e7f
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x11e8d
movl 0x4c(%rdi), %eax
andl $-0x2, %eax
cmpl $0x10, %eax
jne 0x12074
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbx, (%rsp)
pushq $0x10
popq %rcx
cmpq $0x28, %rcx
ja 0x11fc5
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x11fd3
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbx, (%rsp)
pushq $0x10
popq %rcx
cmpq $0x28, %rcx
ja 0x11eb6
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x11ec4
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbx, (%rsp)
pushq $0x10
popq %rcx
cmpq $0x28, %rcx
ja 0x11ed1
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x11edf
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rsi
callq 0x126aa
jmp 0x12070
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %esi
callq 0x126f2
jmp 0x12074
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %edx
testb $0x10, (%rdi)
jne 0x11e99
cmpl $0x6, 0x4c(%rdi)
jne 0x12074
movq 0x38(%rdi), %rdi
pushq $0x64
popq %rsi
xorl %eax, %eax
callq 0x451f7
jmp 0x12070
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %esi
callq 0x12668
jmp 0x12070
movq 0x38(%rdi), %rax
shll $0x14, %edx
movl $0xe00fffff, %ecx       # imm = 0xE00FFFFF
andl (%rax), %ecx
andl $0x1ff00000, %edx       # imm = 0x1FF00000
orl %edx, %ecx
movl %ecx, (%rax)
jmp 0x12074
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rsi
callq 0x1270e
jmp 0x12070
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
testb $0x10, (%rdi)
je 0x12046
movl (%rax), %eax
cmpl $0x3, %eax
ja 0x12046
movl %eax, %eax
leaq 0x65930(%rip), %rcx     # 0x7782c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq 0x38(%rdi), %rax
movl $0xe00fffff, %ecx       # imm = 0xE00FFFFF
andl (%rax), %ecx
orl $0x100000, %ecx         # imm = 0x100000
jmp 0x12038
movl $0x212, %ecx            # imm = 0x212
btl %eax, %ecx
jae 0x11fe7
movq 0x38(%rdi), %rdi
callq 0xcaf2
movq %rax, %rdi
testq %rdi, %rdi
je 0x11ff8
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movq %rbx, (%rsp)
pushq $0x10
popq %rcx
cmpq $0x28, %rcx
ja 0x11f72
movq %rcx, %rax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x11f80
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movslq (%rax), %rsi
callq 0xd26c
testl %eax, %eax
je 0x12074
leaq 0x66337(%rip), %rsi     # 0x782ce
leaq 0x6633c(%rip), %rdx     # 0x782da
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x110c6
jmp 0x12074
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rdx
movl $0x3eb, %esi            # imm = 0x3EB
jmp 0x11fdb
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rdx
movl $0x3e9, %esi            # imm = 0x3E9
xorl %eax, %eax
callq 0x2300e
jmp 0x12070
cmpl $0x6, %eax
jne 0x11ff8
movq 0x38(%rdi), %rax
movq (%rax), %rdi
jmp 0x11f35
leaq 0x662cf(%rip), %rsi     # 0x782ce
leaq 0x662f0(%rip), %rdx     # 0x782f6
xorl %ebx, %ebx
pushq $0x3
popq %rdi
xorl %eax, %eax
callq 0x110c6
jmp 0x12076
movq 0x38(%rdi), %rax
movl $0xe00fffff, %ecx       # imm = 0xE00FFFFF
andl (%rax), %ecx
orl $0x800000, %ecx         # imm = 0x800000
jmp 0x12038
movq 0x38(%rdi), %rax
movl $0xe00fffff, %ecx       # imm = 0xE00FFFFF
andl (%rax), %ecx
orl $0x900000, %ecx         # imm = 0x900000
movl %ecx, (%rax)
jmp 0x12046
movq 0x38(%rdi), %rax
orl $0x1ff00000, (%rax)     # imm = 0x1FF00000
cmpl $0x6, 0x4c(%rdi)
jne 0x12074
leaq 0x20(%rsp), %rax
movq %rsp, %rdx
movq %rax, 0x10(%rdx)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rdx)
movq %rbx, (%rdx)
movq 0x38(%rdi), %rdi
callq 0x4527b
movl %eax, %ebx
jmp 0x12076
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xd0, %rsp
popq %rbx
retq