#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 */
int /*<<< orphan*/ printf(char *);
int rc_saturate_double(double *val, double min, double max) {
  if (min > max) {
    printf("ERROR: in rc_saturate_double, min must be less than max\n");
    return -1;
  }
  if (*val > max) {
    *val = max;
    return 1;
  } else if (*val < min) {
    *val = min;
    return 1;
  }
  return 0;
}


x86 assembly (clang, -O0):
<rc_saturate_double>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
movsd  %xmm0,-0x18(%rbp)
movsd  %xmm1,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    114e <rc_saturate_double+0x3e>
lea    0xec3(%rip),%rdi
call   1030 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b6 <rc_saturate_double+0xa6>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    117a <rc_saturate_double+0x6a>
movsd  -0x20(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11b6 <rc_saturate_double+0xa6>
mov    -0x10(%rbp),%rax
movsd  (%rax),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    11aa <rc_saturate_double+0x9a>
movsd  -0x18(%rbp),%xmm0
mov    -0x10(%rbp),%rax
movsd  %xmm0,(%rax)
movl   $0x1,-0x4(%rbp)
jmp    11b6 <rc_saturate_double+0xa6>
jmp    11af <rc_saturate_double+0x9f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rc_saturate_double>:
push   %rax
ucomisd %xmm1,%xmm0
jbe    112a <rc_saturate_double+0x1a>
lea    0xee2(%rip),%rdi
call   1030 <puts@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
movsd  (%rdi),%xmm2
ucomisd %xmm1,%xmm2
jbe    113a <rc_saturate_double+0x2a>
movsd  %xmm1,(%rdi)
jmp    1146 <rc_saturate_double+0x36>
xor    %eax,%eax
ucomisd %xmm2,%xmm0
jbe    114b <rc_saturate_double+0x3b>
movsd  %xmm0,(%rdi)
mov    $0x1,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [57 x i8] c"ERROR: in rc_saturate_double, min must be less than max\0A\00"
define i32 @rc_saturate_double(double* %0, double %1, double %2) {
%4 = alloca i32
%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* %6
%9 = load double, double* %7
%10 = fcmp ogt double %8, %9
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 @printf(i8* getelementptr inbounds ([57 x i8], [57 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %4
br label %31
13: ; preds = %3
%14 = load double*, double** %5
%15 = load double, double* %14
%16 = load double, double* %7
%17 = fcmp ogt double %15, %16
br i1 %17, label %18, label %21
18: ; preds = %13
%19 = load double, double* %7
%20 = load double*, double** %5
store double %19, double* %20
store i32 1, i32* %4
br label %31
21: ; preds = %13
%22 = load double*, double** %5
%23 = load double, double* %22
%24 = load double, double* %6
%25 = fcmp olt double %23, %24
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load double, double* %6
%28 = load double*, double** %5
store double %27, double* %28
store i32 1, i32* %4
br label %31
29: ; preds = %21
br label %30
30: ; preds = %29
store i32 0, i32* %4
br label %31
31: ; preds = %30, %26, %18, %11
%32 = load i32, i32* %4
ret i32 %32
}

LLVM IR (-O2):
@str = [56 x i8] c"ERROR: in rc_saturate_double, min must be less than max\00"
define i32 @rc_saturate_double(double* nocapture %0, double %1, double %2) {
%4 = fcmp ogt double %1, %2
br i1 %4, label %5, label %7
5: ; preds = %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([56 x i8], [56 x i8]* @str, i64 0, i64 0))
br label %14
7: ; preds = %3
%8 = load double, double* %0
%9 = fcmp ogt double %8, %2
br i1 %9, label %10, label %11
10: ; preds = %7
store double %2, double* %0
br label %14
11: ; preds = %7
%12 = fcmp olt double %8, %1
br i1 %12, label %13, label %14
13: ; preds = %11
store double %1, double* %0
br label %14
14: ; preds = %11, %13, %10, %5
%15 = phi i32 [ -1, %5 ], [ 1, %10 ], [ 1, %13 ], [ 0, %11 ]
ret i32 %15
}