#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 */
typedef scalar_t__ clock_t;

/* Variables and functions */
double CLOCKS_PER_SEC;
scalar_t__ clock();
scalar_t__ fast_sin(double);
int /*<<< orphan*/ printf(char *, double, ...);
scalar_t__ sin(double);
int main(int argc, char *argv[]) {
  const float dx = 0.0000001;
  double x = 0.0;
  double s = 0.0;
  clock_t start_lib = clock();
  while (x < 3.14159265) {
    s += sin(x);
    x += dx;
  }
  double bench_lib = (double)(clock() - start_lib) / CLOCKS_PER_SEC;
  printf("%.4f\n", s);
  x = 0.0;
  s = 0.0;
  clock_t start_fast = clock();
  while (x < 3.14159265) {
    s += fast_sin(x);
    x += dx;
  }
  double bench_fast = (double)(clock() - start_fast) / CLOCKS_PER_SEC;
  printf("%.4f\n", s);
  printf("lib:\t%.2f\nfast:\t%.2f\n", bench_lib, bench_fast);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movss  0xea2(%rip),%xmm0
movss  %xmm0,-0x14(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x30(%rbp)
movsd  0xe82(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    11c1 <main+0x81>
movsd  -0x20(%rbp),%xmm0
call   1050 <sin@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xe5e(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    117e <main+0x3e>
mov    $0x0,%al
call   1030 <clock@plt>
sub    -0x30(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e10(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x38(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xe2b(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x40(%rbp)
movsd  0xdf1(%rip),%xmm0
ucomisd -0x20(%rbp),%xmm0
jbe    1252 <main+0x112>
movsd  -0x20(%rbp),%xmm0
call   1060 <fast_sin@plt>
cvtsi2sd %rax,%xmm0
addsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
movsd  0xdcd(%rip),%xmm0
addsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x20(%rbp)
jmp    120f <main+0xcf>
mov    $0x0,%al
call   1030 <clock@plt>
sub    -0x40(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2d7f(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x48(%rbp)
movsd  -0x28(%rbp),%xmm0
lea    0xd9a(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  -0x38(%rbp),%xmm0
movsd  -0x48(%rbp),%xmm1
lea    0xd88(%rip),%rdi
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
call   1050 <sin@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x8(%rsp),%xmm1
addsd  0xe5d(%rip),%xmm1
movsd  0xe5d(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     1170 <main+0x30>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
mov    0x2e26(%rip),%r12
movsd  (%r12),%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0xe3b(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r15
xorpd  %xmm1,%xmm1
xorpd  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
nopl   0x0(%rax,%rax,1)
movsd  %xmm1,0x8(%rsp)
movapd %xmm1,%xmm0
call   1060 <fast_sin@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
movsd  %xmm1,(%rsp)
movsd  0x8(%rsp),%xmm1
addsd  0xdcd(%rip),%xmm1
movsd  0xdcd(%rip),%xmm0
ucomisd %xmm1,%xmm0
ja     1200 <main+0xc0>
sub    %r14,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
divsd  0x10(%rsp),%xmm0
movsd  %xmm0,0x8(%rsp)
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r15,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
divsd  (%r12),%xmm0
movsd  %xmm0,0x10(%rsp)
lea    0xd93(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1040 <printf@plt>
lea    0xd86(%rip),%rdi
movsd  0x8(%rsp),%xmm0
movsd  0x10(%rsp),%xmm1
mov    $0x2,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [6 x i8] c"%.4f\0A\00"
@.str.1 = [22 x i8] c"lib:\09%.2f\0Afast:\09%.2f\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca float
%7 = alloca double
%8 = alloca double
%9 = alloca i64
%10 = alloca double
%11 = alloca i64
%12 = alloca double
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store float 0x3E7AD7F2A0000000, float* %6
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
%13 = call i64 (...) @clock()
store i64 %13, i64* %9
br label %14
14: ; preds = %17, %2
%15 = load double, double* %7
%16 = fcmp olt double %15, 0x400921FB53C8D4F1
br i1 %16, label %17, label %25
17: ; preds = %14
%18 = load double, double* %7
%19 = call i64 @sin(double %18)
%20 = sitofp i64 %19 to double
%21 = load double, double* %8
%22 = fadd double %21, %20
store double %22, double* %8
%23 = load double, double* %7
%24 = fadd double %23, 0x3E7AD7F2A0000000
store double %24, double* %7
br label %14
25: ; preds = %14
%26 = call i64 (...) @clock()
%27 = load i64, i64* %9
%28 = sub nsw i64 %26, %27
%29 = sitofp i64 %28 to double
%30 = load double, double* @CLOCKS_PER_SEC
%31 = fdiv double %29, %30
store double %31, double* %10
%32 = load double, double* %8
%33 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %32)
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
%34 = call i64 (...) @clock()
store i64 %34, i64* %11
br label %35
35: ; preds = %38, %25
%36 = load double, double* %7
%37 = fcmp olt double %36, 0x400921FB53C8D4F1
br i1 %37, label %38, label %46
38: ; preds = %35
%39 = load double, double* %7
%40 = call i64 @fast_sin(double %39)
%41 = sitofp i64 %40 to double
%42 = load double, double* %8
%43 = fadd double %42, %41
store double %43, double* %8
%44 = load double, double* %7
%45 = fadd double %44, 0x3E7AD7F2A0000000
store double %45, double* %7
br label %35
46: ; preds = %35
%47 = call i64 (...) @clock()
%48 = load i64, i64* %11
%49 = sub nsw i64 %47, %48
%50 = sitofp i64 %49 to double
%51 = load double, double* @CLOCKS_PER_SEC
%52 = fdiv double %50, %51
store double %52, double* %12
%53 = load double, double* %8
%54 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %53)
%55 = load double, double* %10
%56 = load double, double* %12
%57 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), double %55, double %56)
ret i32 0
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str = [6 x i8] c"%.4f\0A\00"
@.str.1 = [22 x i8] c"lib:\09%.2f\0Afast:\09%.2f\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call i64 (...) @clock()
br label %4
4: ; preds = %2, %4
%5 = phi double [ 0.000000e+00, %2 ], [ %10, %4 ]
%6 = phi double [ 0.000000e+00, %2 ], [ %9, %4 ]
%7 = tail call i64 @sin(double %5)
%8 = sitofp i64 %7 to double
%9 = fadd double %6, %8
%10 = fadd double %5, 0x3E7AD7F2A0000000
%11 = fcmp olt double %10, 0x400921FB53C8D4F1
br i1 %11, label %4, label %12
12: ; preds = %4
%13 = tail call i64 (...) @clock()
%14 = load double, double* @CLOCKS_PER_SEC
%15 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %9)
%16 = tail call i64 (...) @clock()
br label %17
17: ; preds = %12, %17
%18 = phi double [ 0.000000e+00, %12 ], [ %23, %17 ]
%19 = phi double [ 0.000000e+00, %12 ], [ %22, %17 ]
%20 = tail call i64 @fast_sin(double %18)
%21 = sitofp i64 %20 to double
%22 = fadd double %19, %21
%23 = fadd double %18, 0x3E7AD7F2A0000000
%24 = fcmp olt double %23, 0x400921FB53C8D4F1
br i1 %24, label %17, label %25
25: ; preds = %17
%26 = sub nsw i64 %13, %3
%27 = sitofp i64 %26 to double
%28 = fdiv double %27, %14
%29 = tail call i64 (...) @clock()
%30 = sub nsw i64 %29, %16
%31 = sitofp i64 %30 to double
%32 = load double, double* @CLOCKS_PER_SEC
%33 = fdiv double %31, %32
%34 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), double %22)
%35 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.1, i64 0, i64 0), double %28, double %33)
ret i32 0
}