#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 cosh(double arg) {
  double val;
  if (arg < 0) {
    arg = -arg;
  }
  val = exp(arg);
  if (arg > 21.) {
    return (val / 2);
  }
  val += exp(-arg);
  val /= 2;
  return (val);
}


x86 assembly (clang, -O0):
<cosh>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    114c <cosh+0x3c>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm0
movsd  0xe98(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    118d <cosh+0x7d>
movsd  -0x18(%rbp),%xmm0
movsd  0xe89(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11d8 <cosh+0xc8>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <exp@plt>
addsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xe43(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cosh>:
sub    $0x28,%rsp
movapd 0xee4(%rip),%xmm1
xorpd  %xmm0,%xmm1
xorpd  %xmm2,%xmm2
movapd %xmm0,%xmm3
cmpltsd %xmm2,%xmm3
andpd  %xmm3,%xmm1
andnpd %xmm0,%xmm3
orpd   %xmm1,%xmm3
movapd %xmm3,0x10(%rsp)
movapd %xmm3,%xmm0
call   1030 <exp@plt>
movapd 0x10(%rsp),%xmm1
ucomisd 0xeba(%rip),%xmm1
ja     1185 <cosh+0x75>
movsd  %xmm0,0x8(%rsp)
movapd 0xe9a(%rip),%xmm0
xorpd  %xmm1,%xmm0
call   1030 <exp@plt>
movsd  0x8(%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,0x8(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xe8b(%rip),%xmm0
add    $0x28,%rsp
ret

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

LLVM IR (-O2):
define double @cosh(double %0) {
%2 = fcmp olt double %0, 0.000000e+00
%3 = fneg double %0
%4 = select i1 %2, double %3, double %0
%5 = tail call double @exp(double %4)
%6 = fcmp ogt double %4, 2.100000e+01
br i1 %6, label %11, label %7
7: ; preds = %1
%8 = fneg double %4
%9 = tail call double @exp(double %8)
%10 = fadd double %5, %9
br label %11
11: ; preds = %1, %7
%12 = phi double [ %10, %7 ], [ %5, %1 ]
%13 = fmul double %12, 5.000000e-01
ret double %13
}