// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x40(%rbp)
subl $0x5, %eax
ja 0xd50de
movq -0x40(%rbp), %rax
leaq 0x10d12(%rip), %rcx     # 0xe5a94
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
leaq -0x7266(%rip), %rcx     # 0xcdb30
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
leaq -0x7245(%rip), %rcx     # 0xcdb60
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
leaq -0x7ca4(%rip), %rcx     # 0xcd110
cmpq %rcx, 0x18(%rax)
jne 0xd4dcb
movq -0x18(%rbp), %rax
leaq -0x7425(%rip), %rcx     # 0xcd9a0
movq %rcx, 0x20(%rax)
jmp 0xd4dfb
movq -0x18(%rbp), %rax
leaq -0x7996(%rip), %rcx     # 0xcd440
cmpq %rcx, 0x18(%rax)
jne 0xd4ded
movq -0x18(%rbp), %rax
leaq -0x7407(%rip), %rcx     # 0xcd9e0
movq %rcx, 0x20(%rax)
jmp 0xd4df9
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd50ee
jmp 0xd4dfb
jmp 0xd50e7
movl $0x240, %edi            # imm = 0x240
callq 0x69c0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl $0x3, (%rax)
movq -0x28(%rbp), %rax
leaq -0x4393(%rip), %rcx     # 0xd0a90
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
leaq -0x4362(%rip), %rcx     # 0xd0ad0
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rax
movl 0x30(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x38(%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x38(%rcx), %eax
jge 0xd4eaf
movq -0x28(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x1c(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movl (%rax), %eax
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
jl 0xd4ea2
cmpl $0x80, -0x2c(%rbp)
jge 0xd4ea2
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, 0x3c(%rax,%rcx,4)
jmp 0xd4ea4
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xd4e5b
movq -0x18(%rbp), %rax
leaq -0x50ea(%rip), %rcx     # 0xcfdd0
cmpq %rcx, 0x18(%rax)
jne 0xd4ed4
movq -0x28(%rbp), %rax
leaq -0x47bb(%rip), %rcx     # 0xd0710
movq %rcx, 0x20(%rax)
jmp 0xd4f55
movq -0x18(%rbp), %rax
leaq -0x50af(%rip), %rcx     # 0xcfe30
cmpq %rcx, 0x18(%rax)
jne 0xd4ef6
movq -0x28(%rbp), %rax
leaq -0x47c0(%rip), %rcx     # 0xd0730
movq %rcx, 0x20(%rax)
jmp 0xd4f53
movq -0x18(%rbp), %rax
leaq -0x4f11(%rip), %rcx     # 0xcfff0
cmpq %rcx, 0x18(%rax)
jne 0xd4f18
movq -0x28(%rbp), %rax
leaq -0x4642(%rip), %rcx     # 0xd08d0
movq %rcx, 0x20(%rax)
jmp 0xd4f51
movq -0x18(%rbp), %rax
leaq -0x4ec3(%rip), %rcx     # 0xd0060
cmpq %rcx, 0x18(%rax)
jne 0xd4f3a
movq -0x28(%rbp), %rax
leaq -0x4644(%rip), %rcx     # 0xd08f0
movq %rcx, 0x20(%rax)
jmp 0xd4f4f
movq -0x28(%rbp), %rdi
callq 0x6880
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd50ee
jmp 0xd4f51
jmp 0xd4f53
jmp 0xd4f55
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl $0x240, %edx            # imm = 0x240
callq 0x6570
movq -0x28(%rbp), %rdi
callq 0x6880
jmp 0xd50e7
movq -0x18(%rbp), %rax
leaq -0x5cf0(%rip), %rcx     # 0xcf290
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
leaq -0x632f(%rip), %rcx     # 0xcec60
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
leaq -0x6e1e(%rip), %rcx     # 0xce180
cmpq %rcx, 0x18(%rax)
jne 0xd4fb5
movq -0x18(%rbp), %rax
leaq -0x608f(%rip), %rcx     # 0xcef20
movq %rcx, 0x20(%rax)
jmp 0xd4fe5
movq -0x18(%rbp), %rax
leaq -0x6860(%rip), %rcx     # 0xce760
cmpq %rcx, 0x18(%rax)
jne 0xd4fd7
movq -0x18(%rbp), %rax
leaq -0x5dc1(%rip), %rcx     # 0xcf210
movq %rcx, 0x20(%rax)
jmp 0xd4fe3
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd50ee
jmp 0xd4fe5
jmp 0xd50e7
movl $0x240, %edi            # imm = 0x240
callq 0x69c0
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movl $0x4, (%rax)
movq -0x38(%rbp), %rax
leaq -0x2c0d(%rip), %rcx     # 0xd2400
movq %rcx, 0x10(%rax)
movq -0x38(%rbp), %rax
leaq -0x2bac(%rip), %rcx     # 0xd2470
movq %rcx, 0x28(%rax)
movq -0x38(%rbp), %rax
leaq -0x2cab(%rip), %rcx     # 0xd2380
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
movq 0x30(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x48(%rax)
movq -0x18(%rbp), %rax
movq 0x38(%rax), %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x50(%rax)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x48(%rax), %rsi
callq 0xd4d50
cmpl $-0x1, %eax
je 0xd507b
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rax
movq 0x50(%rax), %rsi
callq 0xd4d50
cmpl $-0x1, %eax
jne 0xd5092
movq -0x38(%rbp), %rax
movq 0x10(%rax), %rax
movq -0x38(%rbp), %rdi
callq *%rax
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd50ee
movq -0x18(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x240, %edx            # imm = 0x240
callq 0x6570
movq -0x38(%rbp), %rdi
callq 0x6880
jmp 0xd50e7
movq -0x18(%rbp), %rax
leaq -0x1bca(%rip), %rcx     # 0xd34f0
movq %rcx, 0x10(%rax)
movq -0x18(%rbp), %rax
leaq -0x1ba9(%rip), %rcx     # 0xd3520
movq %rcx, 0x28(%rax)
movq -0x18(%rbp), %rax
leaq -0x1e58(%rip), %rcx     # 0xd3280
movq %rcx, 0x20(%rax)
jmp 0xd50e7
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xd50ee
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)