// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x8c0, %rsp            # imm = 0x8C0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movl (%rax), %eax
decl %eax
movl %eax, %ecx
movq %rcx, -0x8c0(%rbp)
subl $0x32, %eax
ja 0xecad7
movq -0x8c0(%rbp), %rax
leaq 0xc80d(%rip), %rcx      # 0xf8c88
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rax
leaq -0x8f4f(%rip), %rcx     # 0xe3540
movq %rcx, 0x38(%rax)
jmp 0xecae0
movq -0x18(%rbp), %rax
leaq -0xa123(%rip), %rcx     # 0xe2380
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
leaq -0xa102(%rip), %rcx     # 0xe23b0
movq %rcx, 0x38(%rax)
movq -0x18(%rbp), %rax
leaq -0xaaf1(%rip), %rcx     # 0xe19d0
cmpq %rcx, 0x28(%rax)
jne 0xec4d8
movq -0x18(%rbp), %rax
leaq -0xa382(%rip), %rcx     # 0xe2150
movq %rcx, 0x30(%rax)
jmp 0xec550
movq -0x18(%rbp), %rax
leaq -0xa923(%rip), %rcx     # 0xe1bc0
cmpq %rcx, 0x28(%rax)
jne 0xec4fa
movq -0x18(%rbp), %rax
leaq -0xa304(%rip), %rcx     # 0xe21f0
movq %rcx, 0x30(%rax)
jmp 0xec54e
movq -0x18(%rbp), %rax
leaq -0xa855(%rip), %rcx     # 0xe1cb0
cmpq %rcx, 0x28(%rax)
jne 0xec51c
movq -0x18(%rbp), %rax
leaq -0xa266(%rip), %rcx     # 0xe22b0
movq %rcx, 0x30(%rax)
jmp 0xec54c
movq -0x18(%rbp), %rax
leaq -0xa497(%rip), %rcx     # 0xe2090
cmpq %rcx, 0x28(%rax)
jne 0xec53e
movq -0x18(%rbp), %rax
leaq -0xa288(%rip), %rcx     # 0xe22b0
movq %rcx, 0x30(%rax)
jmp 0xec54a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xecae7
jmp 0xec54c
jmp 0xec54e
jmp 0xec550
jmp 0xecae0
movq -0x18(%rbp), %rax
leaq -0x96b0(%rip), %rcx     # 0xe2eb0
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
leaq -0x968f(%rip), %rcx     # 0xe2ee0
movq %rcx, 0x38(%rax)
movq -0x18(%rbp), %rax
leaq -0x9ebe(%rip), %rcx     # 0xe26c0
cmpq %rcx, 0x28(%rax)
jne 0xec595
movq -0x18(%rbp), %rax
leaq -0x985f(%rip), %rcx     # 0xe2d30
movq %rcx, 0x30(%rax)
jmp 0xec60d
movq -0x18(%rbp), %rax
leaq -0x9df0(%rip), %rcx     # 0xe27b0
cmpq %rcx, 0x28(%rax)
jne 0xec5b7
movq -0x18(%rbp), %rax
leaq -0x9821(%rip), %rcx     # 0xe2d90
movq %rcx, 0x30(%rax)
jmp 0xec60b
movq -0x18(%rbp), %rax
leaq -0x9d22(%rip), %rcx     # 0xe28a0
cmpq %rcx, 0x28(%rax)
jne 0xec5d9
movq -0x18(%rbp), %rax
leaq -0x97e3(%rip), %rcx     # 0xe2df0
movq %rcx, 0x30(%rax)
jmp 0xec609
movq -0x18(%rbp), %rax
leaq -0x9c54(%rip), %rcx     # 0xe2990
cmpq %rcx, 0x28(%rax)
jne 0xec5fb
movq -0x18(%rbp), %rax
leaq -0x97a5(%rip), %rcx     # 0xe2e50
movq %rcx, 0x30(%rax)
jmp 0xec607
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xecae7
jmp 0xec609
jmp 0xec60b
jmp 0xec60d
jmp 0xecae0
movl $0x880, %edi            # imm = 0x880
callq 0x4650
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
jne 0xec633
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xecae7
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x28(%rbp), %rax
movl $0x3, (%rax)
movq -0x28(%rbp), %rax
leaq -0x2538(%rip), %rcx     # 0xea120
movq %rcx, 0x20(%rax)
movq -0x28(%rbp), %rax
leaq -0x2507(%rip), %rcx     # 0xea160
movq %rcx, 0x38(%rax)
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rcx
movq -0x28(%rbp), %rax
movq %rcx, 0x60(%rax)
movq -0x18(%rbp), %rax
movl 0x60(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x68(%rax)
movq -0x18(%rbp), %rax
movl 0x70(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x270(%rax)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x28(%rbp), %rcx
cmpl 0x68(%rcx), %eax
jge 0xec6f6
movq -0x28(%rbp), %rax
movq 0x60(%rax), %rax
movslq -0x1c(%rbp), %rcx
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movl %eax, -0x2c(%rbp)
cmpl $-0x1, -0x2c(%rbp)
jl 0xec6e9
cmpl $0x80, -0x2c(%rbp)
jge 0xec6e9
movl -0x1c(%rbp), %edx
movq -0x28(%rbp), %rax
movl -0x2c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
movl %edx, 0x6c(%rax,%rcx,4)
jmp 0xec6eb
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0xec6a1
movq -0x18(%rbp), %rax
leaq -0x3a41(%rip), %rcx     # 0xe8cc0
cmpq %rcx, 0x28(%rax)
jne 0xec71b
movq -0x28(%rbp), %rax
leaq -0x2b62(%rip), %rcx     # 0xe9bb0
movq %rcx, 0x30(%rax)
jmp 0xec7ea
movq -0x18(%rbp), %rax
leaq -0x39f6(%rip), %rcx     # 0xe8d30
cmpq %rcx, 0x28(%rax)
jne 0xec740
movq -0x28(%rbp), %rax
leaq -0x2b67(%rip), %rcx     # 0xe9bd0
movq %rcx, 0x30(%rax)
jmp 0xec7e8
movq -0x18(%rbp), %rax
leaq -0x384b(%rip), %rcx     # 0xe8f00
cmpq %rcx, 0x28(%rax)
jne 0xec765
movq -0x28(%rbp), %rax
leaq -0x29dc(%rip), %rcx     # 0xe9d80
movq %rcx, 0x30(%rax)
jmp 0xec7e6
movq -0x18(%rbp), %rax
leaq -0x3800(%rip), %rcx     # 0xe8f70
cmpq %rcx, 0x28(%rax)
jne 0xec787
movq -0x28(%rbp), %rax
leaq -0x29e1(%rip), %rcx     # 0xe9da0
movq %rcx, 0x30(%rax)
jmp 0xec7e4
movq -0x18(%rbp), %rax
leaq -0x3652(%rip), %rcx     # 0xe9140
cmpq %rcx, 0x28(%rax)
jne 0xec7a9
movq -0x28(%rbp), %rax
leaq -0x2853(%rip), %rcx     # 0xe9f50
movq %rcx, 0x30(%rax)
jmp 0xec7e2
movq -0x18(%rbp), %rax
leaq -0x3604(%rip), %rcx     # 0xe91b0
cmpq %rcx, 0x28(%rax)
jne 0xec7cb
movq -0x28(%rbp), %rax
leaq -0x2855(%rip), %rcx     # 0xe9f70
movq %rcx, 0x30(%rax)
jmp 0xec7e0
movq -0x28(%rbp), %rdi
callq 0x45a0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xecae7
jmp 0xec7e2
jmp 0xec7e4
jmp 0xec7e6
jmp 0xec7e8
jmp 0xec7ea
movq -0x18(%rbp), %rdi
movq -0x28(%rbp), %rsi
movl $0x880, %edx            # imm = 0x880
callq 0x43b0
movq -0x28(%rbp), %rdi
callq 0x45a0
jmp 0xecae0
movq -0x18(%rbp), %rax
leaq -0x8095(%rip), %rcx     # 0xe4780
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
leaq -0x8624(%rip), %rcx     # 0xe4200
movq %rcx, 0x38(%rax)
movq -0x18(%rbp), %rax
leaq -0x8a93(%rip), %rcx     # 0xe3da0
cmpq %rcx, 0x28(%rax)
jne 0xec84a
movq -0x18(%rbp), %rax
leaq -0x81c4(%rip), %rcx     # 0xe4680
movq %rcx, 0x30(%rax)
jmp 0xec89e
movq -0x18(%rbp), %rax
leaq -0x90e5(%rip), %rcx     # 0xe3770
cmpq %rcx, 0x28(%rax)
jne 0xec86c
movq -0x18(%rbp), %rax
leaq -0x84f6(%rip), %rcx     # 0xe4370
movq %rcx, 0x30(%rax)
jmp 0xec89c
movq -0x18(%rbp), %rax
leaq -0x89f7(%rip), %rcx     # 0xe3e80
cmpq %rcx, 0x28(%rax)
jne 0xec88e
movq -0x18(%rbp), %rax
leaq -0x8188(%rip), %rcx     # 0xe4700
movq %rcx, 0x30(%rax)
jmp 0xec89a
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xecae7
jmp 0xec89c
jmp 0xec89e
jmp 0xecae0
movq -0x18(%rbp), %rsi
leaq -0x8b0(%rbp), %rdi
movl $0x880, %edx            # imm = 0x880
callq 0x43b0
leaq -0x70bf(%rip), %rax     # 0xe5800
movq %rax, -0x890(%rbp)
leaq -0x74bd(%rip), %rax     # 0xe5410
movq %rax, -0x878(%rbp)
leaq -0x7e6b(%rip), %rax     # 0xe4a70
cmpq %rax, -0x888(%rbp)
jne 0xec8f4
leaq -0x723b(%rip), %rax     # 0xe56b0
movq %rax, -0x880(%rbp)
jmp 0xec944
leaq -0x7dcb(%rip), %rax     # 0xe4b30
cmpq %rax, -0x888(%rbp)
jne 0xec914
leaq -0x71db(%rip), %rax     # 0xe5730
movq %rax, -0x880(%rbp)
jmp 0xec942
leaq -0x7cfb(%rip), %rax     # 0xe4c20
cmpq %rax, -0x888(%rbp)
jne 0xec934
leaq -0x717b(%rip), %rax     # 0xe57b0
movq %rax, -0x880(%rbp)
jmp 0xec940
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xecae7
jmp 0xec942
jmp 0xec944
movq -0x840(%rbp), %rax
movq %rax, -0x840(%rbp)
movq -0x10(%rbp), %rdi
movq -0x840(%rbp), %rsi
callq 0xec440
cmpl $-0x1, %eax
jne 0xec973
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xecae7
movq -0x18(%rbp), %rdi
leaq -0x8b0(%rbp), %rsi
movl $0x880, %edx            # imm = 0x880
callq 0x43b0
jmp 0xecae0
movl $0x880, %edi            # imm = 0x880
callq 0x4650
movq %rax, -0x8b8(%rbp)
cmpq $0x0, -0x8b8(%rbp)
jne 0xec9b4
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xecae7
movq -0x18(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x8b8(%rbp), %rax
movq %rcx, 0x10(%rax)
movq -0x8b8(%rbp), %rax
movl $0x4, (%rax)
movq -0x8b8(%rbp), %rax
leaq -0x1652(%rip), %rcx     # 0xeb390
movq %rcx, 0x20(%rax)
movq -0x8b8(%rbp), %rax
leaq -0x15f4(%rip), %rcx     # 0xeb400
movq %rcx, 0x38(%rax)
movq -0x8b8(%rbp), %rax
leaq -0x1706(%rip), %rcx     # 0xeb300
movq %rcx, 0x30(%rax)
movq -0x18(%rbp), %rax
movq 0x60(%rax), %rcx
movq -0x8b8(%rbp), %rax
movq %rcx, 0x78(%rax)
movq -0x18(%rbp), %rax
movq 0x68(%rax), %rcx
movq -0x8b8(%rbp), %rax
movq %rcx, 0x80(%rax)
movq -0x10(%rbp), %rdi
movq -0x8b8(%rbp), %rax
movq 0x78(%rax), %rsi
callq 0xec440
cmpl $-0x1, %eax
je 0xeca68
movq -0x10(%rbp), %rdi
movq -0x8b8(%rbp), %rax
movq 0x80(%rax), %rsi
callq 0xec440
cmpl $-0x1, %eax
jne 0xeca85
movq -0x8b8(%rbp), %rax
movq 0x20(%rax), %rax
movq -0x8b8(%rbp), %rdi
callq *%rax
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xecae7
movq -0x18(%rbp), %rdi
movq -0x8b8(%rbp), %rsi
movl $0x880, %edx            # imm = 0x880
callq 0x43b0
movq -0x8b8(%rbp), %rdi
callq 0x45a0
jmp 0xecae0
movq -0x18(%rbp), %rax
leaq -0xbd3(%rip), %rcx      # 0xebee0
movq %rcx, 0x20(%rax)
movq -0x18(%rbp), %rax
leaq -0xbb2(%rip), %rcx      # 0xebf10
movq %rcx, 0x38(%rax)
movq -0x18(%rbp), %rax
leaq -0xcc1(%rip), %rcx      # 0xebe10
movq %rcx, 0x30(%rax)
jmp 0xecae0
movl $0xffffffff, -0x4(%rbp) # imm = 0xFFFFFFFF
jmp 0xecae7
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x8c0, %rsp            # imm = 0x8C0
popq %rbp
retq
nopw %cs:(%rax,%rax)