#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 /*<<< orphan*/ ERANGE;
double HUGE_VAL;
int /*<<< orphan*/ errno;
int exp(double);
double cosh(double arg) {
  if (arg < 0)
    arg = -arg;
  if (arg > 21) {
    if (arg >= HUGE_VAL) {
      errno = ERANGE;
      return HUGE_VAL;
    } else
      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    11c0 <cosh+0xb0>
movsd  -0x10(%rbp),%xmm0
mov    0x2e79(%rip),%rax
ucomisd (%rax),%xmm0
jb     11a0 <cosh+0x90>
mov    0x2e60(%rip),%rax
mov    (%rax),%ecx
mov    0x2e47(%rip),%rax
mov    %ecx,(%rax)
mov    0x2e56(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1206 <cosh+0xf6>
movsd  -0x10(%rbp),%xmm0
call   1030 <exp@plt>
mov    $0x2,%ecx
cltd
idiv   %ecx
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    1206 <cosh+0xf6>
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
ucomisd 0xece(%rip),%xmm3
jbe    1160 <cosh+0x50>
mov    0x2e9d(%rip),%rax
movsd  (%rax),%xmm0
ucomisd %xmm0,%xmm3
jae    1196 <cosh+0x86>
movapd %xmm3,%xmm0
call   1030 <exp@plt>
jmp    1184 <cosh+0x74>
movapd %xmm3,%xmm0
movapd %xmm3,(%rsp)
call   1030 <exp@plt>
mov    %eax,%ebx
movapd 0xe88(%rip),%xmm0
xorpd  (%rsp),%xmm0
call   1030 <exp@plt>
add    %ebx,%eax
mov    %eax,%ecx
shr    $0x1f,%ecx
add    %eax,%ecx
sar    %ecx
xorps  %xmm0,%xmm0
cvtsi2sd %ecx,%xmm0
jmp    11a8 <cosh+0x98>
mov    0x2e43(%rip),%rax
mov    (%rax),%eax
mov    0x2e2a(%rip),%rcx
mov    %eax,(%rcx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@HUGE_VAL = global double 0.000000e+00
@ERANGE = global i32 0
@errno = global i32 0
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 %24
12: ; preds = %9
%13 = load double, double* %3
%14 = load double, double* @HUGE_VAL
%15 = fcmp oge double %13, %14
br i1 %15, label %16, label %19
16: ; preds = %12
%17 = load i32, i32* @ERANGE
store i32 %17, i32* @errno
%18 = load double, double* @HUGE_VAL
store double %18, double* %2
br label %33
19: ; preds = %12
%20 = load double, double* %3
%21 = call i32 @exp(double %20)
%22 = sdiv i32 %21, 2
%23 = sitofp i32 %22 to double
store double %23, double* %2
br label %33
24: ; preds = %9
%25 = load double, double* %3
%26 = call i32 @exp(double %25)
%27 = load double, double* %3
%28 = fneg double %27
%29 = call i32 @exp(double %28)
%30 = add nsw i32 %26, %29
%31 = sdiv i32 %30, 2
%32 = sitofp i32 %31 to double
store double %32, double* %2
br label %33
33: ; preds = %24, %19, %16
%34 = load double, double* %2
ret double %34
}

LLVM IR (-O2):
@HUGE_VAL = global double 0.000000e+00
@ERANGE = global i32 0
@errno = global i32 0
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
br i1 %5, label %6, label %15
6: ; preds = %1
%7 = load double, double* @HUGE_VAL
%8 = fcmp ult double %4, %7
br i1 %8, label %11, label %9
9: ; preds = %6
%10 = load i32, i32* @ERANGE
store i32 %10, i32* @errno
br label %22
11: ; preds = %6
%12 = tail call i32 @exp(double %4)
%13 = sdiv i32 %12, 2
%14 = sitofp i32 %13 to double
br label %22
15: ; preds = %1
%16 = tail call i32 @exp(double %4)
%17 = fneg double %4
%18 = tail call i32 @exp(double %17)
%19 = add nsw i32 %18, %16
%20 = sdiv i32 %19, 2
%21 = sitofp i32 %20 to double
br label %22
22: ; preds = %15, %11, %9
%23 = phi double [ %7, %9 ], [ %14, %11 ], [ %21, %15 ]
ret double %23
}