// File: /workspace/github_c_makefile_star2_O1/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 0x9536a
decl %eax
cmpl $0x5, %eax
ja 0x956d5
leaq 0xfe65(%rip), %rcx      # 0xa5164
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq -0x696e(%rip), %rax     # 0x8e9a1
movq %rax, 0x20(%rbx)
leaq -0x696f(%rip), %rax     # 0x8e9ab
movq %rax, 0x38(%rbx)
movq 0x28(%rbx), %rax
leaq -0x7165(%rip), %rcx     # 0x8e1c4
cmpq %rcx, %rax
je 0x956a4
leaq -0x705f(%rip), %rcx     # 0x8e2da
cmpq %rcx, %rax
je 0x956c8
leaq -0x6f59(%rip), %rcx     # 0x8e3f0
cmpq %rcx, %rax
je 0x9535e
leaq -0x6be7(%rip), %rcx     # 0x8e76e
cmpq %rcx, %rax
jne 0x956d5
leaq -0x6a56(%rip), %rax     # 0x8e90f
jmp 0x956cf
leal -0x29(%rax), %ecx
cmpl $0x2, %ecx
jb 0x9538a
leal -0x2b(%rax), %ecx
cmpl $0x2, %ecx
jae 0x953f0
leaq -0x5cb3(%rip), %rax     # 0x8f6ce
movq %rax, 0x38(%rbx)
jmp 0x956d3
leaq -0x6090(%rip), %rax     # 0x8f301
movq %rax, 0x20(%rbx)
leaq -0x6091(%rip), %rax     # 0x8f30b
movq %rax, 0x38(%rbx)
movq 0x28(%rbx), %rax
leaq -0x67d4(%rip), %rcx     # 0x8ebd7
cmpq %rcx, %rax
je 0x95680
leaq -0x66cc(%rip), %rcx     # 0x8ecef
cmpq %rcx, %rax
je 0x95689
leaq -0x65c4(%rip), %rcx     # 0x8ee07
cmpq %rcx, %rax
je 0x956b6
leaq -0x64bc(%rip), %rcx     # 0x8ef1f
cmpq %rcx, %rax
jne 0x956d5
leaq -0x6105(%rip), %rax     # 0x8f2e6
jmp 0x956cf
cmpl $0x33, %eax
jne 0x956d5
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 -0x50b7(%rip), %rax     # 0x90393
cmpq %rax, %r13
je 0x956ad
leaq -0x5062(%rip), %rax     # 0x903f8
cmpq %rax, %r13
je 0x956f5
leaq -0x4fba(%rip), %rax     # 0x904b0
cmpq %rax, %r13
jne 0x956d5
leaq -0x480e(%rip), %rax     # 0x90c6c
jmp 0x956fc
leaq -0x5289(%rip), %rax     # 0x901fd
movq %rax, 0x20(%rbx)
leaq -0x5602(%rip), %rax     # 0x8fe8f
movq %rax, 0x38(%rbx)
movq 0x28(%rbx), %rax
leaq -0x58eb(%rip), %rcx     # 0x8fbb5
cmpq %rcx, %rax
je 0x9569b
leaq -0x5c1f(%rip), %rcx     # 0x8f891
cmpq %rcx, %rax
je 0x956bf
leaq -0x5852(%rip), %rcx     # 0x8fc6e
cmpq %rcx, %rax
jne 0x956d5
leaq -0x531f(%rip), %rax     # 0x901b1
jmp 0x956cf
movl $0x880, %edi            # imm = 0x880
callq 0x4680
testq %rax, %rax
je 0x956d5
movq %rax, %r14
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r14)
movl $0x3, (%r14)
leaq -0x1bc4(%rip), %rax     # 0x9393d
movq %rax, 0x20(%r14)
leaq -0x1bae(%rip), %rax     # 0x9395e
movq %rax, 0x38(%r14)
movq 0x68(%rbx), %rax
movq %rax, 0x60(%r14)
movl 0x60(%rbx), %eax
movl %eax, 0x68(%r14)
movl 0x70(%rbx), %ecx
movl %ecx, 0x270(%r14)
testl %eax, %eax
jle 0x9555b
xorl %eax, %eax
xorl %ecx, %ecx
movq 0x60(%r14), %rdx
movq (%rdx,%rax), %rdx
leal 0x1(%rdx), %esi
cmpl $0x80, %esi
ja 0x9554b
incl %edx
movl %ecx, 0x6c(%r14,%rdx,4)
incq %rcx
movslq 0x68(%r14), %rdx
addq $0x18, %rax
cmpq %rdx, %rcx
jl 0x95531
movq 0x28(%rbx), %rax
leaq -0x28ad(%rip), %rcx     # 0x92cb9
cmpq %rcx, %rax
je 0x956e9
leaq -0x2898(%rip), %rcx     # 0x92cde
cmpq %rcx, %rax
je 0x9577e
leaq -0x2741(%rip), %rcx     # 0x92e45
cmpq %rcx, %rax
je 0x95787
leaq -0x2733(%rip), %rcx     # 0x92e63
cmpq %rcx, %rax
je 0x95790
leaq -0x25e2(%rip), %rcx     # 0x92fc4
cmpq %rcx, %rax
je 0x95799
leaq -0x25d2(%rip), %rcx     # 0x92fe4
cmpq %rcx, %rax
je 0x957a2
movq %r14, %rdi
callq 0x45c0
jmp 0x956d5
leaq -0x699(%rip), %rax      # 0x94f3a
movq %rax, 0x20(%rbx)
leaq -0x69a(%rip), %rax      # 0x94f44
movq %rax, 0x38(%rbx)
leaq -0x7a4(%rip), %rax      # 0x94e45
jmp 0x956cf
movl $0x880, %edi            # imm = 0x880
callq 0x4680
testq %rax, %rax
je 0x956d5
movq %rax, %r15
movq 0x10(%rbx), %rax
movq %rax, 0x10(%r15)
movl $0x4, (%r15)
leaq -0x106c(%rip), %rax     # 0x945ae
movq %rax, 0x20(%r15)
leaq -0x1049(%rip), %rax     # 0x945dc
movq %rax, 0x38(%r15)
leaq -0x10cf(%rip), %rax     # 0x94561
movq %rax, 0x30(%r15)
movq 0x60(%rbx), %rsi
movq %rsi, 0x78(%r15)
movq 0x68(%rbx), %rax
movq %rax, 0x80(%r15)
movq %r14, %rdi
callq 0x952ca
cmpl $-0x1, %eax
je 0x95692
movq 0x80(%r15), %rsi
movq %r14, %rdi
callq 0x952ca
cmpl $-0x1, %eax
je 0x95692
movl $0x880, %edx            # imm = 0x880
movq %rbx, %rdi
movq %r15, %rsi
callq 0x43c0
movq %r15, %rdi
jmp 0x957c0
leaq -0x63ec(%rip), %rax     # 0x8f29b
jmp 0x956cf
leaq -0x63dd(%rip), %rax     # 0x8f2b3
jmp 0x956cf
movq %r15, %rdi
callq *0x20(%r15)
jmp 0x956d5
leaq -0x553c(%rip), %rax     # 0x90166
jmp 0x956cf
leaq -0x6dea(%rip), %rax     # 0x8e8c1
jmp 0x956cf
leaq -0x4ae0(%rip), %rax     # 0x90bd4
jmp 0x956fc
leaq -0x63f2(%rip), %rax     # 0x8f2cb
jmp 0x956cf
leaq -0x56f8(%rip), %rax     # 0x8ffce
jmp 0x956cf
leaq -0x6de8(%rip), %rax     # 0x8e8e7
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 -0x201d(%rip), %rax     # 0x936d3
jmp 0x957a9
leaq -0x4adc(%rip), %rax     # 0x90c20
movq %rax, 0x8(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x952ca
cmpl $-0x1, %eax
je 0x956d5
leaq 0x40(%rbx), %rax
movaps 0x40(%rsp), %xmm0
movaps 0x50(%rsp), %xmm1
movups %xmm1, 0x10(%rbx)
movups %xmm0, (%rbx)
leaq -0x4a2f(%rip), %rcx     # 0x90cfe
movq %rcx, 0x20(%rbx)
movq %r13, 0x28(%rbx)
movq 0x8(%rsp), %rcx
movq %rcx, 0x30(%rbx)
leaq -0x4dc1(%rip), %rcx     # 0x90984
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 0x956d3
leaq -0x20af(%rip), %rax     # 0x936d6
jmp 0x957a9
leaq -0x1ffa(%rip), %rax     # 0x93794
jmp 0x957a9
leaq -0x2000(%rip), %rax     # 0x93797
jmp 0x957a9
leaq -0x1f3b(%rip), %rax     # 0x93865
jmp 0x957a9
leaq -0x1f41(%rip), %rax     # 0x93868
movq %rax, 0x30(%r14)
movl $0x880, %edx            # imm = 0x880
movq %rbx, %rdi
movq %r14, %rsi
callq 0x43c0
movq %r14, %rdi
callq 0x45c0
jmp 0x956d3