#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */
typedef scalar_t__ uint8_t;
typedef int /*<<< orphan*/ __m128;

/* Variables and functions */
int /*<<< orphan*/ _mm_add_ps(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_cvtepi32_ps(int /*<<< orphan*/);
scalar_t__ _mm_cvtss_f32(int /*<<< orphan*/);
int /*<<< orphan*/ _mm_cvttps_epi32(int /*<<< orphan*/);
int /*<<< orphan*/ _mm_load_ss(float const *);
int /*<<< orphan*/ _mm_max_ss(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_min_ss(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ _mm_set_ss(float);
void densearray_kernel_round_clamp_1d_f32_to_u8_sse2(size_t dim,
                                                     const float *src,
                                                     uint8_t *dst) {
  __m128 lower = _mm_set_ss(0.0f);
  __m128 upper = _mm_set_ss(255.0f);
  __m128 one_half = _mm_set_ss(0.5f);
  __m128 one = _mm_set_ss(1.0f);
  for (size_t idx = 0; idx < dim; idx++) {
    __m128 x = _mm_load_ss(&src[idx]);
    __m128 y = _mm_min_ss(_mm_max_ss(lower, x), upper);
    __m128 u = _mm_add_ps(y, one_half);
    __m128 v = _mm_cvtepi32_ps(_mm_cvttps_epi32(u));
    dst[idx] = (uint8_t)(_mm_cvtss_f32(v));
  }
}


x86 assembly (clang, -O0):
<densearray_kernel_round_clamp_1d_f32_to_u8_sse2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
xorps  %xmm0,%xmm0
call   1060 <_mm_set_ss@plt>
mov    %eax,-0x1c(%rbp)
movss  0xe61(%rip),%xmm0
call   1060 <_mm_set_ss@plt>
mov    %eax,-0x20(%rbp)
movss  0xe4d(%rip),%xmm0
call   1060 <_mm_set_ss@plt>
mov    %eax,-0x24(%rbp)
movss  0xe39(%rip),%xmm0
call   1060 <_mm_set_ss@plt>
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    125c <densearray_kernel_round_clamp_1d_f32_to_u8_sse2+0xdc>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   10a0 <_mm_load_ss@plt>
mov    %eax,-0x34(%rbp)
mov    -0x1c(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1090 <_mm_max_ss@plt>
mov    %eax,%edi
mov    -0x20(%rbp),%esi
call   1070 <_mm_min_ss@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%edi
mov    -0x24(%rbp),%esi
call   1080 <_mm_add_ps@plt>
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%edi
call   1050 <_mm_cvttps_epi32@plt>
mov    %eax,%edi
call   1040 <_mm_cvtepi32_ps@plt>
mov    %eax,-0x40(%rbp)
mov    -0x40(%rbp),%edi
call   1030 <_mm_cvtss_f32@plt>
mov    %rax,%rdx
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    11d7 <densearray_kernel_round_clamp_1d_f32_to_u8_sse2+0x57>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<densearray_kernel_round_clamp_1d_f32_to_u8_sse2>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,(%rsp)
mov    %rsi,%rbx
mov    %rdi,%r15
xorps  %xmm0,%xmm0
call   1060 <_mm_set_ss@plt>
mov    %eax,%r12d
movss  0xe58(%rip),%xmm0
call   1060 <_mm_set_ss@plt>
mov    %eax,%r13d
movss  0xe4c(%rip),%xmm0
call   1060 <_mm_set_ss@plt>
mov    %eax,%ebp
movss  0xe41(%rip),%xmm0
call   1060 <_mm_set_ss@plt>
test   %r15,%r15
je     122f <densearray_kernel_round_clamp_1d_f32_to_u8_sse2+0xaf>
xor    %r14d,%r14d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
call   10a0 <_mm_load_ss@plt>
mov    %r12d,%edi
mov    %eax,%esi
call   1090 <_mm_max_ss@plt>
mov    %eax,%edi
mov    %r13d,%esi
call   1070 <_mm_min_ss@plt>
mov    %eax,%edi
mov    %ebp,%esi
call   1080 <_mm_add_ps@plt>
mov    %eax,%edi
call   1050 <_mm_cvttps_epi32@plt>
mov    %eax,%edi
call   1040 <_mm_cvtepi32_ps@plt>
mov    %eax,%edi
call   1030 <_mm_cvtss_f32@plt>
mov    (%rsp),%rcx
mov    %rax,(%rcx,%r14,8)
add    $0x1,%r14
add    $0x4,%rbx
cmp    %r14,%r15
jne    11e0 <densearray_kernel_round_clamp_1d_f32_to_u8_sse2+0x60>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @densearray_kernel_round_clamp_1d_f32_to_u8_sse2(i64 %0, float* %1, i64* %2) {
%4 = alloca i64
%5 = alloca float*
%6 = alloca i64*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i64
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
store i64 %0, i64* %4
store float* %1, float** %5
store i64* %2, i64** %6
%16 = call i32 @_mm_set_ss(float 0.000000e+00)
store i32 %16, i32* %7
%17 = call i32 @_mm_set_ss(float 2.550000e+02)
store i32 %17, i32* %8
%18 = call i32 @_mm_set_ss(float 5.000000e-01)
store i32 %18, i32* %9
%19 = call i32 @_mm_set_ss(float 1.000000e+00)
store i32 %19, i32* %10
store i64 0, i64* %11
br label %20
20: ; preds = %45, %3
%21 = load i64, i64* %11
%22 = load i64, i64* %4
%23 = icmp ult i64 %21, %22
br i1 %23, label %24, label %48
24: ; preds = %20
%25 = load float*, float** %5
%26 = load i64, i64* %11
%27 = getelementptr inbounds float, float* %25, i64 %26
%28 = call i32 @_mm_load_ss(float* %27)
store i32 %28, i32* %12
%29 = load i32, i32* %7
%30 = load i32, i32* %12
%31 = call i32 @_mm_max_ss(i32 %29, i32 %30)
%32 = load i32, i32* %8
%33 = call i32 @_mm_min_ss(i32 %31, i32 %32)
store i32 %33, i32* %13
%34 = load i32, i32* %13
%35 = load i32, i32* %9
%36 = call i32 @_mm_add_ps(i32 %34, i32 %35)
store i32 %36, i32* %14
%37 = load i32, i32* %14
%38 = call i32 @_mm_cvttps_epi32(i32 %37)
%39 = call i32 @_mm_cvtepi32_ps(i32 %38)
store i32 %39, i32* %15
%40 = load i32, i32* %15
%41 = call i64 @_mm_cvtss_f32(i32 %40)
%42 = load i64*, i64** %6
%43 = load i64, i64* %11
%44 = getelementptr inbounds i64, i64* %42, i64 %43
store i64 %41, i64* %44
br label %45
45: ; preds = %24
%46 = load i64, i64* %11
%47 = add i64 %46, 1
store i64 %47, i64* %11
br label %20
48: ; preds = %20
ret void
}

LLVM IR (-O2):
define void @densearray_kernel_round_clamp_1d_f32_to_u8_sse2(i64 %0, float* %1, i64* nocapture writeonly %2) {
%4 = tail call i32 @_mm_set_ss(float 0.000000e+00)
%5 = tail call i32 @_mm_set_ss(float 2.550000e+02)
%6 = tail call i32 @_mm_set_ss(float 5.000000e-01)
%7 = tail call i32 @_mm_set_ss(float 1.000000e+00)
%8 = icmp eq i64 %0, 0
br i1 %8, label %9, label %10
9: ; preds = %10, %3
ret void
10: ; preds = %3, %10
%11 = phi i64 [ %21, %10 ], [ 0, %3 ]
%12 = getelementptr inbounds float, float* %1, i64 %11
%13 = tail call i32 @_mm_load_ss(float* %12)
%14 = tail call i32 @_mm_max_ss(i32 %4, i32 %13)
%15 = tail call i32 @_mm_min_ss(i32 %14, i32 %5)
%16 = tail call i32 @_mm_add_ps(i32 %15, i32 %6)
%17 = tail call i32 @_mm_cvttps_epi32(i32 %16)
%18 = tail call i32 @_mm_cvtepi32_ps(i32 %17)
%19 = tail call i64 @_mm_cvtss_f32(i32 %18)
%20 = getelementptr inbounds i64, i64* %2, i64 %11
store i64 %19, i64* %20
%21 = add nuw i64 %11, 1
%22 = icmp eq i64 %21, %0
br i1 %22, label %9, label %10
}