#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 exp(double);
double soft_clamp(double x, double max) {
  if (x >= 0)
    return max * (1.0 - exp(-x / max));
  else
    return -max * (1.0 - exp(x / max));
}


x86 assembly (clang, -O0):
<soft_clamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
movsd  %xmm1,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
xorps  %xmm1,%xmm1
ucomisd %xmm1,%xmm0
jb     1186 <soft_clamp+0x76>
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm2
movsd  -0x20(%rbp),%xmm0
movsd  0xe8c(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d3 <soft_clamp+0xc3>
movsd  -0x18(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x10(%rbp),%xmm0
divsd  -0x18(%rbp),%xmm0
call   1030 <exp@plt>
movaps %xmm0,%xmm2
movsd  -0x28(%rbp),%xmm0
movsd  0xe3a(%rip),%xmm1
subsd  %xmm2,%xmm1
mulsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<soft_clamp>:
sub    $0x18,%rsp
movapd %xmm0,%xmm2
xorpd  %xmm0,%xmm0
ucomisd %xmm0,%xmm2
movapd 0xed8(%rip),%xmm4
cmpnlesd %xmm2,%xmm0
movapd %xmm0,%xmm3
andpd  %xmm2,%xmm0
xorpd  %xmm4,%xmm2
andnpd %xmm2,%xmm3
orpd   %xmm3,%xmm0
jb     114a <soft_clamp+0x3a>
movapd %xmm1,(%rsp)
jmp    1153 <soft_clamp+0x43>
xorpd  %xmm1,%xmm4
movapd %xmm4,(%rsp)
divsd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  0xeac(%rip),%xmm1
subsd  %xmm0,%xmm1
mulsd  (%rsp),%xmm1
movapd %xmm1,%xmm0
add    $0x18,%rsp
ret

LLVM IR (-O0):
define double @soft_clamp(double %0, double %1) {
%3 = alloca double
%4 = alloca double
%5 = alloca double
store double %0, double* %4
store double %1, double* %5
%6 = load double, double* %4
%7 = fcmp oge double %6, 0.000000e+00
br i1 %7, label %8, label %17
8: ; preds = %2
%9 = load double, double* %5
%10 = load double, double* %4
%11 = fneg double %10
%12 = load double, double* %5
%13 = fdiv double %11, %12
%14 = call double @exp(double %13)
%15 = fsub double 1.000000e+00, %14
%16 = fmul double %9, %15
store double %16, double* %3
br label %26
17: ; preds = %2
%18 = load double, double* %5
%19 = fneg double %18
%20 = load double, double* %4
%21 = load double, double* %5
%22 = fdiv double %20, %21
%23 = call double @exp(double %22)
%24 = fsub double 1.000000e+00, %23
%25 = fmul double %19, %24
store double %25, double* %3
br label %26
26: ; preds = %17, %8
%27 = load double, double* %3
ret double %27
}

LLVM IR (-O2):
define double @soft_clamp(double %0, double %1) {
%3 = fcmp ult double %0, 0.000000e+00
%4 = fneg double %1
%5 = fneg double %0
%6 = select i1 %3, double %0, double %5
%7 = select i1 %3, double %4, double %1
%8 = fdiv double %6, %1
%9 = tail call double @exp(double %8)
%10 = fsub double 1.000000e+00, %9
%11 = fmul double %10, %7
ret double %11
}