#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 */
double fmax(double, double);
double fmin(double, double);
double ramping_update(double previous, double target,
                      double max_change_per_update) {
  if (previous < target) {
    return fmin(target, previous + max_change_per_update);
  } else {
    return fmax(target, previous - max_change_per_update);
  }
}


x86 assembly (clang, -O0):
<ramping_update>:
push   %rbp
mov    %rsp,%rbp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jbe    115e <ramping_update+0x5e>
movsd  -0x18(%rbp),%xmm3
movsd  -0x10(%rbp),%xmm2
addsd  -0x20(%rbp),%xmm2
movaps %xmm2,%xmm4
movaps %xmm3,%xmm0
cmpunordsd %xmm0,%xmm0
movaps %xmm0,%xmm1
pand   %xmm4,%xmm1
minsd  %xmm3,%xmm2
pandn  %xmm2,%xmm0
por    %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1190 <ramping_update+0x90>
movsd  -0x18(%rbp),%xmm3
movsd  -0x10(%rbp),%xmm2
subsd  -0x20(%rbp),%xmm2
movaps %xmm2,%xmm4
movaps %xmm3,%xmm0
cmpunordsd %xmm0,%xmm0
movaps %xmm0,%xmm1
pand   %xmm4,%xmm1
maxsd  %xmm3,%xmm2
pandn  %xmm2,%xmm0
por    %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
pop    %rbp
ret

x86 assembly (clang, -O2):
<ramping_update>:
ucomisd %xmm0,%xmm1
jbe    1121 <ramping_update+0x21>
addsd  %xmm2,%xmm0
movapd %xmm1,%xmm2
cmpunordsd %xmm1,%xmm2
movapd %xmm2,%xmm3
andpd  %xmm0,%xmm3
minsd  %xmm1,%xmm0
jmp    113a <ramping_update+0x3a>
subsd  %xmm2,%xmm0
movapd %xmm1,%xmm2
cmpunordsd %xmm1,%xmm2
movapd %xmm2,%xmm3
andpd  %xmm0,%xmm3
maxsd  %xmm1,%xmm0
andnpd %xmm0,%xmm2
orpd   %xmm3,%xmm2
movapd %xmm2,%xmm0
ret

LLVM IR (-O0):
define double @ramping_update(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 = load double, double* %6
%10 = fcmp olt double %8, %9
br i1 %10, label %11, label %17
11: ; preds = %3
%12 = load double, double* %6
%13 = load double, double* %5
%14 = load double, double* %7
%15 = fadd double %13, %14
%16 = call double @llvm.minnum.f64(double %12, double %15)
store double %16, double* %4
br label %23
17: ; preds = %3
%18 = load double, double* %6
%19 = load double, double* %5
%20 = load double, double* %7
%21 = fsub double %19, %20
%22 = call double @llvm.maxnum.f64(double %18, double %21)
store double %22, double* %4
br label %23
23: ; preds = %17, %11
%24 = load double, double* %4
ret double %24
}

LLVM IR (-O2):
define double @ramping_update(double %0, double %1, double %2) {
%4 = fcmp olt double %0, %1
br i1 %4, label %5, label %8
5: ; preds = %3
%6 = fadd double %0, %2
%7 = tail call double @llvm.minnum.f64(double %1, double %6)
br label %11
8: ; preds = %3
%9 = fsub double %0, %2
%10 = tail call double @llvm.maxnum.f64(double %1, double %9)
br label %11
11: ; preds = %8, %5
%12 = phi double [ %7, %5 ], [ %10, %8 ]
ret double %12
}