#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 */
scalar_t__ stdlib_base_is_nan(double const);
scalar_t__ stdlib_base_is_negative_zero(double const);
double stdlib_base_clamp(const double v, const double min, const double max) {
  if (stdlib_base_is_nan(v) || stdlib_base_is_nan(min) ||
      stdlib_base_is_nan(max)) {
    return 0.0 / 0.0;
  }
  if (v < min) {
    return min;
  }
  if (v > max) {
    return max;
  }
  if (min == 0.0 && stdlib_base_is_negative_zero(v)) {
    return min;
  }
  if (v == 0.0 && stdlib_base_is_negative_zero(max)) {
    return max;
  }
  return v;
}


x86 assembly (clang, -O0):
<stdlib_base_clamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1040 <stdlib_base_is_nan@plt>
cmp    $0x0,%rax
jne    1173 <stdlib_base_clamp+0x53>
movsd  -0x18(%rbp),%xmm0
call   1040 <stdlib_base_is_nan@plt>
cmp    $0x0,%rax
jne    1173 <stdlib_base_clamp+0x53>
movsd  -0x20(%rbp),%xmm0
call   1040 <stdlib_base_is_nan@plt>
cmp    $0x0,%rax
je     1185 <stdlib_base_clamp+0x65>
movsd  0xe85(%rip),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1247 <stdlib_base_clamp+0x127>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11a8 <stdlib_base_clamp+0x88>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1247 <stdlib_base_clamp+0x127>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11c7 <stdlib_base_clamp+0xa7>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1247 <stdlib_base_clamp+0x127>
movsd  -0x18(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    1202 <stdlib_base_clamp+0xe2>
jp     1202 <stdlib_base_clamp+0xe2>
movsd  -0x10(%rbp),%xmm0
call   1030 <stdlib_base_is_negative_zero@plt>
cmp    $0x0,%rax
je     1202 <stdlib_base_clamp+0xe2>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1247 <stdlib_base_clamp+0x127>
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jne    123d <stdlib_base_clamp+0x11d>
jp     123d <stdlib_base_clamp+0x11d>
movsd  -0x20(%rbp),%xmm0
call   1030 <stdlib_base_is_negative_zero@plt>
cmp    $0x0,%rax
je     123d <stdlib_base_clamp+0x11d>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1247 <stdlib_base_clamp+0x127>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<stdlib_base_clamp>:
sub    $0x18,%rsp
movsd  %xmm2,0x8(%rsp)
movsd  %xmm1,0x10(%rsp)
movsd  %xmm0,(%rsp)
call   1040 <stdlib_base_is_nan@plt>
movsd  0xebe(%rip),%xmm0
test   %rax,%rax
je     114c <stdlib_base_clamp+0x2c>
add    $0x18,%rsp
ret
movsd  0x10(%rsp),%xmm0
call   1040 <stdlib_base_is_nan@plt>
test   %rax,%rax
je     1169 <stdlib_base_clamp+0x49>
movsd  0xe9c(%rip),%xmm0
add    $0x18,%rsp
ret
movsd  0x8(%rsp),%xmm0
call   1040 <stdlib_base_is_nan@plt>
test   %rax,%rax
movsd  0xe81(%rip),%xmm0
jne    1147 <stdlib_base_clamp+0x27>
movsd  (%rsp),%xmm0
movsd  0x10(%rsp),%xmm2
ucomisd %xmm0,%xmm2
jbe    119b <stdlib_base_clamp+0x7b>
movapd %xmm2,%xmm0
add    $0x18,%rsp
ret
movsd  0x8(%rsp),%xmm1
ucomisd %xmm1,%xmm0
jbe    11b0 <stdlib_base_clamp+0x90>
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret
xorpd  %xmm1,%xmm1
ucomisd %xmm1,%xmm2
jne    11d9 <stdlib_base_clamp+0xb9>
jp     11d9 <stdlib_base_clamp+0xb9>
movsd  (%rsp),%xmm0
call   1030 <stdlib_base_is_negative_zero@plt>
xorpd  %xmm1,%xmm1
movsd  0x10(%rsp),%xmm0
test   %rax,%rax
jne    1147 <stdlib_base_clamp+0x27>
movsd  (%rsp),%xmm0
ucomisd %xmm1,%xmm0
jne    1200 <stdlib_base_clamp+0xe0>
jp     1200 <stdlib_base_clamp+0xe0>
movsd  0x8(%rsp),%xmm0
call   1030 <stdlib_base_is_negative_zero@plt>
movsd  0x8(%rsp),%xmm0
test   %rax,%rax
jne    1147 <stdlib_base_clamp+0x27>
movsd  (%rsp),%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @stdlib_base_clamp(double %0, double %1, double %2) {
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store double %0, double* %5
store double %1, double* %6
store double %2, double* %7
%8 = load double, double* %5
%9 = call i64 @stdlib_base_is_nan(double %8)
%10 = icmp ne i64 %9, 0
br i1 %10, label %19, label %11
11: ; preds = %3
%12 = load double, double* %6
%13 = call i64 @stdlib_base_is_nan(double %12)
%14 = icmp ne i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %11
%16 = load double, double* %7
%17 = call i64 @stdlib_base_is_nan(double %16)
%18 = icmp ne i64 %17, 0
br i1 %18, label %19, label %20
19: ; preds = %15, %11, %3
store double 0x7FF8000000000000, double* %4
br label %52
20: ; preds = %15
%21 = load double, double* %5
%22 = load double, double* %6
%23 = fcmp olt double %21, %22
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = load double, double* %6
store double %25, double* %4
br label %52
26: ; preds = %20
%27 = load double, double* %5
%28 = load double, double* %7
%29 = fcmp ogt double %27, %28
br i1 %29, label %30, label %32
30: ; preds = %26
%31 = load double, double* %7
store double %31, double* %4
br label %52
32: ; preds = %26
%33 = load double, double* %6
%34 = fcmp oeq double %33, 0.000000e+00
br i1 %34, label %35, label %41
35: ; preds = %32
%36 = load double, double* %5
%37 = call i64 @stdlib_base_is_negative_zero(double %36)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %41
39: ; preds = %35
%40 = load double, double* %6
store double %40, double* %4
br label %52
41: ; preds = %35, %32
%42 = load double, double* %5
%43 = fcmp oeq double %42, 0.000000e+00
br i1 %43, label %44, label %50
44: ; preds = %41
%45 = load double, double* %7
%46 = call i64 @stdlib_base_is_negative_zero(double %45)
%47 = icmp ne i64 %46, 0
br i1 %47, label %48, label %50
48: ; preds = %44
%49 = load double, double* %7
store double %49, double* %4
br label %52
50: ; preds = %44, %41
%51 = load double, double* %5
store double %51, double* %4
br label %52
52: ; preds = %50, %48, %39, %30, %24, %19
%53 = load double, double* %4
ret double %53
}

LLVM IR (-O2):
define double @stdlib_base_clamp(double %0, double %1, double %2) {
%4 = tail call i64 @stdlib_base_is_nan(double %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %27
6: ; preds = %3
%7 = tail call i64 @stdlib_base_is_nan(double %1)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %27
9: ; preds = %6
%10 = tail call i64 @stdlib_base_is_nan(double %2)
%11 = icmp eq i64 %10, 0
br i1 %11, label %12, label %27
12: ; preds = %9
%13 = fcmp olt double %0, %1
br i1 %13, label %27, label %14
14: ; preds = %12
%15 = fcmp ogt double %0, %2
br i1 %15, label %27, label %16
16: ; preds = %14
%17 = fcmp oeq double %1, 0.000000e+00
br i1 %17, label %18, label %21
18: ; preds = %16
%19 = tail call i64 @stdlib_base_is_negative_zero(double %0)
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %27
21: ; preds = %18, %16
%22 = fcmp oeq double %0, 0.000000e+00
br i1 %22, label %23, label %26
23: ; preds = %21
%24 = tail call i64 @stdlib_base_is_negative_zero(double %2)
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %27
26: ; preds = %23, %21
br label %27
27: ; preds = %23, %18, %14, %12, %3, %6, %9, %26
%28 = phi double [ %0, %26 ], [ 0x7FF8000000000000, %9 ], [ 0x7FF8000000000000, %6 ], [ 0x7FF8000000000000, %3 ], [ %1, %12 ], [ %2, %14 ], [ %1, %18 ], [ %2, %23 ]
ret double %28
}