#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 */

/* Variables and functions */
float fmaxf(float, float);
float fminf(float, float);
scalar_t__ isnan(float);
float flex_clamp(float value, float minValue, float maxValue) {
  if (isnan(value)) {
    return value;
  }
  if (isnan(maxValue)) {
    return fmaxf(value, minValue);
  } else {
    return fmaxf(fminf(value, maxValue), minValue);
  }
}


x86 assembly (clang, -O0):
<flex_clamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movss  %xmm0,-0x8(%rbp)
movss  %xmm1,-0xc(%rbp)
movss  %xmm2,-0x10(%rbp)
movss  -0x8(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     114a <flex_clamp+0x3a>
movss  -0x8(%rbp),%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11e0 <flex_clamp+0xd0>
movss  -0x10(%rbp),%xmm0
call   1030 <isnan@plt>
cmp    $0x0,%rax
je     1190 <flex_clamp+0x80>
movss  -0x8(%rbp),%xmm3
movss  -0xc(%rbp),%xmm2
movaps %xmm2,%xmm4
movaps %xmm3,%xmm0
cmpunordss %xmm0,%xmm0
movaps %xmm0,%xmm1
pand   %xmm4,%xmm1
maxss  %xmm3,%xmm2
pandn  %xmm2,%xmm0
por    %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
jmp    11e0 <flex_clamp+0xd0>
movss  -0x8(%rbp),%xmm2
movss  -0x10(%rbp),%xmm1
movaps %xmm1,%xmm4
movaps %xmm2,%xmm3
cmpunordss %xmm3,%xmm3
movaps %xmm3,%xmm0
pand   %xmm4,%xmm0
minss  %xmm2,%xmm1
pandn  %xmm1,%xmm3
por    %xmm0,%xmm3
movss  -0xc(%rbp),%xmm2
movaps %xmm2,%xmm4
movaps %xmm3,%xmm0
cmpunordss %xmm0,%xmm0
movaps %xmm0,%xmm1
pand   %xmm4,%xmm1
maxss  %xmm3,%xmm2
pandn  %xmm2,%xmm0
por    %xmm1,%xmm0
movss  %xmm0,-0x4(%rbp)
movss  -0x4(%rbp),%xmm0
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<flex_clamp>:
sub    $0x38,%rsp
movaps %xmm2,0x20(%rsp)
movaps %xmm1,0x10(%rsp)
movss  %xmm0,0xc(%rsp)
call   1030 <isnan@plt>
test   %rax,%rax
je     1139 <flex_clamp+0x29>
movss  0xc(%rsp),%xmm0
add    $0x38,%rsp
ret
movaps 0x20(%rsp),%xmm0
call   1030 <isnan@plt>
test   %rax,%rax
je     1170 <flex_clamp+0x60>
movss  0xc(%rsp),%xmm3
movaps %xmm3,%xmm0
cmpunordss %xmm3,%xmm0
movaps %xmm0,%xmm1
movaps 0x10(%rsp),%xmm2
andps  %xmm2,%xmm1
maxss  %xmm3,%xmm2
andnps %xmm2,%xmm0
orps   %xmm1,%xmm0
add    $0x38,%rsp
ret
movss  0xc(%rsp),%xmm2
movaps %xmm2,%xmm0
cmpunordss %xmm2,%xmm0
movaps %xmm0,%xmm1
movaps 0x20(%rsp),%xmm3
andps  %xmm3,%xmm1
minss  %xmm2,%xmm3
andnps %xmm3,%xmm0
orps   %xmm1,%xmm0
movaps 0x10(%rsp),%xmm3
movaps %xmm3,%xmm1
maxss  %xmm0,%xmm1
cmpunordss %xmm0,%xmm0
movaps %xmm0,%xmm2
andnps %xmm1,%xmm2
andps  %xmm3,%xmm0
orps   %xmm2,%xmm0
add    $0x38,%rsp
ret

LLVM IR (-O0):
define float @flex_clamp(float %0, float %1, float %2) {
%4 = alloca float
%5 = alloca float
%6 = alloca float
%7 = alloca float
store float %0, float* %5
store float %1, float* %6
store float %2, float* %7
%8 = load float, float* %5
%9 = call i64 @isnan(float %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = load float, float* %5
store float %12, float* %4
br label %27
13: ; preds = %3
%14 = load float, float* %7
%15 = call i64 @isnan(float %14)
%16 = icmp ne i64 %15, 0
br i1 %16, label %17, label %21
17: ; preds = %13
%18 = load float, float* %5
%19 = load float, float* %6
%20 = call float @llvm.maxnum.f32(float %18, float %19)
store float %20, float* %4
br label %27
21: ; preds = %13
%22 = load float, float* %5
%23 = load float, float* %7
%24 = call float @llvm.minnum.f32(float %22, float %23)
%25 = load float, float* %6
%26 = call float @llvm.maxnum.f32(float %24, float %25)
store float %26, float* %4
br label %27
27: ; preds = %21, %17, %11
%28 = load float, float* %4
ret float %28
}

LLVM IR (-O2):
define float @flex_clamp(float %0, float %1, float %2) {
%4 = tail call i64 @isnan(float %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %3
%7 = tail call i64 @isnan(float %2)
%8 = icmp eq i64 %7, 0
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = tail call float @llvm.maxnum.f32(float %0, float %1)
br label %14
11: ; preds = %6
%12 = tail call float @llvm.minnum.f32(float %0, float %2)
%13 = tail call float @llvm.maxnum.f32(float %12, float %1)
br label %14
14: ; preds = %3, %11, %9
%15 = phi float [ %10, %9 ], [ %13, %11 ], [ %0, %3 ]
ret float %15
}