#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 *);
double chop(double x, double a, double b) {
  if (a >= b) {
    printf("Bad input forthe chop function: a >= b\n");
  }
  if (x > b) {
    return b;
  } else if (x < a) {
    return a;
  } else {
    return x;
  }
}


x86 assembly (clang, -O0):
<chop>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     1143 <chop+0x33>
lea    0xec2(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1162 <chop+0x52>
movsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    118f <chop+0x7f>
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    1185 <chop+0x75>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    118f <chop+0x7f>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<chop>:
movapd %xmm0,%xmm3
ucomisd %xmm2,%xmm1
jb     1152 <chop+0x42>
sub    $0x38,%rsp
lea    0xedb(%rip),%rdi
movapd %xmm2,0x20(%rsp)
movapd %xmm1,0x10(%rsp)
movsd  %xmm3,0x8(%rsp)
call   1030 <puts@plt>
movsd  0x8(%rsp),%xmm3
movapd 0x10(%rsp),%xmm1
movapd 0x20(%rsp),%xmm2
add    $0x38,%rsp
maxsd  %xmm3,%xmm1
movapd %xmm2,%xmm0
cmpltsd %xmm3,%xmm0
movapd %xmm0,%xmm3
andnpd %xmm1,%xmm3
andpd  %xmm2,%xmm0
orpd   %xmm3,%xmm0
ret

LLVM IR (-O0):
@.str = [40 x i8] c"Bad input forthe chop function: a >= b\0A\00"
define double @chop(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* %6
%9 = load double, double* %7
%10 = fcmp oge double %8, %9
br i1 %10, label %11, label %13
11: ; preds = %3
%12 = call i32 @printf(i8* getelementptr inbounds ([40 x i8], [40 x i8]* @.str, i64 0, i64 0))
br label %13
13: ; preds = %11, %3
%14 = load double, double* %5
%15 = load double, double* %7
%16 = fcmp ogt double %14, %15
br i1 %16, label %17, label %19
17: ; preds = %13
%18 = load double, double* %7
store double %18, double* %4
br label %27
19: ; preds = %13
%20 = load double, double* %5
%21 = load double, double* %6
%22 = fcmp olt double %20, %21
br i1 %22, label %23, label %25
23: ; preds = %19
%24 = load double, double* %6
store double %24, double* %4
br label %27
25: ; preds = %19
%26 = load double, double* %5
store double %26, double* %4
br label %27
27: ; preds = %25, %23, %17
%28 = load double, double* %4
ret double %28
}

LLVM IR (-O2):
@str = [39 x i8] c"Bad input forthe chop function: a >= b\00"
define double @chop(double %0, double %1, double %2) {
%4 = fcmp ult double %1, %2
br i1 %4, label %7, label %5
5: ; preds = %3
%6 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str, i64 0, i64 0))
br label %7
7: ; preds = %5, %3
%8 = fcmp ogt double %0, %2
%9 = fcmp olt double %0, %1
%10 = select i1 %9, double %1, double %0
%11 = select i1 %8, double %2, double %10
ret double %11
}