// File: /workspace/github_c_makefile_star2_O0/samtools[P]htslib/cram/cram_io.c
// Function: cram_compress_by_method
static char *cram_compress_by_method(cram_slice *s, char *in, size_t in_size,
                                     int content_id, size_t *out_size,
                                     enum cram_block_method_int method,
                                     int level, int strat) {
    switch (method) {
    case GZIP:
    case GZIP_RLE:
    case GZIP_1:
        // Read names bizarrely benefit from zlib over libdeflate for
        // mid-range compression levels.  Focusing purely of ratio or
        // speed, libdeflate still wins.  It also seems to win for
        // other data series too.
        //
        // Eg RN at level 5;  libdeflate=55.9MB  zlib=51.6MB
#ifdef HAVE_LIBDEFLATE
#  if (LIBDEFLATE_VERSION_MAJOR < 1 || (LIBDEFLATE_VERSION_MAJOR == 1 && LIBDEFLATE_VERSION_MINOR <= 8))
        if (content_id == DS_RN && level >= 4 && level <= 7)
            return zlib_mem_deflate(in, in_size, out_size, level, strat);
        else
#  endif
            return libdeflate_deflate(in, in_size, out_size, level, strat);
#else
        return zlib_mem_deflate(in, in_size, out_size, level, strat);
#endif

    case BZIP2: {
#ifdef HAVE_LIBBZ2
        unsigned int comp_size = in_size*1.01 + 600;
        char *comp = malloc(comp_size);
        if (!comp)
            return NULL;

        if (BZ_OK != BZ2_bzBuffToBuffCompress(comp, &comp_size,
                                              in, in_size,
                                              level, 0, 30)) {
            free(comp);
            return NULL;
        }
        *out_size = comp_size;
        return comp;
#else
        return NULL;
#endif
    }

    case FQZ:
    case FQZ_b:
    case FQZ_c:
    case FQZ_d: {
        // Extract the necessary portion of the slice into an fqz_slice struct.
        // These previously were the same thing, but this permits us to detach
        // the codec from the rest of this CRAM implementation.
        fqz_slice *f = malloc(2*s->hdr->num_records * sizeof(uint32_t) + sizeof(fqz_slice));
        if (!f)
            return NULL;
        f->num_records = s->hdr->num_records;
        f->len = (uint32_t *)(((char *)f) + sizeof(fqz_slice));
        f->flags = f->len + s->hdr->num_records;
        int i;
        for (i = 0; i < s->hdr->num_records; i++) {
            f->flags[i] = s->crecs[i].flags;
            f->len[i] = (i+1 < s->hdr->num_records
                         ? s->crecs[i+1].qual - s->crecs[i].qual
                         : s->block[DS_QS]->uncomp_size - s->crecs[i].qual);
        }
        char *comp = fqz_compress(strat & 0xff /* cram vers */, f,
                                  in, in_size, out_size, strat >> 8, NULL);
        free(f);
        return comp;
    }

    case LZMA:
#ifdef HAVE_LIBLZMA
        return lzma_mem_deflate(in, in_size, out_size, level);
#else
        return NULL;
#endif

    case RANS0:
    case RANS1: {
        unsigned int out_size_i;
        unsigned char *cp;
        cp = rans_compress((unsigned char *)in, in_size, &out_size_i,
                           method == RANS0 ? 0 : 1);
        *out_size = out_size_i;
        return (char *)cp;
    }

    case RANS_PR0:
    case RANS_PR1:
    case RANS_PR64:
    case RANS_PR9:
    case RANS_PR128:
    case RANS_PR129:
    case RANS_PR192:
    case RANS_PR193: {
        unsigned int out_size_i;
        unsigned char *cp;

        // see enum cram_block. We map RANS_* methods to order bit-fields
        static int methmap[] = { 1, 64,9, 128,129, 192,193 };

        int m = method == RANS_PR0 ? 0 : methmap[method - RANS_PR1];
        cp = rans_compress_4x16((unsigned char *)in, in_size, &out_size_i,
                                m | RANS_ORDER_SIMD_AUTO);
        *out_size = out_size_i;
        return (char *)cp;
    }

    case ARITH_PR0:
    case ARITH_PR1:
    case ARITH_PR64:
    case ARITH_PR9:
    case ARITH_PR128:
    case ARITH_PR129:
    case ARITH_PR192:
    case ARITH_PR193: {
        unsigned int out_size_i;
        unsigned char *cp;

        // see enum cram_block. We map ARITH_* methods to order bit-fields
        static int methmap[] = { 1, 64,9, 128,129, 192,193 };

        cp = arith_compress_to((unsigned char *)in, in_size, NULL, &out_size_i,
                               method == ARITH_PR0 ? 0 : methmap[method - ARITH_PR1]);
        *out_size = out_size_i;
        return (char *)cp;
    }

    case TOK3:
    case TOKA: {
        int out_len;
        int lev = level;
        if (method == TOK3 && lev > 3)
            lev = 3;
        uint8_t *cp = tok3_encode_names(in, in_size, lev, strat, &out_len, NULL);
        *out_size = out_len;
        return (char *)cp;
    }

    case RAW:
        break;

    default:
        return NULL;
    }

    return NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movl 0x18(%rbp), %eax
movl 0x10(%rbp), %eax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movl %ecx, -0x24(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movl -0x34(%rbp), %eax
movq %rax, -0xa0(%rbp)
subq $0x1f, %rax
ja 0x7b99e
movq -0xa0(%rbp), %rax
leaq 0x7993e(%rip), %rcx     # 0xf4e98
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rdx
movl 0x10(%rbp), %ecx
movl 0x18(%rbp), %r8d
callq 0x7b9c0
movq %rax, -0x8(%rbp)
jmp 0x7b9b0
movaps 0x74375(%rip), %xmm1    # 0xef900
movq -0x20(%rbp), %xmm0
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x74374(%rip), %xmm1    # 0xef910
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd 0x79fbd(%rip), %xmm1    # 0xf5570
mulsd %xmm1, %xmm0
movsd 0x79fb9(%rip), %xmm1    # 0xf5578
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %rax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl %eax, %edi
callq 0x4650
movq %rax, -0x40(%rbp)
cmpq $0x0, -0x40(%rbp)
jne 0x7b5ed
movq $0x0, -0x8(%rbp)
jmp 0x7b9b0
movq -0x40(%rbp), %rdi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rax
movl %eax, %ecx
movl 0x10(%rbp), %r8d
leaq -0x38(%rbp), %rsi
xorl %r9d, %r9d
movl $0x1e, (%rsp)
callq 0x4270
movl %eax, %ecx
xorl %eax, %eax
cmpl %ecx, %eax
je 0x7b630
movq -0x40(%rbp), %rdi
callq 0x45a0
movq $0x0, -0x8(%rbp)
jmp 0x7b9b0
movl -0x38(%rbp), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x40(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x7b9b0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x18(%rax), %eax
shll %eax
movslq %eax, %rdi
shlq $0x2, %rdi
addq $0x18, %rdi
callq 0x4650
movq %rax, -0x48(%rbp)
cmpq $0x0, -0x48(%rbp)
jne 0x7b67d
movq $0x0, -0x8(%rbp)
jmp 0x7b9b0
movq -0x10(%rbp), %rax
movq (%rax), %rax
movl 0x18(%rax), %ecx
movq -0x48(%rbp), %rax
movl %ecx, (%rax)
movq -0x48(%rbp), %rcx
addq $0x18, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x8(%rax)
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rcx
movq -0x10(%rbp), %rax
movq (%rax), %rax
movslq 0x18(%rax), %rax
shlq $0x2, %rax
addq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x18(%rcx), %eax
jge 0x7b7a3
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x4c(%rbp), %rcx
imulq $0x90, %rcx, %rcx
addq %rcx, %rax
movl 0xc(%rax), %edx
movq -0x48(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x4c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movq -0x10(%rbp), %rcx
movq (%rcx), %rcx
cmpl 0x18(%rcx), %eax
jge 0x7b752
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movl -0x4c(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x90, %rcx, %rcx
addq %rcx, %rax
movl 0x68(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movslq -0x4c(%rbp), %rdx
imulq $0x90, %rdx, %rdx
addq %rdx, %rcx
subl 0x68(%rcx), %eax
movl %eax, -0xa4(%rbp)
jmp 0x7b780
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movq 0x60(%rax), %rax
movl 0x14(%rax), %eax
movq -0x10(%rbp), %rcx
movq 0x30(%rcx), %rcx
movslq -0x4c(%rbp), %rdx
imulq $0x90, %rdx, %rdx
addq %rdx, %rcx
subl 0x68(%rcx), %eax
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %edx
movq -0x48(%rbp), %rax
movq 0x8(%rax), %rax
movslq -0x4c(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x7b6c6
movl 0x18(%rbp), %edi
andl $0xff, %edi
movq -0x48(%rbp), %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %r8
movl 0x18(%rbp), %r9d
sarl $0x8, %r9d
xorl %eax, %eax
movq $0x0, (%rsp)
callq 0x88150
movq %rax, -0x58(%rbp)
movq -0x48(%rbp), %rdi
callq 0x45a0
movq -0x58(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x7b9b0
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
movq -0x30(%rbp), %rdx
movl 0x10(%rbp), %ecx
callq 0x7bc90
movq %rax, -0x8(%rbp)
jmp 0x7b9b0
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %esi
movl -0x34(%rbp), %edx
movl $0x1, %ecx
xorl %eax, %eax
cmpl $0x4, %edx
cmovel %eax, %ecx
leaq -0x5c(%rbp), %rdx
callq 0xc3bc0
movq %rax, -0x68(%rbp)
movl -0x5c(%rbp), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x68(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x7b9b0
cmpl $0x5, -0x34(%rbp)
jne 0x7b85a
xorl %eax, %eax
movl %eax, -0xa8(%rbp)
jmp 0x7b873
movl -0x34(%rbp), %eax
subl $0x11, %eax
movslq %eax, %rcx
leaq 0x92226(%rip), %rax     # 0x10da90
movl (%rax,%rcx,4), %eax
movl %eax, -0xa8(%rbp)
movl -0xa8(%rbp), %eax
movl %eax, -0x7c(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %esi
movl -0x7c(%rbp), %ecx
orl $0x20000, %ecx          # imm = 0x20000
leaq -0x6c(%rbp), %rdx
callq 0x91850
movq %rax, -0x78(%rbp)
movl -0x6c(%rbp), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x78(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x7b9b0
movq -0x18(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x20(%rbp), %rax
movl %eax, -0xac(%rbp)
cmpl $0x6, -0x34(%rbp)
jne 0x7b8da
xorl %eax, %eax
movl %eax, -0xbc(%rbp)
jmp 0x7b8f3
movl -0x34(%rbp), %eax
subl $0x19, %eax
movslq %eax, %rcx
leaq 0x921c6(%rip), %rax     # 0x10dab0
movl (%rax,%rcx,4), %eax
movl %eax, -0xbc(%rbp)
movl -0xac(%rbp), %esi
movq -0xb8(%rbp), %rdi
movl -0xbc(%rbp), %r8d
xorl %eax, %eax
movl %eax, %edx
leaq -0x80(%rbp), %rcx
callq 0x827f0
movq %rax, -0x88(%rbp)
movl -0x80(%rbp), %eax
movl %eax, %ecx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x88(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x7b9b0
movl 0x10(%rbp), %eax
movl %eax, -0x90(%rbp)
cmpl $0x8, -0x34(%rbp)
jne 0x7b956
cmpl $0x3, -0x90(%rbp)
jle 0x7b956
movl $0x3, -0x90(%rbp)
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rax
movl %eax, %esi
movl -0x90(%rbp), %edx
movl 0x18(%rbp), %ecx
leaq -0x8c(%rbp), %r8
xorl %eax, %eax
movl %eax, %r9d
callq 0xc8750
movq %rax, -0x98(%rbp)
movslq -0x8c(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, (%rax)
movq -0x98(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x7b9b0
jmp 0x7b9a8
movq $0x0, -0x8(%rbp)
jmp 0x7b9b0
movq $0x0, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nopl (%rax)