#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 M_E;
double M_LN10;
double M_LN2;
int /*<<< orphan*/ dotest(char *, double, double, double);
double log(double);
int /*<<< orphan*/ printf(char *);
testexplog() {
  extern double exp(), log();
  double x;
  printf("testing exp and log ...\n");
  dotest("exp(%.2f)", -1.0, exp(-1.0), 0.36787944117144232159552377016146087);
  dotest("exp(%.2f)", -0.25, exp(-0.25), 0.77880078307140486824517026697832065);
  dotest("exp(%.2f)", 0.0, exp(0.0), 1.0);
  dotest("exp(%.2f)", 0.25, exp(0.25), 1.28402541668774148407342056806243646);
  dotest("exp(%.2f)", 1.0, exp(1.0), M_E);
  dotest("log(%.2f)", 1.0, log(1.0), 0.0);
  dotest("log(%.2f)", 2.0, log(2.0), M_LN2);
  dotest("log(%.2f)", 4.0, log(4.0), 1.38629436111989061883446424291635313);
  dotest("log(%.2f)", 10.0, log(10.0), M_LN10);
  dotest("log(e)", M_E, log(M_E), 1.0);
  for (x = -30.0; x <= 30.0; x += 0.5) {
    dotest("log(exp(%.2f))", x, log(exp(x)), x);
  }
}


x86 assembly (clang, -O0):
<testexplog>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xf21(%rip),%rdi
call   1040 <printf@plt>
movsd  0xef4(%rip),%xmm0
call   1050 <exp@plt>
movaps %xmm0,%xmm1
lea    0xf1e(%rip),%rdi
movsd  0xedd(%rip),%xmm0
movsd  0xedd(%rip),%xmm2
call   1030 <dotest@plt>
movsd  0xeb8(%rip),%xmm0
call   1050 <exp@plt>
movaps %xmm0,%xmm1
lea    0xef2(%rip),%rdi
movsd  0xea1(%rip),%xmm0
movsd  0xea1(%rip),%xmm2
call   1030 <dotest@plt>
xorps  %xmm0,%xmm0
call   1050 <exp@plt>
movaps %xmm0,%xmm1
lea    0xecb(%rip),%rdi
xorps  %xmm0,%xmm0
movsd  0xe3f(%rip),%xmm2
call   1030 <dotest@plt>
movsd  0xe5a(%rip),%xmm0
call   1050 <exp@plt>
movaps %xmm0,%xmm1
lea    0xea4(%rip),%rdi
movsd  0xe43(%rip),%xmm0
movsd  0xe43(%rip),%xmm2
call   1030 <dotest@plt>
movsd  0xe06(%rip),%xmm0
call   1050 <exp@plt>
movaps %xmm0,%xmm1
mov    0x2dbf(%rip),%rax
movsd  (%rax),%xmm2
lea    0xe6d(%rip),%rdi
movsd  0xde4(%rip),%xmm0
call   1030 <dotest@plt>
movsd  0xdd7(%rip),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
lea    0xe53(%rip),%rdi
movsd  0xdc0(%rip),%xmm0
xorps  %xmm2,%xmm2
call   1030 <dotest@plt>
movsd  0xdd0(%rip),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
mov    0x2d71(%rip),%rax
movsd  (%rax),%xmm2
lea    0xe21(%rip),%rdi
movsd  0xdae(%rip),%xmm0
call   1030 <dotest@plt>
movsd  0xd91(%rip),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
lea    0xdfd(%rip),%rdi
movsd  0xd7a(%rip),%xmm0
movsd  0xd7a(%rip),%xmm2
call   1030 <dotest@plt>
movsd  0xd5d(%rip),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
mov    0x2d1e(%rip),%rax
movsd  (%rax),%xmm2
lea    0xdc6(%rip),%rdi
movsd  0xd3b(%rip),%xmm0
call   1030 <dotest@plt>
mov    0x2cef(%rip),%rax
movsd  (%rax),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    0x2cdf(%rip),%rax
movsd  (%rax),%xmm0
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x18(%rbp),%xmm0
lea    0xd94(%rip),%rdi
movsd  0xcf7(%rip),%xmm2
call   1030 <dotest@plt>
movsd  0xce2(%rip),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  0xd35(%rip),%xmm0
ucomisd -0x10(%rbp),%xmm0
jb     137f <testexplog+0x23f>
movsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1050 <exp@plt>
call   1060 <log@plt>
movaps %xmm0,%xmm1
movsd  -0x20(%rbp),%xmm0
movsd  -0x10(%rbp),%xmm2
lea    0xd41(%rip),%rdi
call   1030 <dotest@plt>
movsd  0xcf8(%rip),%xmm0
addsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
jmp    1323 <testexplog+0x1e3>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<testexplog>:
push   %r14
push   %rbx
push   %rax
lea    0xf67(%rip),%rdi
call   1030 <puts@plt>
lea    0xf31(%rip),%rbx
movsd  0xea1(%rip),%xmm0
movsd  0xea1(%rip),%xmm1
mov    %rbx,%rdi
movaps %xmm1,%xmm2
call   1040 <dotest@plt>
movsd  0xe96(%rip),%xmm0
movsd  0xe96(%rip),%xmm1
mov    %rbx,%rdi
movaps %xmm1,%xmm2
call   1040 <dotest@plt>
movsd  0xe8b(%rip),%xmm1
xorps  %xmm0,%xmm0
mov    %rbx,%rdi
movaps %xmm1,%xmm2
call   1040 <dotest@plt>
movsd  0xe7d(%rip),%xmm0
movsd  0xe7d(%rip),%xmm1
mov    %rbx,%rdi
movaps %xmm1,%xmm2
call   1040 <dotest@plt>
mov    0x2e0b(%rip),%r14
movsd  (%r14),%xmm2
movsd  0xe66(%rip),%xmm1
mov    %rbx,%rdi
movsd  0xe43(%rip),%xmm0
call   1040 <dotest@plt>
lea    0xea9(%rip),%rbx
xorps  %xmm1,%xmm1
xorps  %xmm2,%xmm2
mov    %rbx,%rdi
movsd  0xe26(%rip),%xmm0
call   1040 <dotest@plt>
mov    0x2dd2(%rip),%rax
movsd  (%rax),%xmm2
movsd  0xe2e(%rip),%xmm0
movsd  0xe2e(%rip),%xmm1
mov    %rbx,%rdi
call   1040 <dotest@plt>
movsd  0xe26(%rip),%xmm0
movsd  0xe26(%rip),%xmm1
mov    %rbx,%rdi
movaps %xmm1,%xmm2
call   1040 <dotest@plt>
mov    0x2d9c(%rip),%rax
movsd  (%rax),%xmm2
movsd  0xe10(%rip),%xmm0
movsd  0xe10(%rip),%xmm1
mov    %rbx,%rdi
call   1040 <dotest@plt>
movsd  (%r14),%xmm0
movsd  %xmm0,(%rsp)
call   1060 <log@plt>
movapd %xmm0,%xmm1
lea    0xe22(%rip),%rdi
movsd  (%rsp),%xmm0
movsd  0xd99(%rip),%xmm2
call   1040 <dotest@plt>
movsd  0xddc(%rip),%xmm0
lea    0xe08(%rip),%rbx
nopl   0x0(%rax,%rax,1)
movsd  %xmm0,(%rsp)
movsd  (%rsp),%xmm0
call   1050 <exp@plt>
call   1060 <log@plt>
movaps %xmm0,%xmm1
mov    %rbx,%rdi
movsd  (%rsp),%xmm0
movsd  (%rsp),%xmm2
call   1040 <dotest@plt>
movsd  (%rsp),%xmm0
addsd  0xda2(%rip),%xmm0
movsd  0xda2(%rip),%xmm1
ucomisd %xmm0,%xmm1
jae    12a0 <testexplog+0x160>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [25 x i8] c"testing exp and log ...\0A\00"
@.str.1 = [10 x i8] c"exp(%.2f)\00"
@M_E = global double 0.000000e+00
@.str.2 = [10 x i8] c"log(%.2f)\00"
@M_LN2 = global double 0.000000e+00
@M_LN10 = global double 0.000000e+00
@.str.3 = [7 x i8] c"log(e)\00"
@.str.4 = [15 x i8] c"log(exp(%.2f))\00"
define i32 @testexplog() {
%1 = alloca i32
%2 = alloca double
%3 = call i32 @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
%4 = call double @exp(double -1.000000e+00)
%5 = call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double -1.000000e+00, double %4, double 0x3FD78B56362CEF38)
%6 = call double @exp(double -2.500000e-01)
%7 = call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double -2.500000e-01, double %6, double 0x3FE8EBEF9EAC820B)
%8 = call double @exp(double 0.000000e+00)
%9 = call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double 0.000000e+00, double %8, double 1.000000e+00)
%10 = call double @exp(double 2.500000e-01)
%11 = call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double 2.500000e-01, double %10, double 0x3FF48B5E3C3E8186)
%12 = call double @exp(double 1.000000e+00)
%13 = load double, double* @M_E
%14 = call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double 1.000000e+00, double %12, double %13)
%15 = call double @log(double 1.000000e+00)
%16 = call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double 1.000000e+00, double %15, double 0.000000e+00)
%17 = call double @log(double 2.000000e+00)
%18 = load double, double* @M_LN2
%19 = call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double 2.000000e+00, double %17, double %18)
%20 = call double @log(double 4.000000e+00)
%21 = call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double 4.000000e+00, double %20, double 0x3FF62E42FEFA39EF)
%22 = call double @log(double 1.000000e+01)
%23 = load double, double* @M_LN10
%24 = call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double 1.000000e+01, double %22, double %23)
%25 = load double, double* @M_E
%26 = load double, double* @M_E
%27 = call double @log(double %26)
%28 = call i32 @dotest(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %25, double %27, double 1.000000e+00)
store double -3.000000e+01, double* %2
br label %29
29: ; preds = %39, %0
%30 = load double, double* %2
%31 = fcmp ole double %30, 3.000000e+01
br i1 %31, label %32, label %42
32: ; preds = %29
%33 = load double, double* %2
%34 = load double, double* %2
%35 = call double @exp(double %34)
%36 = call double @log(double %35)
%37 = load double, double* %2
%38 = call i32 @dotest(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), double %33, double %36, double %37)
br label %39
39: ; preds = %32
%40 = load double, double* %2
%41 = fadd double %40, 5.000000e-01
store double %41, double* %2
br label %29
42: ; preds = %29
%43 = load i32, i32* %1
ret i32 %43
}

LLVM IR (-O2):
@.str.1 = [10 x i8] c"exp(%.2f)\00"
@M_E = global double 0.000000e+00
@.str.2 = [10 x i8] c"log(%.2f)\00"
@M_LN2 = global double 0.000000e+00
@M_LN10 = global double 0.000000e+00
@.str.3 = [7 x i8] c"log(e)\00"
@.str.4 = [15 x i8] c"log(exp(%.2f))\00"
@str = [24 x i8] c"testing exp and log ...\00"
define i32 @testexplog() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @str, i64 0, i64 0))
%2 = tail call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double -1.000000e+00, double 0x3FD78B56362CEF38, double 0x3FD78B56362CEF38)
%3 = tail call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double -2.500000e-01, double 0x3FE8EBEF9EAC820B, double 0x3FE8EBEF9EAC820B)
%4 = tail call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double 0.000000e+00, double 1.000000e+00, double 1.000000e+00)
%5 = tail call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double 2.500000e-01, double 0x3FF48B5E3C3E8186, double 0x3FF48B5E3C3E8186)
%6 = load double, double* @M_E
%7 = tail call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), double 1.000000e+00, double 0x4005BF0A8B145769, double %6)
%8 = tail call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double 1.000000e+00, double 0.000000e+00, double 0.000000e+00)
%9 = load double, double* @M_LN2
%10 = tail call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double 2.000000e+00, double 0x3FE62E42FEFA39EF, double %9)
%11 = tail call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double 4.000000e+00, double 0x3FF62E42FEFA39EF, double 0x3FF62E42FEFA39EF)
%12 = load double, double* @M_LN10
%13 = tail call i32 @dotest(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), double 1.000000e+01, double 0x40026BB1BBB55516, double %12)
%14 = load double, double* @M_E
%15 = tail call double @log(double %14)
%16 = tail call i32 @dotest(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.3, i64 0, i64 0), double %14, double %15, double 1.000000e+00)
br label %17
17: ; preds = %0, %17
%18 = phi double [ -3.000000e+01, %0 ], [ %22, %17 ]
%19 = tail call double @exp(double %18)
%20 = tail call double @log(double %19)
%21 = tail call i32 @dotest(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.4, i64 0, i64 0), double %18, double %20, double %18)
%22 = fadd double %18, 5.000000e-01
%23 = fcmp ugt double %22, 3.000000e+01
br i1 %23, label %24, label %17
24: ; preds = %17
ret i32 undef
}