// File: /workspace/github_c_makefile_star2_O1/icebert[P]pblat/htslib/cram/cram_io.c
// Function: cram_set_voption
int cram_set_voption(cram_fd *fd, enum hts_fmt_option opt, va_list args) {
    refs_t *refs;

    if (!fd) {
	errno = EBADF;
	return -1;
    }

    switch (opt) {
    case CRAM_OPT_DECODE_MD:
	fd->decode_md = va_arg(args, int);
	break;

    case CRAM_OPT_PREFIX:
	if (fd->prefix)
	    free(fd->prefix);
	if (!(fd->prefix = strdup(va_arg(args, char *))))
	    return -1;
	break;

    case CRAM_OPT_VERBOSITY:
	fd->verbose = va_arg(args, int);
	break;

    case CRAM_OPT_SEQS_PER_SLICE:
	fd->seqs_per_slice = va_arg(args, int);
	break;

    case CRAM_OPT_SLICES_PER_CONTAINER:
	fd->slices_per_container = va_arg(args, int);
	break;

    case CRAM_OPT_EMBED_REF:
	fd->embed_ref = va_arg(args, int);
	break;

    case CRAM_OPT_NO_REF:
	fd->no_ref = va_arg(args, int);
	break;

    case CRAM_OPT_IGNORE_MD5:
	fd->ignore_md5 = va_arg(args, int);
	break;

    case CRAM_OPT_USE_BZIP2:
	fd->use_bz2 = va_arg(args, int);
	break;

    case CRAM_OPT_USE_RANS:
	fd->use_rans = va_arg(args, int);
	break;

    case CRAM_OPT_USE_LZMA:
	fd->use_lzma = va_arg(args, int);
	break;

    case CRAM_OPT_SHARED_REF:
	fd->shared_ref = 1;
	refs = va_arg(args, refs_t *);
	if (refs != fd->refs) {
	    if (fd->refs)
		refs_free(fd->refs);
	    fd->refs = refs;
	    fd->refs->count++;
	}
	break;

    case CRAM_OPT_RANGE:
	fd->range = *va_arg(args, cram_range *);
	return cram_seek_to_refpos(fd, &fd->range);

    case CRAM_OPT_REFERENCE:
	return cram_load_reference(fd, va_arg(args, char *));

    case CRAM_OPT_VERSION: {
	int major, minor;
	char *s = va_arg(args, char *);
	if (2 != sscanf(s, "%d.%d", &major, &minor)) {
	    fprintf(stderr, "Malformed version string %s\n", s);
	    return -1;
	}
	if (!((major == 1 &&  minor == 0) ||
	      (major == 2 && (minor == 0 || minor == 1)) ||
	      (major == 3 &&  minor == 0))) {
	    fprintf(stderr, "Unknown version string; "
		    "use 1.0, 2.0, 2.1 or 3.0\n");
	    errno = EINVAL;
	    return -1;
	}
	fd->version = major*256 + minor;

	if (CRAM_MAJOR_VERS(fd->version) >= 3)
	    fd->use_rans = 1;
	break;
    }

    case CRAM_OPT_MULTI_SEQ_PER_SLICE:
	fd->multi_seq = va_arg(args, int);
	break;

    case CRAM_OPT_NTHREADS: {
	int nthreads =  va_arg(args, int);
        if (nthreads > 1) {
            if (!(fd->pool = t_pool_init(nthreads*2, nthreads)))
                return -1;

	    fd->rqueue = t_results_queue_init();
	    pthread_mutex_init(&fd->metrics_lock, NULL);
	    pthread_mutex_init(&fd->ref_lock, NULL);
	    pthread_mutex_init(&fd->bam_list_lock, NULL);
	    fd->shared_ref = 1;
	    fd->own_pool = 1;
        }
	break;
    }

    case CRAM_OPT_THREAD_POOL:
	fd->pool = va_arg(args, t_pool *);
	if (fd->pool) {
	    fd->rqueue = t_results_queue_init();
	    pthread_mutex_init(&fd->metrics_lock, NULL);
	    pthread_mutex_init(&fd->ref_lock, NULL);
	    pthread_mutex_init(&fd->bam_list_lock, NULL);
	}
	fd->shared_ref = 1; // Needed to avoid clobbering ref between threads
	fd->own_pool = 0;

	//fd->qsize = 1;
	//fd->decoded = calloc(fd->qsize, sizeof(cram_container *));
	//t_pool_dispatch(fd->pool, cram_decoder_thread, fd);
	break;

    case CRAM_OPT_REQUIRED_FIELDS:
	fd->required_fields = va_arg(args, int);
	break;

    case HTS_OPT_COMPRESSION_LEVEL:
	fd->level = va_arg(args, int);
	break;

    default:
	fprintf(stderr, "Unknown CRAM option code %d\n", opt);
	errno = EINVAL;
	return -1;
    }

    return 0;
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
testq %rdi, %rdi
je 0x5cd14
movq %rdx, %r14
movq %rdi, %rbx
cmpl $0x12, %esi
ja 0x5cd29
movl %esi, %eax
leaq 0x3bcf0(%rip), %rcx     # 0x989dc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d150
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d15c
callq 0x6060
movl $0x9, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x5d2de
cmpl $0x64, %esi
jne 0x5d2e6
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d205
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d211
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5cf9e
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5cfaa
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5cfb7
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5cfc3
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d032
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d03e
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d04b
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d057
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d064
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d070
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d07d
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d089
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d09b
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d0a7
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d0b4
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d0c0
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d11e
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d12a
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d137
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d143
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0x5ce95
callq 0x68a0
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d169
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d175
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d18f
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d19b
leaq 0x228(%rbx), %rsi
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d1a8
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d1b4
movl $0x1, 0x220(%rbx)
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d1d2
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d1de
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d21b
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d227
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d29c
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d2a8
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d2b2
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d2be
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d2c8
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d2d4
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x21c(%rbx)
jmp 0x5d2dc
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %esi
cmpl $0x2, %esi
jl 0x5d2dc
leal (%rsi,%rsi), %edi
callq 0x6543e
movq %rax, 0x8860(%rbx)
testq %rax, %rax
je 0x5cd1f
callq 0x653b6
movq %rax, 0x8868(%rbx)
leaq 0x8870(%rbx), %rdi
xorl %esi, %esi
callq 0x6b10
leaq 0x8898(%rbx), %rdi
xorl %esi, %esi
callq 0x6b10
leaq 0x88c8(%rbx), %rdi
xorl %esi, %esi
callq 0x6b10
movl $0x1, %eax
movl %eax, 0x220(%rbx)
movl %eax, 0x885c(%rbx)
jmp 0x5d2dc
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x20c(%rbx)
jmp 0x5d2dc
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x204(%rbx)
jmp 0x5d2dc
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x214(%rbx)
jmp 0x5d2dc
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %rsi
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x58a8b
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x1fc(%rbx)
jmp 0x5d2dc
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %rax
movq %rax, 0x8860(%rbx)
testq %rax, %rax
je 0x5d105
callq 0x653b6
movq %rax, 0x8868(%rbx)
leaq 0x8870(%rbx), %rdi
xorl %esi, %esi
callq 0x6b10
leaq 0x8898(%rbx), %rdi
xorl %esi, %esi
callq 0x6b10
leaq 0x88c8(%rbx), %rdi
xorl %esi, %esi
callq 0x6b10
movl $0x1, 0x220(%rbx)
movl $0x0, 0x885c(%rbx)
jmp 0x5d2dc
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x200(%rbx)
jmp 0x5d2dc
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x208(%rbx)
jmp 0x5d2dc
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x1f8(%rbx)
jmp 0x5d2dc
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %rdi
callq 0x6dd0
movq %rax, 0x20(%rbx)
testq %rax, %rax
jne 0x5d2dc
jmp 0x5cd1f
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x218(%rbx)
jmp 0x5d2dc
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %rax
movl 0x8(%rax), %ecx
movl %ecx, 0x8(%rsi)
movq (%rax), %rax
movq %rax, (%rsi)
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r14
jmp 0x53b4d
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %r14
movq 0x48(%rbx), %rdi
cmpq %rdi, %r14
je 0x5d2dc
testq %rdi, %rdi
je 0x5d1f8
callq 0x574b6
movq %r14, 0x48(%rbx)
incl 0x30(%r14)
jmp 0x5d2dc
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x78(%rbx)
jmp 0x5d2dc
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %r14
leaq 0x3e595(%rip), %rsi     # 0x9b7c6
leaq 0x4(%rsp), %rdx
movq %rsp, %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0x66d0
cmpl $0x2, %eax
jne 0x5d2f2
movl 0x4(%rsp), %eax
movl %eax, %edx
xorl $0x1, %edx
movl (%rsp), %ecx
orl %ecx, %edx
je 0x5d281
cmpl $0x2, %eax
sete %sil
cmpl $0x2, %ecx
setb %dil
movl %eax, %edx
xorl $0x3, %edx
orl %ecx, %edx
sete %dl
testb %dil, %sil
jne 0x5d281
testb %dl, %dl
je 0x5d312
shll $0x8, %eax
addl %ecx, %eax
movl %eax, 0xc(%rbx)
cmpl $0x300, %eax            # imm = 0x300
jl 0x5d2dc
movl $0x1, 0x218(%rbx)
jmp 0x5d2dc
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x224(%rbx)
jmp 0x5d2dc
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x8850(%rbx)
jmp 0x5d2dc
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x210(%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movl %esi, %edi
callq 0x7a0d
jmp 0x5cd1f
movq 0x61cdf(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x3bd0a(%rip), %rsi     # 0x9900d
movq %r14, %rdx
xorl %eax, %eax
callq 0x6a90
jmp 0x5cd1f
callq 0x79e0
jmp 0x5cd1f