#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 modf(double, double *);
int /*<<< orphan*/ printf(char *);
double rand_double();
double tic();
double benchmark() {
  double elapsed;
  double iptr;
  double x;
  double y;
  double t;
  int i;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    x = (1.0e7 * rand_double()) - 5.0e6;
    y = modf(x, &iptr);
    if (y != y) {
      printf("should not return NaN\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (y != y) {
    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    11de <benchmark+0x9e>
mov    $0x0,%al
call   1060 <rand_double@plt>
movsd  0xe89(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe85(%rip),%xmm1
addsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    -0x10(%rbp),%rdi
call   1050 <modf@plt>
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jne    11ba <benchmark+0x7a>
jp     11ba <benchmark+0x7a>
jmp    11cb <benchmark+0x8b>
lea    0xe4f(%rip),%rdi
call   1030 <printf@plt>
jmp    11de <benchmark+0x9e>
jmp    11d0 <benchmark+0x90>
mov    -0x2c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x2c(%rbp)
jmp    115b <benchmark+0x1b>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x28(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
movsd  -0x20(%rbp),%xmm0
ucomisd -0x20(%rbp),%xmm0
jne    120a <benchmark+0xca>
jp     120a <benchmark+0xca>
jmp    1216 <benchmark+0xd6>
lea    0xdff(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xf4240,%ebp
lea    0x10(%rsp),%rbx
nopl   (%rax)
xor    %eax,%eax
call   1060 <rand_double@plt>
mulsd  0xe91(%rip),%xmm0
addsd  0xe91(%rip),%xmm0
mov    %rbx,%rdi
call   1050 <modf@plt>
ucomisd %xmm0,%xmm0
jp     1193 <benchmark+0x53>
add    $0xffffffff,%ebp
jne    1160 <benchmark+0x20>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    11bb <benchmark+0x7b>
lea    0xe76(%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    %rbp
ret

LLVM IR (-O0):
@.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 = %22, %0
%9 = load i32, i32* %6
%10 = icmp slt i32 %9, 1000000
br i1 %10, label %11, label %25
11: ; preds = %8
%12 = call double (...) @rand_double()
%13 = call double @llvm.fmuladd.f64(double 1.000000e+07, double %12, double -5.000000e+06)
store double %13, double* %3
%14 = load double, double* %3
%15 = call double @modf(double %14, double* %2)
store double %15, double* %4
%16 = load double, double* %4
%17 = load double, double* %4
%18 = fcmp une double %16, %17
br i1 %18, label %19, label %21
19: ; preds = %11
%20 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %25
21: ; preds = %11
br label %22
22: ; preds = %21
%23 = load i32, i32* %6
%24 = add nsw i32 %23, 1
store i32 %24, i32* %6
br label %8
25: ; preds = %19, %8
%26 = call double (...) @tic()
%27 = load double, double* %5
%28 = fsub double %26, %27
store double %28, double* %1
%29 = load double, double* %4
%30 = load double, double* %4
%31 = fcmp une double %29, %30
br i1 %31, label %32, label %34
32: ; preds = %25
%33 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
br label %34
34: ; preds = %32, %25
%35 = load double, double* %1
ret double %35
}

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