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


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
movsd  0xea7(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1183 <cosh+0x73>
movsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    11c9 <cosh+0xb9>
movsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
mov    %eax,-0x14(%rbp)
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1030 <exp@plt>
mov    %eax,%ecx
mov    -0x14(%rbp),%eax
add    %ecx,%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<cosh>:
push   %rbx
sub    $0x10,%rsp
movapd 0xee3(%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,(%rsp)
movapd %xmm3,%xmm0
call   1030 <exp@plt>
movapd (%rsp),%xmm1
mov    %eax,%ebx
ucomisd 0xeb9(%rip),%xmm1
ja     116c <cosh+0x5c>
movapd 0xe9f(%rip),%xmm0
xorpd  %xmm1,%xmm0
call   1030 <exp@plt>
add    %eax,%ebx
mov    %ebx,%eax
shr    $0x1f,%eax
add    %ebx,%eax
sar    %eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

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

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 = fcmp ogt double %4, 2.100000e+01
%6 = tail call i32 @exp(double %4)
br i1 %5, label %11, label %7
7: ; preds = %1
%8 = fneg double %4
%9 = tail call i32 @exp(double %8)
%10 = add nsw i32 %9, %6
br label %11
11: ; preds = %1, %7
%12 = phi i32 [ %10, %7 ], [ %6, %1 ]
%13 = sdiv i32 %12, 2
%14 = sitofp i32 %13 to double
ret double %14
}