// File: /workspace/github_c_makefile_star2_O3/samtools[P]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_CONST_INT:
    case E_CONST_BYTE:
        // shares struct with decode
        c->store = cram_const_encode_store;
        break;

    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_long)
            c->encode = cram_external_encode_long;
        else if (c->decode == cram_external_decode_char)
            c->encode = cram_external_encode_char;
        else if (c->decode == cram_external_decode_block)
            c->encode = cram_external_encode_char;
        else
            return -1;
        break;

    case E_VARINT_SIGNED:
    case E_VARINT_UNSIGNED:
        // shares struct with decode
        c->free = cram_varint_encode_free;
        c->store = cram_varint_encode_store;
        if (c->decode == cram_varint_decode_int)
            c->encode = cram_varint_encode_int;
        else if (c->decode == cram_varint_decode_sint)
            c->encode = cram_varint_encode_sint;
        else if (c->decode == cram_varint_decode_long)
            c->encode = cram_varint_encode_long;
        else if (c->decode == cram_varint_decode_slong)
            c->encode = cram_varint_encode_slong;
        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));
        if (!t) return -1;
        t->vv     = c->vv;
        t->codec = E_HUFFMAN;
        t->free = cram_huffman_encode_free;
        t->store = cram_huffman_encode_store;
        t->u.e_huffman.codes = c->u.huffman.codes;
        t->u.e_huffman.nvals = c->u.huffman.ncodes;
        t->u.e_huffman.option = c->u.huffman.option;
        for (j = 0; j < t->u.e_huffman.nvals; j++) {
            int32_t sym = t->u.e_huffman.codes[j].symbol;
            if (sym >= -1 && sym < MAX_HUFF)
                t->u.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 if (c->decode == cram_huffman_decode_long0)
            t->encode = cram_huffman_encode_long0;
        else if (c->decode == cram_huffman_decode_long)
            t->encode = cram_huffman_encode_long;
        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_long)
            c->encode = cram_beta_encode_long;
        else if (c->decode == cram_beta_decode_char)
            c->encode = cram_beta_encode_char;
        else
            return -1;
        break;

    case E_XPACK: {
        // shares struct with decode
        cram_codec t = *c;
        t.free = cram_xpack_encode_free;
        t.store = cram_xpack_encode_store;
        if (t.decode == cram_xpack_decode_long)
            t.encode = cram_xpack_encode_long;
        else if (t.decode == cram_xpack_decode_int)
            t.encode = cram_xpack_encode_int;
        else if (t.decode == cram_xpack_decode_char)
            t.encode = cram_xpack_encode_char;
        else
            return -1;
        t.u.e_xpack.sub_codec = t.u.xpack.sub_codec;
        if (cram_codec_decoder2encoder(fd, t.u.e_xpack.sub_codec) == -1)
            return -1;
        *c = t;
        break;
    }

    case E_BYTE_ARRAY_LEN: {
        cram_codec *t = malloc(sizeof(*t));
        if (!t) return -1;
        t->vv     = c->vv;
        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->u.e_byte_array_len.len_codec = c->u.byte_array_len.len_codec;
        t->u.e_byte_array_len.val_codec = c->u.byte_array_len.val_codec;
        if (cram_codec_decoder2encoder(fd, t->u.e_byte_array_len.len_codec) == -1 ||
            cram_codec_decoder2encoder(fd, t->u.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 %r13
pushq %r12
pushq %rbx
subq $0x868, %rsp            # imm = 0x868
movq %rsi, %rbx
movq %rdi, %r14
movl (%rsi), %eax
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
cmpl $0x28, %eax
jg 0x92a14
decl %eax
cmpl $0x5, %eax
ja 0x92d73
leaq 0xff3b(%rip), %rcx      # 0xa28e4
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x6a4d(%rip), %rax     # 0x8bf6c
movq %rax, 0x20(%rbx)
leaq -0x6a4e(%rip), %rax     # 0x8bf76
movq %rax, 0x38(%rbx)
movq 0x28(%rbx), %rax
leaq -0x71f3(%rip), %rcx     # 0x8b7e0
cmpq %rcx, %rax
je 0x92d42
leaq -0x70fd(%rip), %rcx     # 0x8b8e6
cmpq %rcx, %rax
je 0x92d66
leaq -0x7007(%rip), %rcx     # 0x8b9ec
cmpq %rcx, %rax
je 0x92a08
leaq -0x6cc6(%rip), %rcx     # 0x8bd39
cmpq %rcx, %rax
jne 0x92d73
leaq -0x6b35(%rip), %rax     # 0x8beda
jmp 0x92d6d
leal -0x29(%rax), %ecx
cmpl $0x2, %ecx
jb 0x92a34
leal -0x2b(%rax), %ecx
cmpl $0x2, %ecx
jae 0x92a9a
leaq -0x5da2(%rip), %rax     # 0x8cc89
movq %rax, 0x38(%rbx)
jmp 0x92d71
leaq -0x61f0(%rip), %rax     # 0x8c84b
movq %rax, 0x20(%rbx)
leaq -0x61f1(%rip), %rax     # 0x8c855
movq %rax, 0x38(%rbx)
movq 0x28(%rbx), %rax
leaq -0x68d7(%rip), %rcx     # 0x8c17e
cmpq %rcx, %rax
je 0x92d1d
leaq -0x67de(%rip), %rcx     # 0x8c287
cmpq %rcx, %rax
je 0x92d26
leaq -0x66e5(%rip), %rcx     # 0x8c390
cmpq %rcx, %rax
je 0x92d54
leaq -0x65ec(%rip), %rcx     # 0x8c499
cmpq %rcx, %rax
jne 0x92d73
leaq -0x6265(%rip), %rax     # 0x8c830
jmp 0x92d6d
cmpl $0x33, %eax
jne 0x92d73
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movaps %xmm0, 0x40(%rsp)
movaps %xmm1, 0x50(%rsp)
movq 0x28(%rbx), %r13
movups 0x40(%rbx), %xmm0
movaps %xmm0, 0x10(%rsp)
movups 0x50(%rbx), %xmm0
movaps %xmm0, 0x20(%rsp)
movups 0x60(%rbx), %xmm0
movaps %xmm0, 0x30(%rsp)
movq 0x70(%rbx), %r12
leaq 0x78(%rbx), %r15
leaq 0x60(%rsp), %rdi
movl $0x808, %edx            # imm = 0x808
movq %r15, %rsi
callq 0x43c0
leaq -0x51c5(%rip), %rax     # 0x8d92f
cmpq %rax, %r13
je 0x92d4b
leaq -0x5170(%rip), %rax     # 0x8d994
cmpq %rax, %r13
je 0x92d93
leaq -0x4fd2(%rip), %rax     # 0x8db42
cmpq %rax, %r13
jne 0x92d73
leaq -0x4819(%rip), %rax     # 0x8e30b
jmp 0x92d9a
leaq -0x5397(%rip), %rax     # 0x8d799
movq %rax, 0x20(%rbx)
leaq -0x56f4(%rip), %rax     # 0x8d447
movq %rax, 0x38(%rbx)
movq 0x28(%rbx), %rax
leaq -0x59f3(%rip), %rcx     # 0x8d157
cmpq %rcx, %rax
je 0x92d39
leaq -0x5d32(%rip), %rcx     # 0x8ce28
cmpq %rcx, %rax
je 0x92d5d
leaq -0x595a(%rip), %rcx     # 0x8d210
cmpq %rcx, %rax
jne 0x92d73
leaq -0x542d(%rip), %rax     # 0x8d74d
jmp 0x92d6d
movl $0x880, %edi            # imm = 0x880
callq 0x4680
testq %rax, %rax
je 0x92d73
movq %rax, %r14
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r14)
movl $0x3, (%r14)
leaq -0x1b6e(%rip), %rax     # 0x9103d
movq %rax, 0x20(%r14)
leaq -0x1b58(%rip), %rax     # 0x9105e
movq %rax, 0x38(%r14)
movq 0x68(%rbx), %rax
movq %rax, 0x60(%r14)
movslq 0x60(%rbx), %rcx
movl %ecx, 0x68(%r14)
movl 0x70(%rbx), %edx
movl %edx, 0x270(%r14)
testq %rcx, %rcx
jle 0x92bfc
xorl %edx, %edx
movq (%rax), %rsi
leal 0x1(%rsi), %edi
cmpl $0x80, %edi
ja 0x92bf0
incl %esi
movl %edx, 0x6c(%r14,%rsi,4)
incq %rdx
addq $0x18, %rax
cmpq %rcx, %rdx
jb 0x92bdb
movq 0x28(%rbx), %rax
leaq -0x292a(%rip), %rcx     # 0x902dd
cmpq %rcx, %rax
je 0x92d87
leaq -0x2915(%rip), %rcx     # 0x90302
cmpq %rcx, %rax
je 0x92e1c
leaq -0x27eb(%rip), %rcx     # 0x9043c
cmpq %rcx, %rax
je 0x92e25
leaq -0x26fa(%rip), %rcx     # 0x9053d
cmpq %rcx, %rax
je 0x92e2e
leaq -0x25d5(%rip), %rcx     # 0x90672
cmpq %rcx, %rax
je 0x92e37
leaq -0x2540(%rip), %rcx     # 0x90717
cmpq %rcx, %rax
je 0x92e40
movq %r14, %rdi
callq 0x45c0
jmp 0x92d73
leaq -0x681(%rip), %rax      # 0x925f3
movq %rax, 0x20(%rbx)
leaq -0x682(%rip), %rax      # 0x925fd
movq %rax, 0x38(%rbx)
leaq -0x78f(%rip), %rax      # 0x924fb
jmp 0x92d6d
movl $0x880, %edi            # imm = 0x880
callq 0x4680
testq %rax, %rax
je 0x92d73
movq %rax, %r15
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r15)
movl $0x4, (%r15)
leaq -0x1081(%rip), %rax     # 0x91c3a
movq %rax, 0x20(%r15)
leaq -0x105e(%rip), %rax     # 0x91c68
movq %rax, 0x38(%r15)
leaq -0x10e4(%rip), %rax     # 0x91bed
movq %rax, 0x30(%r15)
movq 0x60(%rbx), %rsi
movq %rsi, 0x78(%r15)
movq 0x68(%rbx), %r12
movq %r12, 0x80(%r15)
movq %r14, %rdi
callq 0x92974
cmpl $-0x1, %eax
je 0x92d2f
movq %r14, %rdi
movq %r12, %rsi
callq 0x92974
cmpl $-0x1, %eax
je 0x92d2f
movl $0x880, %edx            # imm = 0x880
movq %rbx, %rdi
movq %r15, %rsi
callq 0x43c0
movq %r15, %rdi
jmp 0x92e5e
leaq -0x653f(%rip), %rax     # 0x8c7e5
jmp 0x92d6d
leaq -0x6530(%rip), %rax     # 0x8c7fd
jmp 0x92d6d
movq %r15, %rdi
callq 0x91c3a
jmp 0x92d73
leaq -0x563e(%rip), %rax     # 0x8d702
jmp 0x92d6d
leaq -0x6ebd(%rip), %rax     # 0x8be8c
jmp 0x92d6d
leaq -0x4adf(%rip), %rax     # 0x8e273
jmp 0x92d9a
leaq -0x6546(%rip), %rax     # 0x8c815
jmp 0x92d6d
leaq -0x57ff(%rip), %rax     # 0x8d565
jmp 0x92d6d
leaq -0x6ebb(%rip), %rax     # 0x8beb2
movq %rax, 0x30(%rbx)
xorl %ebp, %ebp
movl %ebp, %eax
addq $0x868, %rsp            # imm = 0x868
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0x1fbc(%rip), %rax     # 0x90dd2
jmp 0x92e47
leaq -0x4adb(%rip), %rax     # 0x8e2bf
movq %rax, 0x8(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x92974
cmpl $-0x1, %eax
je 0x92d73
leaq 0x40(%rbx), %rax
movaps 0x40(%rsp), %xmm0
movaps 0x50(%rsp), %xmm1
movups %xmm1, 0x10(%rbx)
movups %xmm0, (%rbx)
leaq -0x4a2e(%rip), %rcx     # 0x8e39d
movq %rcx, 0x20(%rbx)
movq %r13, 0x28(%rbx)
movq 0x8(%rsp), %rcx
movq %rcx, 0x30(%rbx)
leaq -0x4da0(%rip), %rcx     # 0x8e043
movq %rcx, 0x38(%rbx)
movaps 0x10(%rsp), %xmm0
movaps 0x20(%rsp), %xmm1
movaps 0x30(%rsp), %xmm2
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
movq %r12, 0x70(%rbx)
leaq 0x60(%rsp), %rsi
movl $0x808, %edx            # imm = 0x808
movq %r15, %rdi
callq 0x43c0
jmp 0x92d71
leaq -0x204e(%rip), %rax     # 0x90dd5
jmp 0x92e47
leaq -0x1f95(%rip), %rax     # 0x90e97
jmp 0x92e47
leaq -0x1f9b(%rip), %rax     # 0x90e9a
jmp 0x92e47
leaq -0x1ed9(%rip), %rax     # 0x90f65
jmp 0x92e47
leaq -0x1edf(%rip), %rax     # 0x90f68
movq %rax, 0x30(%r14)
movl $0x880, %edx            # imm = 0x880
movq %rbx, %rdi
movq %r14, %rsi
callq 0x43c0
movq %r14, %rdi
callq 0x45c0
jmp 0x92d71