// File: /workspace/github_c_makefile_star2_O1/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 %rbx
pushq %rax
movl (%rsi), %eax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
decl %eax
cmpl $0x5, %eax
ja 0x8bf2b
movq %rsi, %rbx
leaq 0xfb16(%rip), %rcx      # 0x9b814
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x3af0(%rip), %rax     # 0x8821e
movq %rax, 0x10(%rbx)
leaq -0x3af1(%rip), %rax     # 0x88228
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rax
leaq -0x40a0(%rip), %rcx     # 0x87c88
cmpq %rcx, %rax
je 0x8bed5
leaq -0x3f1d(%rip), %rcx     # 0x87e1b
cmpq %rcx, %rax
jne 0x8bf2b
leaq -0x3bf0(%rip), %rax     # 0x88158
jmp 0x8beee
movq %rdi, %r15
movl $0x240, %edi            # imm = 0x240
callq 0x69d0
movq %rax, %r14
movl $0x4, (%rax)
leaq -0xebb(%rip), %rax      # 0x8aeaf
movq %rax, 0x10(%r14)
leaq -0xe9b(%rip), %rax      # 0x8aeda
movq %rax, 0x28(%r14)
leaq -0xf1b(%rip), %rax      # 0x8ae65
movq %rax, 0x20(%r14)
movq 0x30(%rbx), %rsi
movq %rsi, 0x48(%r14)
movq 0x38(%rbx), %rax
movq %rax, 0x50(%r14)
movq %r15, %rdi
callq 0x8bcdb
cmpl $-0x1, %eax
je 0x8bdb6
movq 0x50(%r14), %rsi
movq %r15, %rdi
callq 0x8bcdb
cmpl $-0x1, %eax
jne 0x8bf11
movq %r14, %rdi
callq *0x10(%r14)
jmp 0x8bf2b
movl $0x240, %edi            # imm = 0x240
callq 0x69d0
movq %rax, %r14
movl $0x3, (%rax)
leaq -0x1e3b(%rip), %rax     # 0x89fa1
movq %rax, 0x10(%r14)
leaq -0x1e25(%rip), %rax     # 0x89fc2
movq %rax, 0x28(%r14)
movq 0x38(%rbx), %rax
movq %rax, 0x30(%r14)
movl 0x30(%rbx), %eax
movl %eax, 0x38(%r14)
testl %eax, %eax
jle 0x8be2a
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x30(%r14), %rdx
movl (%rdx,%rax), %edx
incl %edx
cmpl $0x80, %edx
ja 0x8be1a
movl %edx, %edx
movl %ecx, 0x3c(%r14,%rdx,4)
incq %rcx
movslq 0x38(%r14), %rdx
addq $0x10, %rax
cmpq %rdx, %rcx
jl 0x8be02
movq 0x18(%rbx), %rax
leaq -0x290b(%rip), %rcx     # 0x8952a
cmpq %rcx, %rax
je 0x8bede
leaq -0x28fb(%rip), %rcx     # 0x8954a
cmpq %rcx, %rax
je 0x8bef4
leaq -0x27ab(%rip), %rcx     # 0x896aa
cmpq %rcx, %rax
je 0x8befd
leaq -0x279d(%rip), %rcx     # 0x896c8
cmpq %rcx, %rax
je 0x8bf06
movq %r14, %rdi
callq 0x68a0
jmp 0x8bf2b
leaq -0x606(%rip), %rax      # 0x8b87c
movq %rax, 0x10(%rbx)
leaq -0x607(%rip), %rax      # 0x8b886
movq %rax, 0x28(%rbx)
leaq -0x782(%rip), %rax      # 0x8b716
jmp 0x8beee
leaq -0x30b6(%rip), %rax     # 0x88deb
movq %rax, 0x10(%rbx)
leaq -0x342e(%rip), %rax     # 0x88a7e
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rax
leaq -0x39da(%rip), %rcx     # 0x884e1
cmpq %rcx, %rax
je 0x8bee7
leaq -0x36c8(%rip), %rcx     # 0x887ff
cmpq %rcx, %rax
jne 0x8bf2b
leaq -0x3131(%rip), %rax     # 0x88da2
jmp 0x8beee
leaq -0x3d94(%rip), %rax     # 0x88148
jmp 0x8beee
leaq -0x20be(%rip), %rax     # 0x89e27
jmp 0x8bf0d
leaq -0x32e6(%rip), %rax     # 0x88c08
movq %rax, 0x20(%rbx)
jmp 0x8bf29
leaq -0x20d1(%rip), %rax     # 0x89e2a
jmp 0x8bf0d
leaq -0x2024(%rip), %rax     # 0x89ee0
jmp 0x8bf0d
leaq -0x202a(%rip), %rax     # 0x89ee3
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
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax,%rax)