// File: /workspace/github_c_makefile_star2_O2/samtools[P]htslib/htscodecs/htscodecs/rANS_static4x16pr.c
// Function: rans_enc_func
static inline
unsigned char *(*rans_enc_func(int do_simd, int order))
    (unsigned char *in,
     unsigned int in_size,
     unsigned char *out,
     unsigned int *out_size) {

    if (!do_simd) { // SIMD disabled
        return order & 1
            ? rans_compress_O1_4x16
            : rans_compress_O0_4x16;
    }

#ifdef NO_THREADS
    htscodecs_tls_cpu_init();
#else
    int err = pthread_once(&rans_cpu_once, htscodecs_tls_cpu_init);
    if (err != 0) {
        fprintf(stderr, "Initialising TLS data failed: pthread_once: %s\n",
                strerror(err));
        fprintf(stderr, "Using scalar code only\n");
    }
#endif

    int have_e_sse4_1  = have_sse4_1;
    int have_e_avx2    = have_avx2;
    int have_e_avx512f = have_avx512f;

    if (!(rans_cpu & RANS_CPU_ENC_AVX512)) have_e_avx512f = 0;
    if (!(rans_cpu & RANS_CPU_ENC_AVX2))   have_e_avx2    = 0;
    if (!(rans_cpu & RANS_CPU_ENC_SSE4))   have_e_sse4_1  = 0;

    if (order & 1) {
        // With simulated gathers, the AVX512 is now slower than AVX2, so
        // we avoid using it unless asking for the real avx512 gather.
        // Note for testing we do -c 0x0404 to enable AVX512 and disable AVX2.
        // We then need to call the avx512 func regardless.
        int use_gather;
#ifdef USE_GATHER
        use_gather = 1;
#else
        use_gather = !have_e_avx2;
#endif

#if defined(HAVE_AVX512)
        if (have_e_avx512f && (!is_amd || !have_e_avx2) && use_gather)
            return rans_compress_O1_32x16_avx512;
#endif
#if defined(HAVE_AVX2)
        if (have_e_avx2)
            return rans_compress_O1_32x16_avx2;
#endif
#if defined(HAVE_SSE4_1) && defined(HAVE_SSSE3) && defined(HAVE_POPCNT)
        if (have_e_sse4_1)
            return rans_compress_O1_32x16;
#endif
        return rans_compress_O1_32x16;
    } else {
#if defined(HAVE_AVX512)
        if (have_e_avx512f && (!is_amd || !have_e_avx2))
            return rans_compress_O0_32x16_avx512;
#endif
#if defined(HAVE_AVX2)
        if (have_e_avx2)
            return rans_compress_O0_32x16_avx2;
#endif
#if defined(HAVE_SSE4_1) && defined(HAVE_SSSE3) && defined(HAVE_POPCNT)
        if (have_e_sse4_1)
            return rans_compress_O0_32x16;
#endif
        return rans_compress_O0_32x16;
    }
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
movl %esi, %ebx
testl %edi, %edi
je 0x508f9
leaq 0x4e87b(%rip), %rdi     # 0x9f114
leaq -0xc9e(%rip), %rsi      # 0x4fc02
callq 0x4470
testl %eax, %eax
jne 0x50947
movl 0x4dedd(%rip), %ecx     # 0x9e790
movl %ecx, %eax
shll $0x1d, %eax
sarl $0x1f, %eax
andl 0x4e84f(%rip), %eax     # 0x9f110
shll $0x1e, %ecx
sarl $0x1f, %ecx
andl 0x4e83f(%rip), %ecx     # 0x9f10c
testb $0x1, %bl
jne 0x50910
testl %eax, %eax
je 0x508ec
cmpl $0x0, 0x4e81f(%rip)     # 0x9f0fc
setne %al
testl %ecx, %ecx
setne %dl
andb %al, %dl
cmpb $0x1, %dl
jne 0x5093a
testl %ecx, %ecx
jne 0x50931
leaq 0xbce9(%rip), %rax      # 0x5c5e0
jmp 0x50941
testb $0x1, %bl
leaq -0x1aa2(%rip), %rcx     # 0x4ee61
leaq 0xc3d(%rip), %rax       # 0x51547
cmoveq %rcx, %rax
jmp 0x50941
testl %eax, %eax
jne 0x5091d
leaq 0xce2c(%rip), %rax      # 0x5d747
jmp 0x50924
leaq 0x6d86(%rip), %rax      # 0x576aa
testl %ecx, %ecx
je 0x50941
leaq 0x37c4(%rip), %rax      # 0x540f3
jmp 0x50941
leaq 0x2234(%rip), %rax      # 0x52b6c
jmp 0x50941
leaq 0x5d57(%rip), %rax      # 0x56698
popq %rbx
popq %r14
popq %r15
retq
movq 0x4d68a(%rip), %r15     # 0x9dfd8
movq (%r15), %r14
movl %eax, %edi
callq 0x4150
leaq 0x2d316(%rip), %rsi     # 0x7dc75
movq %r14, %rdi
movq %rax, %rdx
xorl %eax, %eax
callq 0x4700
movq (%r15), %rcx
leaq 0x2d32f(%rip), %rdi     # 0x7dca5
pushq $0x17
popq %rsi
pushq $0x1
popq %rdx
callq 0x49b0
jmp 0x508ad