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

/* Variables and functions */
int /*<<< orphan*/ printf(char *);
float rand_float();
int /*<<< orphan*/ stdlib_base_float32_to_word(float, int *);
double tic();
double benchmark() {
  double elapsed;
  uint32_t w;
  double t;
  float x;
  int i;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    x = (1000.0f * rand_float()) - 500.0f;
    stdlib_base_float32_to_word(x, &w);
    if (w == 1) {
      printf("unexpected result\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (w == 1) {
    printf("unexpected result\n");
  }
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1050 <tic@plt>
movsd  %xmm0,-0x18(%rbp)
movl   $0x0,-0x20(%rbp)
cmpl   $0xf4240,-0x20(%rbp)
jge    11c8 <benchmark+0x88>
mov    $0x0,%al
call   1030 <rand_float@plt>
movss  0xe89(%rip),%xmm1
mulss  %xmm1,%xmm0
movss  0xe81(%rip),%xmm1
addss  %xmm1,%xmm0
movss  %xmm0,-0x1c(%rbp)
movss  -0x1c(%rbp),%xmm0
lea    -0xc(%rbp),%rdi
call   1060 <stdlib_base_float32_to_word@plt>
cmpl   $0x1,-0xc(%rbp)
jne    11b5 <benchmark+0x75>
lea    0xe5d(%rip),%rdi
call   1040 <printf@plt>
jmp    11c8 <benchmark+0x88>
jmp    11ba <benchmark+0x7a>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    115b <benchmark+0x1b>
mov    $0x0,%al
call   1050 <tic@plt>
subsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpl   $0x1,-0xc(%rbp)
jne    11ef <benchmark+0xaf>
lea    0xe1e(%rip),%rdi
call   1040 <printf@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1050 <tic@plt>
movsd  %xmm0,0x10(%rsp)
mov    $0xf4240,%ebp
lea    0x4(%rsp),%rbx
nopl   (%rax)
xor    %eax,%eax
call   1040 <rand_float@plt>
mulss  0xe91(%rip),%xmm0
addss  0xe8d(%rip),%xmm0
mov    %rbx,%rdi
call   1060 <stdlib_base_float32_to_word@plt>
cmpl   $0x1,0x4(%rsp)
je     118d <benchmark+0x4d>
add    $0xffffffff,%ebp
jne    1160 <benchmark+0x20>
jmp    1199 <benchmark+0x59>
lea    0xe74(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <tic@plt>
cmpl   $0x1,0x4(%rsp)
jne    11bf <benchmark+0x7f>
lea    0xe5a(%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 i32
%3 = alloca double
%4 = alloca float
%5 = alloca i32
%6 = call double (...) @tic()
store double %6, double* %3
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 float (...) @rand_float()
%12 = call float @llvm.fmuladd.f32(float 1.000000e+03, float %11, float -5.000000e+02)
store float %12, float* %4
%13 = load float, float* %4
%14 = call i32 @stdlib_base_float32_to_word(float %13, i32* %2)
%15 = load i32, i32* %2
%16 = icmp eq i32 %15, 1
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* %3
%26 = fsub double %24, %25
store double %26, double* %1
%27 = load i32, i32* %2
%28 = icmp eq i32 %27, 1
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 i32
%2 = bitcast i32* %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 float (...) @rand_float()
%10 = call float @llvm.fmuladd.f32(float %9, float 1.000000e+03, float -5.000000e+02)
%11 = call i32 @stdlib_base_float32_to_word(float %10, i32* %1)
%12 = load i32, i32* %1
%13 = icmp eq i32 %12, 1
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 i32, i32* %1
%19 = icmp eq i32 %18, 1
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
}