// File: /workspace/github_c_makefile_star2_O3/icebert[P]pblat/htslib/cram/cram_codecs.c
// Function: cram_codec_decoder2encoder
int cram_codec_decoder2encoder(cram_fd *fd, cram_codec *c) {
    int j;

    switch (c->codec) {
    case E_EXTERNAL:
	// shares struct with decode
	c->free = cram_external_encode_free;
	c->store = cram_external_encode_store;
	if (c->decode == cram_external_decode_int)
	    c->encode = cram_external_encode_int;
	else if (c->decode == cram_external_decode_char)
	    c->encode = cram_external_encode_char;
	else
	    return -1;
	break;

    case E_HUFFMAN: {
	// New structure, so switch.
	// FIXME: we huffman and e_huffman structs amended, we could
	// unify this.
	cram_codec *t = malloc(sizeof(*t));
	t->codec = E_HUFFMAN;
	t->free = cram_huffman_encode_free;
	t->store = cram_huffman_encode_store;
	t->e_huffman.codes = c->huffman.codes;
	t->e_huffman.nvals = c->huffman.ncodes;
	for (j = 0; j < t->e_huffman.nvals; j++) {
	    int32_t sym = t->e_huffman.codes[j].symbol;
	    if (sym >= -1 && sym < MAX_HUFF)
		t->e_huffman.val2code[sym+1] = j;
	}

	if (c->decode == cram_huffman_decode_char0)
	    t->encode = cram_huffman_encode_char0;
	else if (c->decode == cram_huffman_decode_char)
	    t->encode = cram_huffman_encode_char;
	else if (c->decode == cram_huffman_decode_int0)
	    t->encode = cram_huffman_encode_int0;
	else if (c->decode == cram_huffman_decode_int)
	    t->encode = cram_huffman_encode_int;
	else {
	    free(t);
	    return -1;
	}
	*c = *t;
	free(t);
	break;
    }

    case E_BETA:
	// shares struct with decode
	c->free = cram_beta_encode_free;
	c->store = cram_beta_encode_store;
	if (c->decode == cram_beta_decode_int)
	    c->encode = cram_beta_encode_int;
	else if (c->decode == cram_beta_decode_char)
	    c->encode = cram_beta_encode_char;
	else
	    return -1;
	break;

    case E_BYTE_ARRAY_LEN: {
	cram_codec *t = malloc(sizeof(*t));
	t->codec = E_BYTE_ARRAY_LEN;
	t->free   = cram_byte_array_len_encode_free;
	t->store  = cram_byte_array_len_encode_store;
	t->encode = cram_byte_array_len_encode;
	t->e_byte_array_len.len_codec = c->byte_array_len.len_codec;
	t->e_byte_array_len.val_codec = c->byte_array_len.val_codec;
	if (cram_codec_decoder2encoder(fd, t->e_byte_array_len.len_codec) == -1 ||
	    cram_codec_decoder2encoder(fd, t->e_byte_array_len.val_codec) == -1) {
	    t->free(t);
	    return -1;
	}

	// {len,val}_{encoding,dat} are undefined, but unused.
	// Leaving them unset here means we can test that assertion.
	*c = *t;
	free(t);
	break;
    }

    case E_BYTE_ARRAY_STOP:
	// shares struct with decode
	c->free   = cram_byte_array_stop_encode_free;
	c->store  = cram_byte_array_stop_encode_store;
	c->encode = cram_byte_array_stop_encode;
	break;

    default:
	return -1;
    }

    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
movl (%rsi), %eax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
decl %eax
cmpl $0x5, %eax
ja 0x8ba51
movq %rsi, %rbx
leaq 0x102e7(%rip), %rcx     # 0x9bb14
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x3ac7(%rip), %rax     # 0x87d76
movq %rax, 0x10(%rbx)
leaq -0x3ac8(%rip), %rax     # 0x87d80
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rax
leaq -0x405f(%rip), %rcx     # 0x877f8
cmpq %rcx, %rax
je 0x8b9fb
leaq -0x3ee3(%rip), %rcx     # 0x87984
cmpq %rcx, %rax
jne 0x8ba51
leaq -0x3bd7(%rip), %rax     # 0x87ca0
jmp 0x8ba14
movq %rdi, %r15
movl $0x240, %edi            # imm = 0x240
callq 0x69d0
movq %rax, %r14
movl $0x4, (%rax)
leaq -0xeb5(%rip), %rax      # 0x8a9e4
movq %rax, 0x10(%r14)
leaq -0xe95(%rip), %rax      # 0x8aa0f
movq %rax, 0x28(%r14)
leaq -0xf15(%rip), %rax      # 0x8a99a
movq %rax, 0x20(%r14)
movq 0x30(%rbx), %rsi
movq %rsi, 0x48(%r14)
movq 0x38(%rbx), %r12
movq %r12, 0x50(%r14)
movq %r15, %rdi
callq 0x8b809
cmpl $-0x1, %eax
je 0x8b8e4
movq %r15, %rdi
movq %r12, %rsi
callq 0x8b809
cmpl $-0x1, %eax
jne 0x8ba37
movq %r14, %rdi
callq 0x8a9e4
jmp 0x8ba51
movl $0x240, %edi            # imm = 0x240
callq 0x69d0
movq %rax, %r14
movl $0x3, (%rax)
leaq -0x1dfc(%rip), %rax     # 0x89b0f
movq %rax, 0x10(%r14)
leaq -0x1de6(%rip), %rax     # 0x89b30
movq %rax, 0x28(%r14)
movq 0x38(%rbx), %rax
movq %rax, 0x30(%r14)
movslq 0x30(%rbx), %rcx
movl %ecx, 0x38(%r14)
testq %rcx, %rcx
jle 0x8b950
xorl %edx, %edx
movl (%rax), %esi
incl %esi
cmpl $0x80, %esi
ja 0x8b944
movl %esi, %esi
movl %edx, 0x3c(%r14,%rsi,4)
incq %rdx
addq $0x10, %rax
cmpq %rcx, %rdx
jb 0x8b931
movq 0x18(%rbx), %rax
leaq -0x2924(%rip), %rcx     # 0x89037
cmpq %rcx, %rax
je 0x8ba04
leaq -0x2914(%rip), %rcx     # 0x89057
cmpq %rcx, %rax
je 0x8ba1a
leaq -0x27ed(%rip), %rcx     # 0x8918e
cmpq %rcx, %rax
je 0x8ba23
leaq -0x26fc(%rip), %rcx     # 0x8928f
cmpq %rcx, %rax
je 0x8ba2c
movq %r14, %rdi
callq 0x68a0
jmp 0x8ba51
leaq -0x5fc(%rip), %rax      # 0x8b3ac
movq %rax, 0x10(%rbx)
leaq -0x5fd(%rip), %rax      # 0x8b3b6
movq %rax, 0x28(%rbx)
leaq -0x796(%rip), %rax      # 0x8b228
jmp 0x8ba14
leaq -0x307d(%rip), %rax     # 0x8894a
movq %rax, 0x10(%rbx)
leaq -0x33ff(%rip), %rax     # 0x885d3
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rax
leaq -0x39a2(%rip), %rcx     # 0x8803f
cmpq %rcx, %rax
je 0x8ba0d
leaq -0x3698(%rip), %rcx     # 0x88355
cmpq %rcx, %rax
jne 0x8ba51
leaq -0x30f8(%rip), %rax     # 0x88901
jmp 0x8ba14
leaq -0x3d72(%rip), %rax     # 0x87c90
jmp 0x8ba14
leaq -0x207b(%rip), %rax     # 0x89990
jmp 0x8ba33
leaq -0x32b2(%rip), %rax     # 0x88762
movq %rax, 0x20(%rbx)
jmp 0x8ba4f
leaq -0x208e(%rip), %rax     # 0x89993
jmp 0x8ba33
leaq -0x1fe1(%rip), %rax     # 0x89a49
jmp 0x8ba33
leaq -0x1fe7(%rip), %rax     # 0x89a4c
movq %rax, 0x20(%r14)
movl $0x240, %edx            # imm = 0x240
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6570
movq %r14, %rdi
callq 0x68a0
xorl %ebp, %ebp
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)