// File: /workspace/github_cpp_makefile_star2_O2/karel-brinda[P]ococo/ext/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_LOSSY_NAMES:
	fd->lossy_read_names = 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 0x2dd9d
movq %rdx, %r14
movl %esi, %edx
movq %rdi, %rbx
cmpl $0x13, %esi
ja 0x2ddb0
movl %edx, %eax
leaq 0x17947(%rip), %rcx     # 0x456bc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e202
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e20e
callq 0x4060
movl $0x9, (%rax)
pushq $-0x1
popq %rax
jmp 0x2e390
cmpl $0x64, %edx
jne 0x2e398
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e153
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e15f
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e03f
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e04b
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e058
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e064
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e0d1
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e0dd
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e0ea
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e0f6
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e103
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e10f
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e11c
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e128
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e13a
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e146
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e169
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e175
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e1d0
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e1dc
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e1e9
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e1f5
movq 0x20(%rbx), %rdi
callq 0x4600
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e21b
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e227
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e241
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e24d
leaq 0x228(%rbx), %rsi
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e25a
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e266
movl $0x1, 0x220(%rbx)
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e284
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e290
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e2b7
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e2c3
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e338
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e344
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e34e
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e35a
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e364
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e370
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x2e37a
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x2e386
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x21c(%rbx)
jmp 0x2e38e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %esi
cmpl $0x2, %esi
jl 0x2e38e
leal (%rsi,%rsi), %edi
callq 0x34ad5
movq %rax, 0x8860(%rbx)
testq %rax, %rax
je 0x2dda8
callq 0x34a7f
movq %rax, 0x8868(%rbx)
leaq 0x8870(%rbx), %rdi
xorl %esi, %esi
callq 0x47c0
leaq 0x8898(%rbx), %rdi
xorl %esi, %esi
callq 0x47c0
leaq 0x88c8(%rbx), %rdi
xorl %esi, %esi
callq 0x47c0
pushq $0x1
popq %rax
movl %eax, 0x220(%rbx)
movl %eax, 0x885c(%rbx)
jmp 0x2e38e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x20c(%rbx)
jmp 0x2e38e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x204(%rbx)
jmp 0x2e38e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x214(%rbx)
jmp 0x2e38e
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 0x2a280
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x1fc(%rbx)
jmp 0x2e38e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x78(%rbx)
jmp 0x2e38e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %rax
movq %rax, 0x8860(%rbx)
testq %rax, %rax
je 0x2e1ba
callq 0x34a7f
movq %rax, 0x8868(%rbx)
leaq 0x8870(%rbx), %rdi
xorl %esi, %esi
callq 0x47c0
leaq 0x8898(%rbx), %rdi
xorl %esi, %esi
callq 0x47c0
leaq 0x88c8(%rbx), %rdi
xorl %esi, %esi
callq 0x47c0
movl $0x1, 0x220(%rbx)
andl $0x0, 0x885c(%rbx)
jmp 0x2e38e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x200(%rbx)
jmp 0x2e38e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x208(%rbx)
jmp 0x2e38e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x1f8(%rbx)
jmp 0x2e38e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %rdi
callq 0x49a0
movq %rax, 0x20(%rbx)
testq %rax, %rax
jne 0x2e38e
jmp 0x2dda8
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x218(%rbx)
jmp 0x2e38e
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 0x2611b
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %r14
movq 0x48(%rbx), %rdi
cmpq %rdi, %r14
je 0x2e38e
testq %rdi, %rdi
je 0x2e2aa
callq 0x28d94
movq %r14, 0x48(%rbx)
incl 0x30(%r14)
jmp 0x2e38e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %r14
leaq 0x19816(%rip), %rsi     # 0x47ae3
leaq 0x4(%rsp), %rdx
movq %rsp, %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0x4510
cmpl $0x2, %eax
jne 0x2e3b2
movl 0x4(%rsp), %eax
movl %eax, %edx
xorl $0x1, %edx
movl (%rsp), %ecx
orl %ecx, %edx
je 0x2e31d
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 0x2e31d
testb %dl, %dl
je 0x2e3d2
shll $0x8, %eax
addl %ecx, %eax
movl %eax, 0xc(%rbx)
cmpl $0x300, %eax            # imm = 0x300
jb 0x2e38e
movl $0x1, 0x218(%rbx)
jmp 0x2e38e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x224(%rbx)
jmp 0x2e38e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x8850(%rbx)
jmp 0x2e38e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x210(%rbx)
jmp 0x2e38e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x88fc(%rbx)
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
retq
movq 0x28c31(%rip), %rax     # 0x56fd0
movq (%rax), %rdi
leaq 0x17976(%rip), %rsi     # 0x45d1f
xorl %eax, %eax
callq 0x4770
jmp 0x2e3ee
movq 0x28c17(%rip), %rax     # 0x56fd0
movq (%rax), %rdi
leaq 0x1790d(%rip), %rsi     # 0x45cd0
movq %r14, %rdx
xorl %eax, %eax
callq 0x4770
jmp 0x2dda8
movq 0x28bf7(%rip), %rax     # 0x56fd0
movq (%rax), %rcx
leaq 0x1790a(%rip), %rdi     # 0x45ced
pushq $0x31
popq %rsi
pushq $0x1
popq %rdx
callq 0x4a20
callq 0x4060
movl $0x16, (%rax)
jmp 0x2dda8