// File: /workspace/github_c_makefile_star2_O3/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 0x5d0ae
movq %rdx, %r14
movq %rdi, %rbx
cmpl $0x12, %esi
ja 0x5d0c3
movl %esi, %eax
leaq 0x3ba46(%rip), %rcx     # 0x98acc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d4ea
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d4f6
callq 0x6060
movl $0x9, (%rax)
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
jmp 0x5d678
cmpl $0x64, %esi
jne 0x5d680
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d59f
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d5ab
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d338
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d344
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d351
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d35d
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d3cc
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d3d8
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d3e5
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d3f1
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d3fe
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d40a
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d417
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d423
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d435
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d441
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d44e
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d45a
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d4b8
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d4c4
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d4d1
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d4dd
movq 0x20(%rbx), %rdi
testq %rdi, %rdi
je 0x5d22f
callq 0x68a0
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d503
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d50f
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d529
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d535
leaq 0x228(%rbx), %rsi
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d542
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d54e
movl $0x1, 0x220(%rbx)
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d56c
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d578
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d5b5
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d5c1
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d636
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d642
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d64c
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d658
movl (%r14), %ecx
cmpq $0x28, %rcx
ja 0x5d662
movq %rcx, %rax
addq 0x10(%r14), %rax
addl $0x8, %ecx
movl %ecx, (%r14)
jmp 0x5d66e
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x21c(%rbx)
jmp 0x5d676
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %esi
cmpl $0x2, %esi
jl 0x5d676
leal (%rsi,%rsi), %edi
callq 0x6542a
movq %rax, 0x8860(%rbx)
testq %rax, %rax
je 0x5d0b9
callq 0x653d2
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 0x5d676
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x20c(%rbx)
jmp 0x5d676
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x204(%rbx)
jmp 0x5d676
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x214(%rbx)
jmp 0x5d676
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 0x58cb4
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x1fc(%rbx)
jmp 0x5d676
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %rax
movq %rax, 0x8860(%rbx)
testq %rax, %rax
je 0x5d49f
callq 0x653d2
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 0x5d676
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x200(%rbx)
jmp 0x5d676
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x208(%rbx)
jmp 0x5d676
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x1f8(%rbx)
jmp 0x5d676
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 0x5d676
jmp 0x5d0b9
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x218(%rbx)
jmp 0x5d676
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 0x53e4f
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %r14
movq 0x48(%rbx), %rdi
cmpq %rdi, %r14
je 0x5d676
testq %rdi, %rdi
je 0x5d592
callq 0x576f8
movq %r14, 0x48(%rbx)
incl 0x30(%r14)
jmp 0x5d676
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x78(%rbx)
jmp 0x5d676
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movq (%rax), %r14
leaq 0x3e4fb(%rip), %rsi     # 0x9bac6
leaq 0x4(%rsp), %rdx
movq %rsp, %rcx
movq %r14, %rdi
xorl %eax, %eax
callq 0x66d0
cmpl $0x2, %eax
jne 0x5d68c
movl 0x4(%rsp), %eax
movl %eax, %edx
xorl $0x1, %edx
movl (%rsp), %ecx
orl %ecx, %edx
je 0x5d61b
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 0x5d61b
testb %dl, %dl
je 0x5d6ac
shll $0x8, %eax
addl %ecx, %eax
movl %eax, 0xc(%rbx)
cmpl $0x300, %eax            # imm = 0x300
jb 0x5d676
movl $0x1, 0x218(%rbx)
jmp 0x5d676
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x224(%rbx)
jmp 0x5d676
movq 0x8(%r14), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x8(%r14)
movl (%rax), %eax
movl %eax, 0x8850(%rbx)
jmp 0x5d676
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 0x79ba
jmp 0x5d0b9
movq 0x61945(%rip), %rax     # 0xbefd8
movq (%rax), %rdi
leaq 0x3bb7b(%rip), %rsi     # 0x99218
movq %r14, %rdx
xorl %eax, %eax
callq 0x6a90
jmp 0x5d0b9
callq 0x798d
jmp 0x5d0b9