// File: /workspace/github_c_makefile_star2_O2/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
pushq $-0x1
popq %rbp
decl %eax
cmpl $0x5, %eax
ja 0x79ffa
movq %rsi, %rbx
leaq 0x109eb(%rip), %rcx     # 0x8a7c4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x311a(%rip), %rax     # 0x76ccf
movq %rax, 0x10(%rbx)
leaq -0x3120(%rip), %rax     # 0x76cd4
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rax
leaq -0x35eb(%rip), %rcx     # 0x76818
cmpq %rcx, %rax
je 0x79fa4
leaq -0x348c(%rip), %rcx     # 0x76987
cmpq %rcx, %rax
jne 0x79ffa
leaq -0x320b(%rip), %rax     # 0x76c18
jmp 0x79fbd
movq %rdi, %r15
movl $0x240, %edi            # imm = 0x240
callq 0x69d0
movq %rax, %r14
movl $0x4, (%rax)
leaq -0xd68(%rip), %rax      # 0x790dd
movq %rax, 0x10(%r14)
leaq -0xd48(%rip), %rax      # 0x79108
movq %rax, 0x28(%r14)
leaq -0xdc6(%rip), %rax      # 0x79095
movq %rax, 0x20(%r14)
movq 0x30(%rbx), %rsi
movq %rsi, 0x48(%r14)
movq 0x38(%rbx), %r12
movq %r12, 0x50(%r14)
movq %r15, %rdi
callq 0x79db7
cmpl $-0x1, %eax
je 0x79e90
movq %r15, %rdi
movq %r12, %rsi
callq 0x79db7
cmpl $-0x1, %eax
jne 0x79fe0
movq %r14, %rdi
callq 0x790dd
jmp 0x79ffa
movl $0x240, %edi            # imm = 0x240
callq 0x69d0
movq %rax, %r14
movl $0x3, (%rax)
leaq -0x1a2a(%rip), %rax     # 0x7848d
movq %rax, 0x10(%r14)
leaq -0x1a19(%rip), %rax     # 0x784a9
movq %rax, 0x28(%r14)
movq 0x38(%rbx), %rax
movq %rax, 0x30(%r14)
movslq 0x30(%rbx), %rcx
movl %ecx, 0x38(%r14)
xorl %edx, %edx
cmpq %rcx, %rdx
jge 0x79ef9
movl (%rax), %esi
incl %esi
cmpl $0x80, %esi
ja 0x79ef0
movl %esi, %esi
movl %edx, 0x3c(%r14,%rsi,4)
incq %rdx
addq $0x10, %rax
jmp 0x79ed8
movq 0x18(%rbx), %rax
leaq -0x210c(%rip), %rcx     # 0x77df8
cmpq %rcx, %rax
je 0x79fad
leaq -0x20fa(%rip), %rcx     # 0x77e1a
cmpq %rcx, %rax
je 0x79fc3
leaq -0x1ff8(%rip), %rcx     # 0x77f2c
cmpq %rcx, %rax
je 0x79fcc
leaq -0x1fe8(%rip), %rcx     # 0x77f4c
cmpq %rcx, %rax
je 0x79fd5
movq %r14, %rdi
callq 0x68a0
jmp 0x79ffa
leaq -0x5b9(%rip), %rax      # 0x79998
movq %rax, 0x10(%rbx)
leaq -0x5bf(%rip), %rax      # 0x7999d
movq %rax, 0x28(%rbx)
leaq -0x716(%rip), %rax      # 0x79851
jmp 0x79fbd
leaq -0x2727(%rip), %rax     # 0x77849
movq %rax, 0x10(%rbx)
leaq -0x2a85(%rip), %rax     # 0x774f6
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rax
leaq -0x3031(%rip), %rcx     # 0x76f59
cmpq %rcx, %rax
je 0x79fb6
leaq -0x2d0d(%rip), %rcx     # 0x77289
cmpq %rcx, %rax
jne 0x79ffa
leaq -0x27a1(%rip), %rax     # 0x77801
jmp 0x79fbd
leaq -0x33a3(%rip), %rax     # 0x76c08
jmp 0x79fbd
leaq -0x1ca4(%rip), %rax     # 0x78310
jmp 0x79fdc
leaq -0x2956(%rip), %rax     # 0x77667
movq %rax, 0x20(%rbx)
jmp 0x79ff8
leaq -0x1cb7(%rip), %rax     # 0x78313
jmp 0x79fdc
leaq -0x1c09(%rip), %rax     # 0x783ca
jmp 0x79fdc
leaq -0x1c0f(%rip), %rax     # 0x783cd
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
nopw %cs:(%rax,%rax)
nop