// File: /workspace/github_c_makefile_star2_O2/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 0x53d07
movq %rdx, %r14
movl %esi, %edx
movq %rdi, %rbx
cmpl $0x12, %esi
ja 0x53d1a
movl %edx, %eax
leaq 0x33d1d(%rip), %rcx     # 0x879fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x54137
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x54143
callq 0x6060
movl $0x9, (%rax)
pushq $-0x1
popq %rax
jmp 0x542c5
cmpl $0x64, %edx
jne 0x542cd
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x541ec
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x541f8
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x53f8a
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x53f96
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x53fa3
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x53faf
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5401c
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x54028
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x54035
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x54041
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5404e
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5405a
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x54067
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x54073
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x54085
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x54091
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5409e
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x540aa
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x54105
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x54111
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5411e
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5412a
movq 0x20(%rbx), %rdi
callq 0x68a0
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x54150
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5415c
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x54176
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x54182
leaq 0x228(%rbx), %rsi
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5418f
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5419b
movl $0x1, 0x220(%rbx)
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x541b9
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x541c5
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x54202
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5420e
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x54283
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5428f
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x54299
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x542a5
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x542af
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x542bb
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x21c(%rbx)
jmp 0x542c3
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %esi
cmpl $0x2, %esi
jl 0x542c3
leal (%rsi,%rsi), %edi
callq 0x5a815
movq %rax, 0x8860(%rbx)
testq %rax, %rax
je 0x53d12
callq 0x5a7bf
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
pushq $0x1
popq %rax
movl %eax, 0x220(%rbx)
movl %eax, 0x885c(%rbx)
jmp 0x542c3
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x20c(%rbx)
jmp 0x542c3
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x204(%rbx)
jmp 0x542c3
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x214(%rbx)
jmp 0x542c3
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 0x501e9
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x1fc(%rbx)
jmp 0x542c3
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %rax
movq %rax, 0x8860(%rbx)
testq %rax, %rax
je 0x540ef
callq 0x5a7bf
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)
andl $0x0, 0x885c(%rbx)
jmp 0x542c3
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x200(%rbx)
jmp 0x542c3
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x208(%rbx)
jmp 0x542c3
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x1f8(%rbx)
jmp 0x542c3
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 0x542c3
jmp 0x53d12
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x218(%rbx)
jmp 0x542c3
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 0x4c182
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %r14
movq 0x48(%rbx), %rdi
cmpq %rdi, %r14
je 0x542c3
testq %rdi, %rdi
je 0x541df
callq 0x4ee57
movq %r14, 0x48(%rbx)
incl 0x30(%r14)
jmp 0x542c3
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x78(%rbx)
jmp 0x542c3
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %r14
leaq 0x3655e(%rip), %rsi     # 0x8a776
leaq 0x4(%rsp), %rdx
movq %rsp, %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0x66d0
cmpl $0x2, %eax
jne 0x542e7
movl 0x4(%rsp), %eax
movl %eax, %edx
xorl $0x1, %edx
movl (%rsp), %ecx
orl %ecx, %edx
je 0x54268
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 0x54268
testb %dl, %dl
je 0x54307
shll $0x8, %eax
addl %ecx, %eax
movl %eax, 0xc(%rbx)
cmpl $0x300, %eax            # imm = 0x300
jb 0x542c3
movl $0x1, 0x218(%rbx)
jmp 0x542c3
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x224(%rbx)
jmp 0x542c3
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x8850(%rbx)
jmp 0x542c3
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
movq 0x5ed04(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
leaq 0x33d34(%rip), %rsi     # 0x88012
xorl %eax, %eax
callq 0x6a90
jmp 0x54323
movq 0x5ecea(%rip), %rax     # 0xb2fd8
movq (%rax), %rdi
leaq 0x33ccb(%rip), %rsi     # 0x87fc3
movq %r14, %rdx
xorl %eax, %eax
callq 0x6a90
jmp 0x53d12
movq 0x5ecca(%rip), %rax     # 0xb2fd8
movq (%rax), %rcx
leaq 0x33cc8(%rip), %rdi     # 0x87fe0
pushq $0x31
popq %rsi
pushq $0x1
popq %rdx
callq 0x6e70
callq 0x6060
movl $0x16, (%rax)
jmp 0x53d12