#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__ uint32_t;

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
double rand_double();
int /*<<< orphan*/ stdlib_base_float64_get_low_word(double, scalar_t__ *);
double tic();
double benchmark() {
  double elapsed;
  uint32_t l;
  double x;
  double t;
  int i;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    x = (1000.0 * rand_double()) + 500.0;
    stdlib_base_float64_get_low_word(x, &l);
    if (l == 0) {
      printf("unexpected result\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (l == 0) {
    printf("unexpected result\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,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
cmpl   $0xf4240,-0x24(%rbp)
jge    11c9 <benchmark+0x89>
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 <stdlib_base_float64_get_low_word@plt>
cmpq   $0x0,-0x10(%rbp)
jne    11b6 <benchmark+0x76>
lea    0xe64(%rip),%rdi
call   1030 <printf@plt>
jmp    11c9 <benchmark+0x89>
jmp    11bb <benchmark+0x7b>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    115b <benchmark+0x1b>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x20(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11f1 <benchmark+0xb1>
lea    0xe24(%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,0x10(%rsp)
mov    $0xf4240,%ebp
mov    %rsp,%rbx
nopl   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1060 <rand_double@plt>
mulsd  0xe91(%rip),%xmm0
addsd  0xe91(%rip),%xmm0
mov    %rbx,%rdi
call   1050 <stdlib_base_float64_get_low_word@plt>
cmpq   $0x0,(%rsp)
je     118d <benchmark+0x4d>
add    $0xffffffff,%ebp
jne    1160 <benchmark+0x20>
jmp    1199 <benchmark+0x59>
lea    0xe7c(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <tic@plt>
cmpq   $0x0,(%rsp)
jne    11bf <benchmark+0x7f>
lea    0xe62(%rip),%rdi
movsd  %xmm0,0x8(%rsp)
call   1030 <puts@plt>
movsd  0x8(%rsp),%xmm0
subsd  0x10(%rsp),%xmm0
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [19 x i8] c"unexpected result\0A\00"
define double @benchmark() {
%1 = alloca double
%2 = alloca i64
%3 = alloca double
%4 = alloca double
%5 = alloca i32
%6 = call double (...) @tic()
store double %6, double* %4
store i32 0, i32* %5
br label %7
7: ; preds = %20, %0
%8 = load i32, i32* %5
%9 = icmp slt i32 %8, 1000000
br i1 %9, label %10, label %23
10: ; preds = %7
%11 = call double (...) @rand_double()
%12 = call double @llvm.fmuladd.f64(double 1.000000e+03, double %11, double 5.000000e+02)
store double %12, double* %3
%13 = load double, double* %3
%14 = call i32 @stdlib_base_float64_get_low_word(double %13, i64* %2)
%15 = load i64, i64* %2
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %19
17: ; preds = %10
%18 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %23
19: ; preds = %10
br label %20
20: ; preds = %19
%21 = load i32, i32* %5
%22 = add nsw i32 %21, 1
store i32 %22, i32* %5
br label %7
23: ; preds = %17, %7
%24 = call double (...) @tic()
%25 = load double, double* %4
%26 = fsub double %24, %25
store double %26, double* %1
%27 = load i64, i64* %2
%28 = icmp eq i64 %27, 0
br i1 %28, label %29, label %31
29: ; preds = %23
%30 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
br label %31
31: ; preds = %29, %23
%32 = load double, double* %1
ret double %32
}

LLVM IR (-O2):
@str.1 = [18 x i8] c"unexpected result\00"
define double @benchmark() {
%1 = alloca i64
%2 = bitcast i64* %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 %16, label %7
7: ; preds = %0, %4
%8 = phi i32 [ 0, %0 ], [ %5, %4 ]
%9 = call double (...) @rand_double()
%10 = call double @llvm.fmuladd.f64(double %9, double 1.000000e+03, double 5.000000e+02)
%11 = call i32 @stdlib_base_float64_get_low_word(double %10, i64* %1)
%12 = load i64, i64* %1
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %4
14: ; preds = %7
%15 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.1, i64 0, i64 0))
br label %16
16: ; preds = %4, %14
%17 = call double (...) @tic()
%18 = load i64, i64* %1
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %22
20: ; preds = %16
%21 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([18 x i8], [18 x i8]* @str.1, i64 0, i64 0))
br label %22
22: ; preds = %20, %16
%23 = fsub double %17, %3
ret double %23
}