#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_PI;
double cos(double);
int /*<<< orphan*/ printf(char *);
double rand_double();
double sin(double);
double tic();
double benchmark() {
  double elapsed;
  double x;
  double y;
  double z;
  double t;
  int i;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    x = (20.0 * rand_double()) - 10.0;
    y = sin(M_PI * x);
    z = cos(M_PI * x);
    if (y != y || z != z) {
      printf("should not return NaN\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (y != y || z != z) {
    printf("should not return NaN\n");
  }
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    $0x0,%al
call   1040 <tic@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
cmpl   $0xf4240,-0x2c(%rbp)
jge    1225 <benchmark+0xd5>
mov    $0x0,%al
call   1050 <rand_double@plt>
movsd  0xe79(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe75(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x10(%rbp)
mov    0x2e45(%rip),%rax
movsd  (%rax),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1060 <sin@plt>
movsd  %xmm0,-0x18(%rbp)
mov    0x2e2b(%rip),%rax
movsd  (%rax),%xmm0
mulsd  -0x10(%rbp),%xmm0
call   1070 <cos@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    1201 <benchmark+0xb1>
jp     1201 <benchmark+0xb1>
movsd  -0x20(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jne    1201 <benchmark+0xb1>
jp     1201 <benchmark+0xb1>
jmp    1212 <benchmark+0xc2>
lea    0xe08(%rip),%rdi
call   1030 <printf@plt>
jmp    1225 <benchmark+0xd5>
jmp    1217 <benchmark+0xc7>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    116b <benchmark+0x1b>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x18(%rbp),%xmm0
ucomisd -0x18(%rbp),%xmm0
jne    1267 <benchmark+0x117>
jp     1267 <benchmark+0x117>
movsd  -0x20(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jne    1267 <benchmark+0x117>
jp     1267 <benchmark+0x117>
jmp    1273 <benchmark+0x123>
lea    0xda2(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark>:
push   %r14
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xf4240,%ebx
mov    0x2e78(%rip),%r14
xor    %eax,%eax
call   1050 <rand_double@plt>
movapd %xmm0,%xmm1
mulsd  0xe7d(%rip),%xmm1
addsd  0xe7d(%rip),%xmm1
movsd  %xmm1,0x10(%rsp)
movsd  (%r14),%xmm0
mulsd  %xmm1,%xmm0
call   1060 <sin@plt>
movsd  %xmm0,(%rsp)
movsd  0x10(%rsp),%xmm0
mulsd  (%r14),%xmm0
call   1070 <cos@plt>
movsd  (%rsp),%xmm1
ucomisd %xmm1,%xmm1
jp     11d3 <benchmark+0x83>
ucomisd %xmm0,%xmm0
jp     11d3 <benchmark+0x83>
add    $0xffffffff,%ebx
jne    1170 <benchmark+0x20>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    11fb <benchmark+0xab>
lea    0xe36(%rip),%rbx
mov    %rbx,%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,(%rsp)
mov    %rbx,%rdi
call   1030 <puts@plt>
movsd  (%rsp),%xmm0
subsd  0x8(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@M_PI = global double 0.000000e+00
@.str = [23 x i8] c"should not return NaN\0A\00"
define double @benchmark() {
%1 = alloca double
%2 = alloca double
%3 = alloca double
%4 = alloca double
%5 = alloca double
%6 = alloca i32
%7 = call double (...) @tic()
store double %7, double* %5
store i32 0, i32* %6
br label %8
8: ; preds = %32, %0
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 1000000
br i1 %10, label %11, label %35
11: ; preds = %8
%12 = call double (...) @rand_double()
%13 = call double @llvm.fmuladd.f64(double 2.000000e+01, double %12, double -1.000000e+01)
store double %13, double* %2
%14 = load double, double* @M_PI
%15 = load double, double* %2
%16 = fmul double %14, %15
%17 = call double @sin(double %16)
store double %17, double* %3
%18 = load double, double* @M_PI
%19 = load double, double* %2
%20 = fmul double %18, %19
%21 = call double @cos(double %20)
store double %21, double* %4
%22 = load double, double* %3
%23 = load double, double* %3
%24 = fcmp une double %22, %23
br i1 %24, label %29, label %25
25: ; preds = %11
%26 = load double, double* %4
%27 = load double, double* %4
%28 = fcmp une double %26, %27
br i1 %28, label %29, label %31
29: ; preds = %25, %11
%30 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %35
31: ; preds = %25
br label %32
32: ; preds = %31
%33 = load i32, i32* %6
%34 = add nsw i32 %33, 1
store i32 %34, i32* %6
br label %8
35: ; preds = %29, %8
%36 = call double (...) @tic()
%37 = load double, double* %5
%38 = fsub double %36, %37
store double %38, double* %1
%39 = load double, double* %3
%40 = load double, double* %3
%41 = fcmp une double %39, %40
br i1 %41, label %46, label %42
42: ; preds = %35
%43 = load double, double* %4
%44 = load double, double* %4
%45 = fcmp une double %43, %44
br i1 %45, label %46, label %48
46: ; preds = %42, %35
%47 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %48
48: ; preds = %46, %42
%49 = load double, double* %1
ret double %49
}

LLVM IR (-O2):
@M_PI = global double 0.000000e+00
@str.1 = [22 x i8] c"should not return NaN\00"
define double @benchmark() {
%1 = tail call double (...) @tic()
br label %5
2: ; preds = %5
%3 = add nuw nsw i32 %6, 1
%4 = icmp eq i32 %3, 1000000
br i1 %4, label %18, label %5
5: ; preds = %0, %2
%6 = phi i32 [ 0, %0 ], [ %3, %2 ]
%7 = tail call double (...) @rand_double()
%8 = tail call double @llvm.fmuladd.f64(double %7, double 2.000000e+01, double -1.000000e+01)
%9 = load double, double* @M_PI
%10 = fmul double %9, %8
%11 = tail call double @sin(double %10)
%12 = load double, double* @M_PI
%13 = fmul double %8, %12
%14 = tail call double @cos(double %13)
%15 = fcmp uno double %11, 0.000000e+00
%16 = fcmp uno double %14, 0.000000e+00
%17 = select i1 %15, i1 true, i1 %16
br i1 %17, label %20, label %2
18: ; preds = %2
%19 = tail call double (...) @tic()
br label %24
20: ; preds = %5
%21 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.1, i64 0, i64 0))
%22 = tail call double (...) @tic()
%23 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str.1, i64 0, i64 0))
br label %24
24: ; preds = %18, %20
%25 = phi double [ %19, %18 ], [ %22, %20 ]
%26 = fsub double %25, %1
ret double %26
}