// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/cram/cram_codecs.c
// Function: cram_xpack_encode_init
cram_codec *cram_xpack_encode_init(cram_stats *st,
                                   enum cram_encoding codec,
                                   enum cram_external_type option,
                                   void *dat,
                                   int version, varint_vec *vv) {
    cram_codec *c;

    if (!(c = malloc(sizeof(*c))))
        return NULL;

    c->codec  = E_XPACK;
    c->free   = cram_xpack_encode_free;
    if (option == E_LONG)
        c->encode = cram_xpack_encode_long;
    else if (option == E_INT)
        c->encode = cram_xpack_encode_int;
    else
        c->encode = cram_xpack_encode_char;
    c->store  = cram_xpack_encode_store;
    c->flush  = cram_xpack_encode_flush;

    cram_xpack_encoder *e = (cram_xpack_encoder *)dat;
    c->u.e_xpack.nbits = e->nbits;
    c->u.e_xpack.nval = e->nval;
    c->u.e_xpack.sub_codec = cram_encoder_init(e->sub_encoding, NULL,
                                               E_BYTE_ARRAY, e->sub_codec_dat,
                                               version, vv);

    // Initialise fwd and rev maps
    memcpy(c->u.e_xpack.map, e->map, sizeof(e->map)); // P,A,C,K to 0,1,2,3
    int i, n;
    for (i = n = 0; i < 256; i++)
        if (e->map[i] != -1)
            c->u.e_xpack.rmap[n++] = i;               // 0,1,2,3 to P,A,C,K
    if (n != e->nval) {
        fprintf(stderr, "Incorrectly specified number of map items in PACK\n");
        return NULL;
    }

    return c;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movl $0x880, %edi            # imm = 0x880
callq 0x4650
movq %rax, -0x38(%rbp)
cmpq $0x0, %rax
jne 0xe589f
movq $0x0, -0x8(%rbp)
jmp 0xe5a11
movq -0x38(%rbp), %rax
movl $0x33, (%rax)
movq -0x38(%rbp), %rax
leaq -0xb4(%rip), %rcx       # 0xe5800
movq %rcx, 0x20(%rax)
cmpl $0x2, -0x18(%rbp)
jne 0xe58cf
movq -0x38(%rbp), %rax
leaq -0x219(%rip), %rcx      # 0xe56b0
movq %rcx, 0x30(%rax)
jmp 0xe58f7
cmpl $0x1, -0x18(%rbp)
jne 0xe58e6
movq -0x38(%rbp), %rax
leaq -0x1b0(%rip), %rcx      # 0xe5730
movq %rcx, 0x30(%rax)
jmp 0xe58f5
movq -0x38(%rbp), %rax
leaq -0x141(%rip), %rcx      # 0xe57b0
movq %rcx, 0x30(%rax)
jmp 0xe58f7
movq -0x38(%rbp), %rax
leaq -0x4f2(%rip), %rcx      # 0xe5410
movq %rcx, 0x38(%rax)
movq -0x38(%rbp), %rax
leaq -0x5d1(%rip), %rcx      # 0xe5340
movq %rcx, 0x48(%rax)
movq -0x20(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movl (%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x60(%rax)
movq -0x40(%rbp), %rax
movl 0x18(%rax), %ecx
movq -0x38(%rbp), %rax
movl %ecx, 0x78(%rax)
movq -0x40(%rbp), %rax
movl 0x4(%rax), %edi
movq -0x40(%rbp), %rax
movq 0x8(%rax), %rcx
movl -0x24(%rbp), %r8d
movq -0x30(%rbp), %r9
xorl %eax, %eax
movl %eax, %esi
movl $0x4, %edx
callq 0xe5a20
movq %rax, %rcx
movq -0x38(%rbp), %rax
movq %rcx, 0x70(%rax)
movq -0x38(%rbp), %rdi
addq $0x60, %rdi
addq $0x41c, %rdi            # imm = 0x41C
movq -0x40(%rbp), %rsi
addq $0x41c, %rsi            # imm = 0x41C
movl $0x400, %edx            # imm = 0x400
callq 0x43b0
movl $0x0, -0x48(%rbp)
movl $0x0, -0x44(%rbp)
cmpl $0x100, -0x44(%rbp)     # imm = 0x100
jge 0xe59db
movq -0x40(%rbp), %rax
movslq -0x44(%rbp), %rcx
cmpl $-0x1, 0x41c(%rax,%rcx,4)
je 0xe59ce
movl -0x44(%rbp), %edx
movq -0x38(%rbp), %rax
movl -0x48(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x48(%rbp)
movslq %ecx, %rcx
movl %edx, 0x7c(%rax,%rcx,4)
jmp 0xe59d0
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xe599a
movl -0x48(%rbp), %eax
movq -0x40(%rbp), %rcx
cmpl 0x18(%rcx), %eax
je 0xe5a09
movq 0x275f2(%rip), %rax     # 0x10cfe0
movq (%rax), %rdi
leaq 0x134d3(%rip), %rsi     # 0xf8ecb
movb $0x0, %al
callq 0x46d0
movq $0x0, -0x8(%rbp)
jmp 0xe5a11
movq -0x38(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
nopl (%rax,%rax)