// File: /workspace/github_cpp_makefile_star2_O3/karel-brinda[P]ococo/ext/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 0x4cfc2
movq %rsi, %rbx
leaq 0x7a5a(%rip), %rcx      # 0x547f8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x3afd(%rip), %rax     # 0x492b1
movq %rax, 0x10(%rbx)
leaq -0x3afe(%rip), %rax     # 0x492bb
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rax
leaq -0x409c(%rip), %rcx     # 0x48d2c
cmpq %rcx, %rax
je 0x4cf6c
leaq -0x3f20(%rip), %rcx     # 0x48eb8
cmpq %rcx, %rax
jne 0x4cfc2
leaq -0x3c0d(%rip), %rax     # 0x491db
jmp 0x4cf85
movq %rdi, %r15
movl $0x240, %edi            # imm = 0x240
callq 0x4700
movq %rax, %r14
movl $0x4, (%rax)
leaq -0xeca(%rip), %rax      # 0x4bf40
movq %rax, 0x10(%r14)
leaq -0xeaa(%rip), %rax      # 0x4bf6b
movq %rax, 0x28(%r14)
leaq -0xf2a(%rip), %rax      # 0x4bef6
movq %rax, 0x20(%r14)
movq 0x30(%rbx), %rsi
movq %rsi, 0x48(%r14)
movq 0x38(%rbx), %r12
movq %r12, 0x50(%r14)
movq %r15, %rdi
callq 0x4cd7a
cmpl $-0x1, %eax
je 0x4ce55
movq %r15, %rdi
movq %r12, %rsi
callq 0x4cd7a
cmpl $-0x1, %eax
jne 0x4cfa8
movq %r14, %rdi
callq 0x4bf40
jmp 0x4cfc2
movl $0x240, %edi            # imm = 0x240
callq 0x4700
movq %rax, %r14
movl $0x3, (%rax)
leaq -0x1e11(%rip), %rax     # 0x4b06b
movq %rax, 0x10(%r14)
leaq -0x1dfb(%rip), %rax     # 0x4b08c
movq %rax, 0x28(%r14)
movq 0x38(%rbx), %rax
movq %rax, 0x30(%r14)
movslq 0x30(%rbx), %rcx
movl %ecx, 0x38(%r14)
testq %rcx, %rcx
jle 0x4cec1
xorl %edx, %edx
movl (%rax), %esi
incl %esi
cmpl $0x80, %esi
ja 0x4ceb5
movl %esi, %esi
movl %edx, 0x3c(%r14,%rsi,4)
incq %rdx
addq $0x10, %rax
cmpq %rcx, %rdx
jb 0x4cea2
movq 0x18(%rbx), %rax
leaq -0x293e(%rip), %rcx     # 0x4a58e
cmpq %rcx, %rax
je 0x4cf75
leaq -0x2929(%rip), %rcx     # 0x4a5b3
cmpq %rcx, %rax
je 0x4cf8b
leaq -0x2802(%rip), %rcx     # 0x4a6ea
cmpq %rcx, %rax
je 0x4cf94
leaq -0x2711(%rip), %rcx     # 0x4a7eb
cmpq %rcx, %rax
je 0x4cf9d
movq %r14, %rdi
callq 0x4610
jmp 0x4cfc2
leaq -0x5e1(%rip), %rax      # 0x4c938
movq %rax, 0x10(%rbx)
leaq -0x5e2(%rip), %rax      # 0x4c942
movq %rax, 0x28(%rbx)
leaq -0x77b(%rip), %rax      # 0x4c7b4
jmp 0x4cf85
leaq -0x3097(%rip), %rax     # 0x49ea1
movq %rax, 0x10(%rbx)
leaq -0x3419(%rip), %rax     # 0x49b2a
movq %rax, 0x28(%rbx)
movq 0x18(%rbx), %rax
leaq -0x39d8(%rip), %rcx     # 0x4957a
cmpq %rcx, %rax
je 0x4cf7e
leaq -0x36ce(%rip), %rcx     # 0x49890
cmpq %rcx, %rax
jne 0x4cfc2
leaq -0x3112(%rip), %rax     # 0x49e58
jmp 0x4cf85
leaq -0x3da8(%rip), %rax     # 0x491cb
jmp 0x4cf85
leaq -0x2090(%rip), %rax     # 0x4aeec
jmp 0x4cfa4
leaq -0x32cc(%rip), %rax     # 0x49cb9
movq %rax, 0x20(%rbx)
jmp 0x4cfc0
leaq -0x20a3(%rip), %rax     # 0x4aeef
jmp 0x4cfa4
leaq -0x1ff6(%rip), %rax     # 0x4afa5
jmp 0x4cfa4
leaq -0x1ffc(%rip), %rax     # 0x4afa8
movq %rax, 0x20(%r14)
movl $0x240, %edx            # imm = 0x240
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4420
movq %r14, %rdi
callq 0x4610
xorl %ebp, %ebp
movl %ebp, %eax
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)