#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 int /*<<< orphan*/ __m128;

/* Variables and functions */
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);
int /*<<< orphan*/ _mm_store_ss(float *, int /*<<< orphan*/);
void densearray_kernel_clamp_1d_f32_sse2(size_t dim, const float *src,
                                         float *dst, float lowerf,
                                         float upperf) {
  __m128 lower = _mm_set_ss(lowerf);
  __m128 upper = _mm_set_ss(upperf);
  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);
    _mm_store_ss(&dst[idx], y);
  }
}


x86 assembly (clang, -O0):
<densearray_kernel_clamp_1d_f32_sse2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movss  %xmm0,-0x1c(%rbp)
movss  %xmm1,-0x20(%rbp)
movss  -0x1c(%rbp),%xmm0
call   1030 <_mm_set_ss@plt>
mov    %eax,-0x24(%rbp)
movss  -0x20(%rbp),%xmm0
call   1030 <_mm_set_ss@plt>
mov    %eax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x8(%rbp),%rax
jae    11f5 <densearray_kernel_clamp_1d_f32_sse2+0xa5>
mov    -0x10(%rbp),%rdi
mov    -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
call   1070 <_mm_load_ss@plt>
mov    %eax,-0x34(%rbp)
mov    -0x24(%rbp),%edi
mov    -0x34(%rbp),%esi
call   1060 <_mm_max_ss@plt>
mov    %eax,%edi
mov    -0x28(%rbp),%esi
call   1050 <_mm_min_ss@plt>
mov    %eax,-0x38(%rbp)
mov    -0x18(%rbp),%rdi
mov    -0x30(%rbp),%rax
shl    $0x2,%rax
add    %rax,%rdi
mov    -0x38(%rbp),%esi
call   1040 <_mm_store_ss@plt>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
jmp    1190 <densearray_kernel_clamp_1d_f32_sse2+0x40>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<densearray_kernel_clamp_1d_f32_sse2>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
movss  %xmm1,0xc(%rsp)
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %rdi,%r15
call   1030 <_mm_set_ss@plt>
mov    %eax,%r12d
movss  0xc(%rsp),%xmm0
call   1030 <_mm_set_ss@plt>
test   %r15,%r15
je     11c3 <densearray_kernel_clamp_1d_f32_sse2+0x73>
mov    %eax,%ebp
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
call   1070 <_mm_load_ss@plt>
mov    %r12d,%edi
mov    %eax,%esi
call   1060 <_mm_max_ss@plt>
mov    %eax,%edi
mov    %ebp,%esi
call   1050 <_mm_min_ss@plt>
mov    %r14,%rdi
mov    %eax,%esi
call   1040 <_mm_store_ss@plt>
add    $0x4,%r14
add    $0x4,%rbx
add    $0xffffffffffffffff,%r15
jne    1190 <densearray_kernel_clamp_1d_f32_sse2+0x40>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
define void @densearray_kernel_clamp_1d_f32_sse2(i64 %0, float* %1, float* %2, float %3, float %4) {
%6 = alloca i64
%7 = alloca float*
%8 = alloca float*
%9 = alloca float
%10 = alloca float
%11 = alloca i32
%12 = alloca i32
%13 = alloca i64
%14 = alloca i32
%15 = alloca i32
store i64 %0, i64* %6
store float* %1, float** %7
store float* %2, float** %8
store float %3, float* %9
store float %4, float* %10
%16 = load float, float* %9
%17 = call i32 @_mm_set_ss(float %16)
store i32 %17, i32* %11
%18 = load float, float* %10
%19 = call i32 @_mm_set_ss(float %18)
store i32 %19, i32* %12
store i64 0, i64* %13
br label %20
20: ; preds = %39, %5
%21 = load i64, i64* %13
%22 = load i64, i64* %6
%23 = icmp ult i64 %21, %22
br i1 %23, label %24, label %42
24: ; preds = %20
%25 = load float*, float** %7
%26 = load i64, i64* %13
%27 = getelementptr inbounds float, float* %25, i64 %26
%28 = call i32 @_mm_load_ss(float* %27)
store i32 %28, i32* %14
%29 = load i32, i32* %11
%30 = load i32, i32* %14
%31 = call i32 @_mm_max_ss(i32 %29, i32 %30)
%32 = load i32, i32* %12
%33 = call i32 @_mm_min_ss(i32 %31, i32 %32)
store i32 %33, i32* %15
%34 = load float*, float** %8
%35 = load i64, i64* %13
%36 = getelementptr inbounds float, float* %34, i64 %35
%37 = load i32, i32* %15
%38 = call i32 @_mm_store_ss(float* %36, i32 %37)
br label %39
39: ; preds = %24
%40 = load i64, i64* %13
%41 = add i64 %40, 1
store i64 %41, i64* %13
br label %20
42: ; preds = %20
ret void
}

LLVM IR (-O2):
define void @densearray_kernel_clamp_1d_f32_sse2(i64 %0, float* %1, float* %2, float %3, float %4) {
%6 = tail call i32 @_mm_set_ss(float %3)
%7 = tail call i32 @_mm_set_ss(float %4)
%8 = icmp eq i64 %0, 0
br i1 %8, label %9, label %10
9: ; preds = %10, %5
ret void
10: ; preds = %5, %10
%11 = phi i64 [ %18, %10 ], [ 0, %5 ]
%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 %6, i32 %13)
%15 = tail call i32 @_mm_min_ss(i32 %14, i32 %7)
%16 = getelementptr inbounds float, float* %2, i64 %11
%17 = tail call i32 @_mm_store_ss(float* %16, i32 %15)
%18 = add nuw i64 %11, 1
%19 = icmp eq i64 %18, %0
br i1 %19, label %9, label %10
}