#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_sub(double);
double __frem_for_exp(double, int *);
double exp(double x) {
  if (x < 0) {
    return 1.0 / exp(-x);
  } else if (x < 0.693147180) {
    return __exp_sub(x);
  } else {
    int d, m;
    double z;
    z = __frem_for_exp(x, &m);
    d = 1;
    while (m-- > 0)
      d *= 2;
    return d * __exp_sub(z);
  }
}


x86 assembly (clang, -O0):
<exp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    1185 <exp+0x55>
movsd  -0x10(%rbp),%xmm0
movq   %xmm0,%rax
movabs $0x8000000000000000,%rcx
xor    %rcx,%rax
movq   %rax,%xmm0
call   1040 <exp@plt>
movaps %xmm0,%xmm1
movsd  0xe91(%rip),%xmm0
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120d <exp+0xdd>
movsd  0xe73(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    11b0 <exp+0x80>
movsd  -0x10(%rbp),%xmm0
call   1030 <__exp_sub@plt>
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
jmp    120d <exp+0xdd>
movsd  -0x10(%rbp),%xmm0
lea    -0x18(%rbp),%rdi
call   1050 <__frem_for_exp@plt>
movsd  %xmm0,-0x20(%rbp)
movl   $0x1,-0x14(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x18(%rbp)
cmp    $0x0,%eax
jle    11ec <exp+0xbc>
mov    -0x14(%rbp),%eax
shl    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11ca <exp+0x9a>
mov    -0x14(%rbp),%eax
mov    %eax,-0x24(%rbp)
movsd  -0x20(%rbp),%xmm0
call   1030 <__exp_sub@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
imul   %ecx,%eax
cvtsi2sd %eax,%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<exp>:
push   %rbx
sub    $0x10,%rsp
xorpd  %xmm1,%xmm1
ucomisd %xmm0,%xmm1
jbe    115e <exp+0x2e>
xorpd  0xec9(%rip),%xmm0
call   1040 <exp@plt>
movapd %xmm0,%xmm1
movsd  0xeb0(%rip),%xmm0
divsd  %xmm1,%xmm0
jmp    11b2 <exp+0x82>
movsd  0xe9a(%rip),%xmm1
ucomisd %xmm0,%xmm1
jbe    1173 <exp+0x43>
call   1030 <__exp_sub@plt>
jmp    11ab <exp+0x7b>
lea    0xc(%rsp),%rdi
call   1050 <__frem_for_exp@plt>
mov    0xc(%rsp),%ecx
xor    %eax,%eax
test   %ecx,%ecx
cmovs  %ecx,%eax
add    $0x1,%ecx
mov    $0x1,%edx
mov    %edx,%ebx
lea    (%rbx,%rbx,1),%edx
add    $0xffffffff,%ecx
test   %ecx,%ecx
jg     1190 <exp+0x60>
add    $0xffffffff,%eax
mov    %eax,0xc(%rsp)
call   1030 <__exp_sub@plt>
imul   %ebx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define double @exp(double %0) {
%2 = alloca double
%3 = alloca double
%4 = alloca i32
%5 = alloca i32
%6 = alloca double
store double %0, double* %3
%7 = load double, double* %3
%8 = fcmp olt double %7, 0.000000e+00
br i1 %8, label %9, label %14
9: ; preds = %1
%10 = load double, double* %3
%11 = fneg double %10
%12 = call double @exp(double %11)
%13 = fdiv double 1.000000e+00, %12
store double %13, double* %2
br label %37
14: ; preds = %1
%15 = load double, double* %3
%16 = fcmp olt double %15, 0x3FE62E42FEAD449C
br i1 %16, label %17, label %21
17: ; preds = %14
%18 = load double, double* %3
%19 = call i32 @__exp_sub(double %18)
%20 = sitofp i32 %19 to double
store double %20, double* %2
br label %37
21: ; preds = %14
%22 = load double, double* %3
%23 = call double @__frem_for_exp(double %22, i32* %5)
store double %23, double* %6
store i32 1, i32* %4
br label %24
24: ; preds = %28, %21
%25 = load i32, i32* %5
%26 = add nsw i32 %25, -1
store i32 %26, i32* %5
%27 = icmp sgt i32 %25, 0
br i1 %27, label %28, label %31
28: ; preds = %24
%29 = load i32, i32* %4
%30 = mul nsw i32 %29, 2
store i32 %30, i32* %4
br label %24
31: ; preds = %24
%32 = load i32, i32* %4
%33 = load double, double* %6
%34 = call i32 @__exp_sub(double %33)
%35 = mul nsw i32 %32, %34
%36 = sitofp i32 %35 to double
store double %36, double* %2
br label %37
37: ; preds = %31, %17, %9
%38 = load double, double* %2
ret double %38
}

LLVM IR (-O2):
define double @exp(double %0) {
%2 = alloca i32
%3 = fcmp olt double %0, 0.000000e+00
br i1 %3, label %6, label %10
4: ; preds = %12, %26, %6
%5 = phi double [ %9, %6 ], [ %14, %12 ], [ %30, %26 ]
ret double %5
6: ; preds = %1
%7 = fneg double %0
%8 = tail call double @exp(double %7)
%9 = fdiv double 1.000000e+00, %8
br label %4
10: ; preds = %1
%11 = fcmp olt double %0, 0x3FE62E42FEAD449C
br i1 %11, label %12, label %15
12: ; preds = %10
%13 = tail call i32 @__exp_sub(double %0)
%14 = sitofp i32 %13 to double
br label %4
15: ; preds = %10
%16 = bitcast i32* %2 to i8*
%17 = call double @__frem_for_exp(double %0, i32* %2)
%18 = load i32, i32* %2
%19 = call i32 @llvm.smin.i32(i32 %18, i32 0)
br label %20
20: ; preds = %20, %15
%21 = phi i32 [ %23, %20 ], [ %18, %15 ]
%22 = phi i32 [ %25, %20 ], [ 1, %15 ]
%23 = add nsw i32 %21, -1
%24 = icmp sgt i32 %21, 0
%25 = shl nsw i32 %22, 1
br i1 %24, label %20, label %26
26: ; preds = %20
%27 = add i32 %19, -1
store i32 %27, i32* %2
%28 = call i32 @__exp_sub(double %17)
%29 = mul nsw i32 %28, %22
%30 = sitofp i32 %29 to double
br label %4
}