#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*/ FE_UPWARD;
int /*<<< orphan*/ exp(double);
double fabs(double);
int fegetround();
int /*<<< orphan*/ fesetround(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, double, ...);
int main(void) {
  double ans = 1., tmp = 1;
  double eps = 1;
  double x = -19.5;
  long count = 0;
  printf("rounding mode = %d\n", fegetround());
  fesetround(FE_UPWARD);
  printf("rounding mode = %d\n", fegetround());
  while (eps > 1e-15) {
    count++;
    tmp *= x / (count);
    eps = fabs(tmp);
    ans += tmp;
  }
  printf("math.h exp(%.6lf) = %.9le\n", x, exp(x));
  printf("ans = %.16le\n", ans);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
movsd  0xeb1(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xea4(%rip),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xe97(%rip),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  0xe82(%rip),%xmm0
movsd  %xmm0,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    $0x0,%al
call   1050 <fegetround@plt>
cvtsi2sd %eax,%xmm0
lea    0xe93(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1030 <fesetround@plt>
mov    $0x0,%al
call   1050 <fegetround@plt>
cvtsi2sd %eax,%xmm0
lea    0xe6c(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x20(%rbp),%xmm0
movsd  0xe38(%rip),%xmm1
ucomisd %xmm1,%xmm0
jbe    1230 <main+0xf0>
mov    -0x30(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x30(%rbp)
movsd  -0x28(%rbp),%xmm0
cvtsi2sdq -0x30(%rbp),%xmm1
divsd  %xmm1,%xmm0
mulsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
movaps 0xe0d(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    11cb <main+0x8b>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
call   1060 <exp@plt>
movsd  -0x38(%rbp),%xmm0
mov    %eax,%esi
lea    0xdf2(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x10(%rbp),%xmm0
lea    0xdfa(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1050 <fegetround@plt>
cvtsi2sd %eax,%xmm0
lea    0xed9(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    0x2e78(%rip),%rax
mov    (%rax),%edi
call   1030 <fesetround@plt>
xor    %eax,%eax
call   1050 <fegetround@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
mov    %rbx,%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0xe71(%rip),%xmm6
mov    $0x1,%eax
movsd  0xe6c(%rip),%xmm0
movapd 0xe7c(%rip),%xmm1
movsd  0xe64(%rip),%xmm2
movapd %xmm6,%xmm3
xorps  %xmm4,%xmm4
cvtsi2sd %rax,%xmm4
movapd %xmm0,%xmm5
divsd  %xmm4,%xmm5
mulsd  %xmm5,%xmm3
movapd %xmm3,%xmm4
andpd  %xmm1,%xmm4
addsd  %xmm3,%xmm6
add    $0x1,%rax
ucomisd %xmm2,%xmm4
ja     11b0 <main+0x70>
movsd  0xe26(%rip),%xmm0
movsd  %xmm6,0x8(%rsp)
call   1060 <exp@plt>
lea    0xe50(%rip),%rdi
movsd  0xe0c(%rip),%xmm0
mov    %eax,%esi
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xe53(%rip),%rdi
movsd  0x8(%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [20 x i8] c"rounding mode = %d\0A\00"
@FE_UPWARD = global i32 0
@.str.1 = [27 x i8] c"math.h exp(%.6lf) = %.9le\0A\00"
@.str.2 = [14 x i8] c"ans = %.16le\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i64
store i32 0, i32* %1
store double 1.000000e+00, double* %2
store double 1.000000e+00, double* %3
store double 1.000000e+00, double* %4
store double -1.950000e+01, double* %5
store i64 0, i64* %6
%7 = call i32 (...) @fegetround()
%8 = sitofp i32 %7 to double
%9 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), double %8)
%10 = load i32, i32* @FE_UPWARD
%11 = call i32 @fesetround(i32 %10)
%12 = call i32 (...) @fegetround()
%13 = sitofp i32 %12 to double
%14 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), double %13)
br label %15
15: ; preds = %18, %0
%16 = load double, double* %4
%17 = fcmp ogt double %16, 1.000000e-15
br i1 %17, label %18, label %32
18: ; preds = %15
%19 = load i64, i64* %6
%20 = add nsw i64 %19, 1
store i64 %20, i64* %6
%21 = load double, double* %5
%22 = load i64, i64* %6
%23 = sitofp i64 %22 to double
%24 = fdiv double %21, %23
%25 = load double, double* %3
%26 = fmul double %25, %24
store double %26, double* %3
%27 = load double, double* %3
%28 = call double @llvm.fabs.f64(double %27)
store double %28, double* %4
%29 = load double, double* %3
%30 = load double, double* %2
%31 = fadd double %30, %29
store double %31, double* %2
br label %15
32: ; preds = %15
%33 = load double, double* %5
%34 = load double, double* %5
%35 = call i32 @exp(double %34)
%36 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), double %33, i32 %35)
%37 = load double, double* %2
%38 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %37)
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"rounding mode = %d\0A\00"
@FE_UPWARD = global i32 0
@.str.1 = [27 x i8] c"math.h exp(%.6lf) = %.9le\0A\00"
@.str.2 = [14 x i8] c"ans = %.16le\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @fegetround()
%2 = sitofp i32 %1 to double
%3 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), double %2)
%4 = load i32, i32* @FE_UPWARD
%5 = tail call i32 @fesetround(i32 %4)
%6 = tail call i32 (...) @fegetround()
%7 = sitofp i32 %6 to double
%8 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), double %7)
br label %9
9: ; preds = %0, %9
%10 = phi i64 [ 0, %0 ], [ %13, %9 ]
%11 = phi double [ 1.000000e+00, %0 ], [ %18, %9 ]
%12 = phi double [ 1.000000e+00, %0 ], [ %16, %9 ]
%13 = add nuw nsw i64 %10, 1
%14 = sitofp i64 %13 to double
%15 = fdiv double -1.950000e+01, %14
%16 = fmul double %12, %15
%17 = tail call double @llvm.fabs.f64(double %16)
%18 = fadd double %11, %16
%19 = fcmp ogt double %17, 1.000000e-15
br i1 %19, label %9, label %20
20: ; preds = %9
%21 = tail call i32 @exp(double -1.950000e+01)
%22 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0), double -1.950000e+01, i32 %21)
%23 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %18)
ret i32 0
}