// File: /workspace/github_c_makefile_star2_O2/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
pushq $-0x1
popq %rbp
leal -0x1(%rax), %ecx
cmpl $0x5, %ecx
jbe 0x747ae
leal -0x29(%rax), %ecx
cmpl $0x2, %ecx
jb 0x74820
leal -0x2b(%rax), %ecx
cmpl $0x2, %ecx
jae 0x74886
leaq -0x4d77(%rip), %rax     # 0x6fa2e
movq %rax, 0x38(%rbx)
jmp 0x74b72
leaq 0xfa1f(%rip), %rax      # 0x841d4
movslq (%rax,%rcx,4), %rcx
addq %rax, %rcx
jmpq *%rcx
leaq -0x561f(%rip), %rax     # 0x6f1a6
movq %rax, 0x20(%rbx)
leaq -0x5625(%rip), %rax     # 0x6f1ab
movq %rax, 0x38(%rbx)
movq 0x28(%rbx), %rax
leaq -0x5a9f(%rip), %rcx     # 0x6ed40
cmpq %rcx, %rax
je 0x74b37
leaq -0x59ac(%rip), %rcx     # 0x6ee43
cmpq %rcx, %rax
je 0x74b67
leaq -0x5932(%rip), %rcx     # 0x6eecd
cmpq %rcx, %rax
je 0x74814
leaq -0x576a(%rip), %rcx     # 0x6f0a1
cmpq %rcx, %rax
jne 0x74b74
leaq -0x56d0(%rip), %rax     # 0x6f14b
jmp 0x74b6e
leaq -0x510c(%rip), %rax     # 0x6f71b
movq %rax, 0x20(%rbx)
leaq -0x5112(%rip), %rax     # 0x6f720
movq %rax, 0x38(%rbx)
movq 0x28(%rbx), %rax
leaq -0x5530(%rip), %rcx     # 0x6f311
cmpq %rcx, %rax
je 0x74aa1
leaq -0x54af(%rip), %rcx     # 0x6f3a2
cmpq %rcx, %rax
je 0x74b1b
leaq -0x542e(%rip), %rcx     # 0x6f433
cmpq %rcx, %rax
je 0x74b49
leaq -0x53ad(%rip), %rcx     # 0x6f4c4
cmpq %rcx, %rax
jne 0x74b74
leaq -0x5181(%rip), %rax     # 0x6f700
jmp 0x74b6e
cmpl $0x33, %eax
jne 0x74b74
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 -0x4383(%rip), %rax     # 0x7055d
cmpq %rax, %r13
je 0x74b40
leaq -0x432d(%rip), %rax     # 0x705c3
cmpq %rax, %r13
je 0x74b88
leaq -0x42b2(%rip), %rax     # 0x7064e
cmpq %rax, %r13
jne 0x74b74
leaq -0x3bda(%rip), %rax     # 0x70d36
jmp 0x74b8f
leaq -0x4531(%rip), %rax     # 0x703eb
movq %rax, 0x20(%rbx)
leaq -0x4845(%rip), %rax     # 0x700e2
movq %rax, 0x38(%rbx)
movq 0x28(%rbx), %rax
leaq -0x4ad1(%rip), %rcx     # 0x6fe65
cmpq %rcx, %rax
je 0x74b2e
leaq -0x4e16(%rip), %rcx     # 0x6fb30
cmpq %rcx, %rax
je 0x74b52
leaq -0x4a65(%rip), %rcx     # 0x6fef1
cmpq %rcx, %rax
jne 0x74b74
leaq -0x45c6(%rip), %rax     # 0x703a0
jmp 0x74b6e
movl $0x880, %edi            # imm = 0x880
callq 0x4680
testq %rax, %rax
je 0x74b74
movq %rax, %r14
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r14)
movl $0x3, (%r14)
leaq -0x15ac(%rip), %rax     # 0x733eb
movq %rax, 0x20(%r14)
leaq -0x159b(%rip), %rax     # 0x73407
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)
xorl %edx, %edx
cmpq %rcx, %rdx
jge 0x74aad
movq (%rax), %rsi
leal 0x1(%rsi), %edi
cmpl $0x80, %edi
ja 0x749e0
incl %esi
movl %edx, 0x6c(%r14,%rsi,4)
incq %rdx
addq $0x18, %rax
jmp 0x749c2
leaq -0x557(%rip), %rax      # 0x74499
movq %rax, 0x20(%rbx)
leaq -0x55d(%rip), %rax      # 0x7449e
movq %rax, 0x38(%rbx)
leaq -0x5ca(%rip), %rax      # 0x7443c
jmp 0x74b6e
movl $0x880, %edi            # imm = 0x880
callq 0x4680
testq %rax, %rax
je 0x74b74
movq %rax, %r15
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r15)
movl $0x4, (%r15)
leaq -0xbe9(%rip), %rax      # 0x73e4e
movq %rax, 0x20(%r15)
leaq -0xbc6(%rip), %rax      # 0x73e7c
movq %rax, 0x38(%r15)
leaq -0xc4a(%rip), %rax      # 0x73e03
movq %rax, 0x30(%r15)
movq 0x60(%rbx), %rsi
movq %rsi, 0x78(%r15)
movq 0x68(%rbx), %r12
movq %r12, 0x80(%r15)
movq %r14, %rdi
callq 0x74762
cmpl $-0x1, %eax
je 0x74b24
movq %r14, %rdi
movq %r12, %rsi
callq 0x74762
cmpl $-0x1, %eax
je 0x74b24
movl $0x880, %edx            # imm = 0x880
movq %rbx, %rdi
movq %r15, %rsi
callq 0x43c0
movq %r15, %rdi
jmp 0x74c53
leaq -0x53f3(%rip), %rax     # 0x6f6b5
jmp 0x74b6e
movq 0x28(%rbx), %rax
leaq -0x21c7(%rip), %rcx     # 0x728f1
cmpq %rcx, %rax
je 0x74b5b
leaq -0x21b0(%rip), %rcx     # 0x72918
cmpq %rcx, %rax
je 0x74c11
leaq -0x20ac(%rip), %rcx     # 0x72a2c
cmpq %rcx, %rax
je 0x74c1a
leaq -0x209c(%rip), %rcx     # 0x72a4c
cmpq %rcx, %rax
je 0x74c23
leaq -0x1f9a(%rip), %rcx     # 0x72b5e
cmpq %rcx, %rax
je 0x74c2c
leaq -0x1f88(%rip), %rcx     # 0x72b80
cmpq %rcx, %rax
je 0x74c35
movq %r14, %rdi
callq 0x45c0
jmp 0x74b74
leaq -0x5455(%rip), %rax     # 0x6f6cd
jmp 0x74b6e
movq %r15, %rdi
callq 0x73e4e
jmp 0x74b74
leaq -0x47df(%rip), %rax     # 0x70356
jmp 0x74b6e
leaq -0x5a41(%rip), %rax     # 0x6f0fd
jmp 0x74b6e
leaq -0x3ea7(%rip), %rax     # 0x70ca0
jmp 0x74b8f
leaq -0x546b(%rip), %rax     # 0x6f6e5
jmp 0x74b6e
leaq -0x499b(%rip), %rax     # 0x701be
jmp 0x74b6e
leaq -0x19ca(%rip), %rax     # 0x73198
jmp 0x74c3c
leaq -0x5a4b(%rip), %rax     # 0x6f123
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 -0x3ea4(%rip), %rax     # 0x70ceb
movq %rax, 0x8(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x74762
cmpl $-0x1, %eax
je 0x74b74
leaq 0x40(%rbx), %rax
movaps 0x40(%rsp), %xmm0
movaps 0x50(%rsp), %xmm1
movups %xmm1, 0x10(%rbx)
movups %xmm0, (%rbx)
leaq -0x3e78(%rip), %rcx     # 0x70d48
movq %rcx, 0x20(%rbx)
movq %r13, 0x28(%rbx)
movq 0x8(%rsp), %rcx
movq %rcx, 0x30(%rbx)
leaq -0x40bd(%rip), %rcx     # 0x70b1b
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 0x74b72
leaq -0x1a7d(%rip), %rax     # 0x7319b
jmp 0x74c3c
leaq -0x19cd(%rip), %rax     # 0x73254
jmp 0x74c3c
leaq -0x19d3(%rip), %rax     # 0x73257
jmp 0x74c3c
leaq -0x191a(%rip), %rax     # 0x73319
jmp 0x74c3c
leaq -0x1920(%rip), %rax     # 0x7331c
movq %rax, 0x30(%r14)
movl $0x880, %edx            # imm = 0x880
movq %rbx, %rdi
movq %r14, %rsi
callq 0x43c0
movq %r14, %rdi
callq 0x45c0
jmp 0x74b72