// File: /workspace/github_cpp_makefile_star2_O3/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 0x389c5
movq %rdx, %r14
movq %rdi, %rbx
cmpl $0x13, %esi
ja 0x389da
movl %esi, %eax
leaq 0x19def(%rip), %rcx     # 0x5278c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38e36
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38e42
callq 0x4070
movl $0x9, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x38fc4
cmpl $0x64, %esi
jne 0x38fcc
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38d84
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38d90
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38c6e
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38c7a
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38c87
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38c93
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38d02
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38d0e
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38d1b
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38d27
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38d34
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38d40
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38d4d
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38d59
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38d6b
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38d77
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38d9a
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38da6
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38e04
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38e10
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38e1d
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38e29
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0x38b46
callq 0x4610
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38e4f
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38e5b
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38e75
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38e81
leaq 0x228(%rbx), %rsi
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38e8e
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38e9a
movl $0x1, 0x220(%rbx)
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38eb8
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38ec4
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38eeb
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38ef7
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38f6c
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38f78
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38f82
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38f8e
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38f98
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38fa4
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x38fae
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x38fba
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x21c(%rbx)
jmp 0x38fc2
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %esi
cmpl $0x2, %esi
jl 0x38fc2
leal (%rsi,%rsi), %edi
callq 0x4118a
movq %rax, 0x8860(%rbx)
testq %rax, %rax
je 0x389d0
callq 0x41132
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, %eax
movl %eax, 0x220(%rbx)
movl %eax, 0x885c(%rbx)
jmp 0x38fc2
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x20c(%rbx)
jmp 0x38fc2
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x204(%rbx)
jmp 0x38fc2
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x214(%rbx)
jmp 0x38fc2
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 0x345b1
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x1fc(%rbx)
jmp 0x38fc2
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x78(%rbx)
jmp 0x38fc2
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %rax
movq %rax, 0x8860(%rbx)
testq %rax, %rax
je 0x38deb
callq 0x41132
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)
movl $0x0, 0x885c(%rbx)
jmp 0x38fc2
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x200(%rbx)
jmp 0x38fc2
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x208(%rbx)
jmp 0x38fc2
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x1f8(%rbx)
jmp 0x38fc2
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %rdi
callq 0x49c0
movq %rax, 0x20(%rbx)
testq %rax, %rax
jne 0x38fc2
jmp 0x389d0
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x218(%rbx)
jmp 0x38fc2
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 0x2f567
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %r14
movq 0x48(%rbx), %rdi
cmpq %rdi, %r14
je 0x38fc2
testq %rdi, %rdi
je 0x38ede
callq 0x32dfc
movq %r14, 0x48(%rbx)
incl 0x30(%r14)
jmp 0x38fc2
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %r14
leaq 0x1be6a(%rip), %rsi     # 0x54d6b
leaq 0x4(%rsp), %rdx
movq %rsp, %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0x4520
cmpl $0x2, %eax
jne 0x38fd8
movl 0x4(%rsp), %eax
movl %eax, %edx
xorl $0x1, %edx
movl (%rsp), %ecx
orl %ecx, %edx
je 0x38f51
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 0x38f51
testb %dl, %dl
je 0x38ff8
shll $0x8, %eax
addl %ecx, %eax
movl %eax, 0xc(%rbx)
cmpl $0x300, %eax            # imm = 0x300
jb 0x38fc2
movl $0x1, 0x218(%rbx)
jmp 0x38fc2
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x224(%rbx)
jmp 0x38fc2
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x8850(%rbx)
jmp 0x38fc2
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x210(%rbx)
jmp 0x38fc2
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
movl %esi, %edi
callq 0x5813
jmp 0x389d0
movq 0x28fe9(%rip), %rax     # 0x61fc8
movq (%rax), %rdi
leaq 0x19f6c(%rip), %rsi     # 0x52f55
movq %r14, %rdx
xorl %eax, %eax
callq 0x4770
jmp 0x389d0
callq 0x57e6
jmp 0x389d0