#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 M_PI;
double erf(int);
double exp(int);
double fabs(double);
double ferf(int);
double fexp(int);
int /*<<< orphan*/ printf(char *, double);
double sin(int);
double sine(double);
int /*<<< orphan*/ waveform_init();
int main() {
  waveform_init();
  double sine_error = 0;
  double erf_error = 0;
  double exp_error = 0;
  double e;
  for (double x = 0; x < 1; x += 1e-7) {
    e = fabs(sin(2 * M_PI * x) - sine(x));
    if (e > sine_error) {
      sine_error = e;
    }
    e = fabs(erf(10 * x - 5) - ferf(10 * x - 5));
    if (e > erf_error) {
      erf_error = e;
    }
    e = fabs(exp(-20 * x) - fexp(-20 * x));
    if (e > exp_error) {
      exp_error = e;
    }
  }
  printf("Sine error %g\n", sine_error);
  printf("Erf error %g\n", erf_error);
  printf("Exp error %g\n", exp_error);
  return 0;
  double x = 5.3;
  for (size_t i = 0; i < 1000000000; i++) {
    x = sine(x);
  }
  printf("%g\n", x);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1090 <waveform_init@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
movsd  0xe42(%rip),%xmm0
ucomisd -0x30(%rbp),%xmm0
jbe    1336 <main+0x1b6>
mov    0x2e18(%rip),%rax
mov    (%rax),%eax
shl    $0x1,%eax
cvtsi2sd %eax,%xmm0
mulsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sin@plt>
movsd  %xmm0,-0x40(%rbp)
movsd  -0x30(%rbp),%xmm0
call   1050 <sine@plt>
movaps %xmm0,%xmm1
movsd  -0x40(%rbp),%xmm0
subsd  %xmm1,%xmm0
movaps 0xe27(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x10(%rbp),%xmm0
jbe    122c <main+0xac>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x10(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xdcf(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xdcb(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1080 <erf@plt>
movsd  %xmm0,-0x48(%rbp)
movsd  -0x30(%rbp),%xmm0
movsd  0xda4(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xda0(%rip),%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   10a0 <ferf@plt>
movaps %xmm0,%xmm1
movsd  -0x48(%rbp),%xmm0
subsd  %xmm1,%xmm0
movaps 0xda0(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jbe    12b3 <main+0x133>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  0xd5d(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1060 <exp@plt>
movsd  %xmm0,-0x50(%rbp)
movsd  0xd42(%rip),%xmm0
mulsd  -0x30(%rbp),%xmm0
cvttsd2si %xmm0,%edi
call   1070 <fexp@plt>
movaps %xmm0,%xmm1
movsd  -0x50(%rbp),%xmm0
subsd  %xmm1,%xmm0
movaps 0xd39(%rip),%xmm1
pand   %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  -0x28(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    131a <main+0x19a>
movsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    131f <main+0x19f>
movsd  0xcf9(%rip),%xmm0
addsd  -0x30(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
jmp    11b6 <main+0x36>
movsd  -0x10(%rbp),%xmm0
lea    0xcfe(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x18(%rbp),%xmm0
lea    0xcfc(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x20(%rbp),%xmm0
lea    0xcf9(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x58,%rsp
xor    %eax,%eax
call   1090 <waveform_init@plt>
xorpd  %xmm1,%xmm1
mov    0x2e4f(%rip),%r14
xorpd  %xmm3,%xmm3
xorpd  %xmm0,%xmm0
movapd %xmm0,0x20(%rsp)
xorps  %xmm2,%xmm2
nopw   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
mov    (%r14),%eax
add    %eax,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  %xmm2,0x48(%rsp)
movaps 0x20(%rsp),%xmm2
movsd  %xmm2,0x10(%rsp)
movsd  %xmm3,0x50(%rsp)
mulsd  %xmm1,%xmm0
cvttsd2si %xmm0,%edi
call   1040 <sin@plt>
movapd %xmm0,0x30(%rsp)
movsd  0x8(%rsp),%xmm0
call   1050 <sine@plt>
movapd 0x30(%rsp),%xmm1
subsd  %xmm0,%xmm1
movapd 0xdf7(%rip),%xmm0
andpd  %xmm0,%xmm1
maxsd  0x48(%rsp),%xmm1
movapd %xmm1,0x30(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xde9(%rip),%xmm0
addsd  0xde9(%rip),%xmm0
cvttsd2si %xmm0,%ebx
mov    %ebx,%edi
call   1080 <erf@plt>
movapd %xmm0,0x20(%rsp)
mov    %ebx,%edi
call   10a0 <ferf@plt>
movapd 0x20(%rsp),%xmm1
subsd  %xmm0,%xmm1
andpd  0xda7(%rip),%xmm1
maxsd  0x10(%rsp),%xmm1
movapd %xmm1,0x20(%rsp)
movsd  0x8(%rsp),%xmm0
mulsd  0xdad(%rip),%xmm0
cvttsd2si %xmm0,%ebx
mov    %ebx,%edi
call   1060 <exp@plt>
movapd %xmm0,0x10(%rsp)
mov    %ebx,%edi
call   1070 <fexp@plt>
movapd 0x10(%rsp),%xmm3
movaps 0x30(%rsp),%xmm2
movsd  0x8(%rsp),%xmm1
subsd  %xmm0,%xmm3
andpd  0xd58(%rip),%xmm3
maxsd  0x50(%rsp),%xmm3
addsd  0xd72(%rip),%xmm1
movsd  0xd72(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     11b0 <main+0x30>
lea    0xd69(%rip),%rdi
movaps %xmm2,%xmm0
movapd %xmm3,0x10(%rsp)
call   1030 <printf@plt>
lea    0xd63(%rip),%rdi
movaps 0x20(%rsp),%xmm0
call   1030 <printf@plt>
lea    0xd60(%rip),%rdi
movaps 0x10(%rsp),%xmm0
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x58,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@M_PI = global i32 0
@.str = [15 x i8] c"Sine error %g\0A\00"
@.str.1 = [14 x i8] c"Erf error %g\0A\00"
@.str.2 = [14 x i8] c"Exp error %g\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca double
%7 = alloca double
store i32 0, i32* %1
%8 = call i32 (...) @waveform_init()
store double 0.000000e+00, double* %2
store double 0.000000e+00, double* %3
store double 0.000000e+00, double* %4
store double 0.000000e+00, double* %6
br label %9
9: ; preds = %62, %0
%10 = load double, double* %6
%11 = fcmp olt double %10, 1.000000e+00
br i1 %11, label %12, label %65
12: ; preds = %9
%13 = load i32, i32* @M_PI
%14 = mul nsw i32 2, %13
%15 = sitofp i32 %14 to double
%16 = load double, double* %6
%17 = fmul double %15, %16
%18 = fptosi double %17 to i32
%19 = call double @sin(i32 %18)
%20 = load double, double* %6
%21 = call double @sine(double %20)
%22 = fsub double %19, %21
%23 = call double @llvm.fabs.f64(double %22)
store double %23, double* %5
%24 = load double, double* %5
%25 = load double, double* %2
%26 = fcmp ogt double %24, %25
br i1 %26, label %27, label %29
27: ; preds = %12
%28 = load double, double* %5
store double %28, double* %2
br label %29
29: ; preds = %27, %12
%30 = load double, double* %6
%31 = call double @llvm.fmuladd.f64(double 1.000000e+01, double %30, double -5.000000e+00)
%32 = fptosi double %31 to i32
%33 = call double @erf(i32 %32)
%34 = load double, double* %6
%35 = call double @llvm.fmuladd.f64(double 1.000000e+01, double %34, double -5.000000e+00)
%36 = fptosi double %35 to i32
%37 = call double @ferf(i32 %36)
%38 = fsub double %33, %37
%39 = call double @llvm.fabs.f64(double %38)
store double %39, double* %5
%40 = load double, double* %5
%41 = load double, double* %3
%42 = fcmp ogt double %40, %41
br i1 %42, label %43, label %45
43: ; preds = %29
%44 = load double, double* %5
store double %44, double* %3
br label %45
45: ; preds = %43, %29
%46 = load double, double* %6
%47 = fmul double -2.000000e+01, %46
%48 = fptosi double %47 to i32
%49 = call double @exp(i32 %48)
%50 = load double, double* %6
%51 = fmul double -2.000000e+01, %50
%52 = fptosi double %51 to i32
%53 = call double @fexp(i32 %52)
%54 = fsub double %49, %53
%55 = call double @llvm.fabs.f64(double %54)
store double %55, double* %5
%56 = load double, double* %5
%57 = load double, double* %4
%58 = fcmp ogt double %56, %57
br i1 %58, label %59, label %61
59: ; preds = %45
%60 = load double, double* %5
store double %60, double* %4
br label %61
61: ; preds = %59, %45
br label %62
62: ; preds = %61
%63 = load double, double* %6
%64 = fadd double %63, 0x3E7AD7F29ABCAF48
store double %64, double* %6
br label %9
65: ; preds = %9
%66 = load double, double* %2
%67 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %66)
%68 = load double, double* %3
%69 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double %68)
%70 = load double, double* %4
%71 = call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %70)
ret i32 0
}

LLVM IR (-O2):
@M_PI = global i32 0
@.str = [15 x i8] c"Sine error %g\0A\00"
@.str.1 = [14 x i8] c"Erf error %g\0A\00"
@.str.2 = [14 x i8] c"Exp error %g\0A\00"
define i32 @main() {
%1 = tail call i32 (...) @waveform_init()
br label %6
2: ; preds = %6
%3 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i64 0, i64 0), double %21)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), double %29)
%5 = tail call i32 @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), double %37)
ret i32 0
6: ; preds = %0, %6
%7 = phi double [ 0.000000e+00, %0 ], [ %38, %6 ]
%8 = phi double [ 0.000000e+00, %0 ], [ %37, %6 ]
%9 = phi double [ 0.000000e+00, %0 ], [ %29, %6 ]
%10 = phi double [ 0.000000e+00, %0 ], [ %21, %6 ]
%11 = load i32, i32* @M_PI
%12 = shl nsw i32 %11, 1
%13 = sitofp i32 %12 to double
%14 = fmul double %7, %13
%15 = fptosi double %14 to i32
%16 = tail call double @sin(i32 %15)
%17 = tail call double @sine(double %7)
%18 = fsub double %16, %17
%19 = tail call double @llvm.fabs.f64(double %18)
%20 = fcmp ogt double %19, %10
%21 = select i1 %20, double %19, double %10
%22 = tail call double @llvm.fmuladd.f64(double %7, double 1.000000e+01, double -5.000000e+00)
%23 = fptosi double %22 to i32
%24 = tail call double @erf(i32 %23)
%25 = tail call double @ferf(i32 %23)
%26 = fsub double %24, %25
%27 = tail call double @llvm.fabs.f64(double %26)
%28 = fcmp ogt double %27, %9
%29 = select i1 %28, double %27, double %9
%30 = fmul double %7, -2.000000e+01
%31 = fptosi double %30 to i32
%32 = tail call double @exp(i32 %31)
%33 = tail call double @fexp(i32 %31)
%34 = fsub double %32, %33
%35 = tail call double @llvm.fabs.f64(double %34)
%36 = fcmp ogt double %35, %8
%37 = select i1 %36, double %35, double %8
%38 = fadd double %7, 0x3E7AD7F29ABCAF48
%39 = fcmp olt double %38, 1.000000e+00
br i1 %39, label %6, label %2
}