#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 pow(double, double);
double linexp(double x, double a, double b, double c, double d) {
  if (x <= a)
    return c;
  if (x >= b)
    return d;
  return pow(d / c, (x - a) / (b - a)) * c;
}


x86 assembly (clang, -O0):
<linexp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  %xmm2,-0x20(%rbp)
movsd  %xmm3,-0x28(%rbp)
movsd  %xmm4,-0x30(%rbp)
movsd  -0x10(%rbp),%xmm1
movsd  -0x18(%rbp),%xmm0
ucomisd %xmm1,%xmm0
jb     1154 <linexp+0x44>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a4 <linexp+0x94>
movsd  -0x10(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jb     1173 <linexp+0x63>
movsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11a4 <linexp+0x94>
movsd  -0x30(%rbp),%xmm0
divsd  -0x28(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm1
subsd  -0x18(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
subsd  -0x18(%rbp),%xmm2
divsd  %xmm2,%xmm1
call   1030 <pow@plt>
mulsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<linexp>:
movapd %xmm3,%xmm5
ucomisd %xmm0,%xmm1
jae    1154 <linexp+0x44>
movapd %xmm0,%xmm3
ucomisd %xmm2,%xmm0
jae    1159 <linexp+0x49>
push   %rax
divsd  %xmm5,%xmm4
subsd  %xmm1,%xmm3
subsd  %xmm1,%xmm2
divsd  %xmm2,%xmm3
movapd %xmm4,%xmm0
movapd %xmm3,%xmm1
movsd  %xmm5,(%rsp)
call   1030 <pow@plt>
movsd  (%rsp),%xmm5
mulsd  %xmm0,%xmm5
add    $0x8,%rsp
movapd %xmm5,%xmm0
ret
movaps %xmm4,%xmm0
ret

LLVM IR (-O0):
define double @linexp(double %0, double %1, double %2, double %3, double %4) {
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca double
%11 = alloca double
store double %0, double* %7
store double %1, double* %8
store double %2, double* %9
store double %3, double* %10
store double %4, double* %11
%12 = load double, double* %7
%13 = load double, double* %8
%14 = fcmp ole double %12, %13
br i1 %14, label %15, label %17
15: ; preds = %5
%16 = load double, double* %10
store double %16, double* %6
br label %37
17: ; preds = %5
%18 = load double, double* %7
%19 = load double, double* %9
%20 = fcmp oge double %18, %19
br i1 %20, label %21, label %23
21: ; preds = %17
%22 = load double, double* %11
store double %22, double* %6
br label %37
23: ; preds = %17
%24 = load double, double* %11
%25 = load double, double* %10
%26 = fdiv double %24, %25
%27 = load double, double* %7
%28 = load double, double* %8
%29 = fsub double %27, %28
%30 = load double, double* %9
%31 = load double, double* %8
%32 = fsub double %30, %31
%33 = fdiv double %29, %32
%34 = call double @pow(double %26, double %33)
%35 = load double, double* %10
%36 = fmul double %34, %35
store double %36, double* %6
br label %37
37: ; preds = %23, %21, %15
%38 = load double, double* %6
ret double %38
}

LLVM IR (-O2):
define double @linexp(double %0, double %1, double %2, double %3, double %4) {
%6 = fcmp ugt double %0, %1
br i1 %6, label %7, label %16
7: ; preds = %5
%8 = fcmp ult double %0, %2
br i1 %8, label %9, label %16
9: ; preds = %7
%10 = fdiv double %4, %3
%11 = fsub double %0, %1
%12 = fsub double %2, %1
%13 = fdiv double %11, %12
%14 = tail call double @pow(double %10, double %13)
%15 = fmul double %14, %3
br label %16
16: ; preds = %7, %5, %9
%17 = phi double [ %15, %9 ], [ %3, %5 ], [ %4, %7 ]
ret double %17
}