// File: /workspace/github_c_makefile_star2_O1/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 0x14e65
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
cmpl $0x6, %eax
ja 0x14ec6
leaq 0x83928(%rip), %rcx     # 0x9879c
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)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rsp)
movl $0x10, %ecx
cmpq $0x28, %rcx
ja 0x15199
movl $0x10, %eax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x151a7
leal -0x3e8(%rsi), %eax
cmpl $0x4, %eax
ja 0x153b4
leaq 0x838dc(%rip), %rcx     # 0x987b8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x4c(%rdi), %eax
andl $-0x2, %eax
cmpl $0x10, %eax
jne 0x153ec
xorl %eax, %eax
addq $0xd0, %rsp
popq %rbx
jmp 0x2a012
movl 0x4c(%rdi), %ecx
xorl %eax, %eax
cmpl $0x11, %ecx
ja 0x15280
movl $0x3010c, %edx          # imm = 0x3010C
btl %ecx, %edx
jae 0x15269
cmpl $0x0, 0x54(%rdi)
movq 0x38(%rdi), %rax
je 0x15280
movq %rax, %rdi
jmp 0x1527b
movl 0x4c(%rdi), %eax
andl $-0x2, %eax
cmpl $0x10, %eax
jne 0x153ec
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rsp)
movl $0x10, %ecx
cmpq $0x28, %rcx
ja 0x15328
movl $0x10, %eax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x15336
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rsp)
movl $0x10, %ecx
cmpq $0x28, %rcx
ja 0x15152
movl $0x10, %eax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x15160
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rsp)
movl $0x10, %ecx
cmpq $0x28, %rcx
ja 0x1516d
movl $0x10, %eax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x1517b
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rsp)
movl $0x10, %ecx
cmpq $0x28, %rcx
ja 0x151cd
movl $0x10, %eax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x151db
movl 0x4c(%rdi), %eax
andl $-0x2, %eax
cmpl $0x10, %eax
jne 0x153ec
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rsp)
movl $0x10, %ecx
cmpq $0x28, %rcx
ja 0x1534e
movl $0x10, %eax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x1535c
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rsp)
movl $0x10, %ecx
cmpq $0x28, %rcx
ja 0x15204
movl $0x10, %eax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x15212
leaq 0x20(%rsp), %rax
movq %rax, 0x10(%rsp)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rsp)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rsp)
movl $0x10, %ecx
cmpq $0x28, %rcx
ja 0x1521f
movl $0x10, %eax
addq 0x10(%rsp), %rax
addl $0x8, %ecx
movl %ecx, (%rsp)
jmp 0x1522d
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rsi
callq 0x15a15
jmp 0x153e8
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
cmpl $0x2, 0x54(%rdi)
jne 0x153ec
movl (%rax), %esi
xorl %ebx, %ebx
testb $0x10, (%rdi)
jne 0x15340
xorl %edi, %edi
jmp 0x15344
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %edx
testb $0x10, (%rdi)
jne 0x151e7
cmpl $0x6, 0x4c(%rdi)
jne 0x153ec
movq 0x38(%rdi), %rdi
movl $0x64, %esi
xorl %eax, %eax
callq 0x55e0e
jmp 0x153e8
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movl (%rax), %esi
callq 0x159d1
jmp 0x153e8
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 0x153ec
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rsi
callq 0x15a7b
jmp 0x153e8
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
testb $0x10, (%rdi)
je 0x153b4
movl (%rax), %eax
cmpl $0x3, %eax
ja 0x153b4
movl %eax, %eax
leaq 0x83582(%rip), %rcx     # 0x987cc
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 0x153a6
movl $0x212, %edx            # imm = 0x212
btl %ecx, %edx
jae 0x1536d
movq 0x38(%rdi), %rdi
callq 0xe7a3
testq %rax, %rax
je 0x152c7
leaq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rsp)
leaq 0xe0(%rsp), %rcx
movq %rcx, 0x8(%rsp)
movabsq $0x3000000010, %rcx     # imm = 0x3000000010
movq %rcx, (%rsp)
movl $0x10, %edx
cmpq $0x28, %rdx
ja 0x152e8
movl $0x10, %ecx
addq 0x10(%rsp), %rcx
addl $0x8, %edx
movl %edx, (%rsp)
jmp 0x152f6
leaq 0x83f6f(%rip), %rsi     # 0x9923d
leaq 0x83f90(%rip), %rdx     # 0x99265
xorl %ebx, %ebx
movl $0x3, %edi
xorl %eax, %eax
callq 0x14378
jmp 0x153ee
movq 0x8(%rsp), %rcx
leaq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movslq (%rcx), %rsi
movq %rax, %rdi
callq 0xefdd
testl %eax, %eax
je 0x153ec
leaq 0x83f2d(%rip), %rsi     # 0x9923d
leaq 0x83f32(%rip), %rdx     # 0x99249
movl $0x3, %edi
xorl %eax, %eax
callq 0x14378
jmp 0x153ec
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rdx
movl $0x3eb, %esi            # imm = 0x3EB
jmp 0x15364
movq 0x38(%rdi), %rdi
callq 0xd782
jmp 0x153ee
movq 0x8(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq (%rax), %rdx
movl $0x3e9, %esi            # imm = 0x3E9
xorl %eax, %eax
callq 0x2a012
jmp 0x153e8
cmpl $0x6, %ecx
jne 0x15280
movq 0x38(%rdi), %rax
movq (%rax), %rax
jmp 0x15280
movq 0x38(%rdi), %rax
movl $0xe00fffff, %ecx       # imm = 0xE00FFFFF
andl (%rax), %ecx
orl $0x800000, %ecx         # imm = 0x800000
jmp 0x153a6
movq 0x38(%rdi), %rax
movl $0xe00fffff, %ecx       # imm = 0xE00FFFFF
andl (%rax), %ecx
orl $0x900000, %ecx         # imm = 0x900000
movl %ecx, (%rax)
jmp 0x153b4
movq 0x38(%rdi), %rax
orl $0x1ff00000, (%rax)     # imm = 0x1FF00000
cmpl $0x6, 0x4c(%rdi)
jne 0x153ec
leaq 0x20(%rsp), %rax
movq %rsp, %rdx
movq %rax, 0x10(%rdx)
leaq 0xe0(%rsp), %rax
movq %rax, 0x8(%rdx)
movabsq $0x3000000010, %rax     # imm = 0x3000000010
movq %rax, (%rdx)
movq 0x38(%rdi), %rdi
callq 0x55e92
movl %eax, %ebx
jmp 0x153ee
xorl %ebx, %ebx
movl %ebx, %eax
addq $0xd0, %rsp
popq %rbx
retq