#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 */
int /*<<< orphan*/ printf(char *);
int rand();
double tic();
double benchmark() {
  double elapsed;
  double t;
  int y;
  int i;
  t = tic();
  for (i = 0; i < 1000000; i++) {
    y = rand();
    if (y < 0) {
      printf("should return a value greater than 0\n");
      break;
    }
  }
  elapsed = tic() - t;
  if (y < 0) {
    printf("should return a value greater than 0\n");
  }
  return elapsed;
}


x86 assembly (clang, -O0):
<benchmark>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    $0x0,%al
call   1040 <tic@plt>
movsd  %xmm0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
cmpl   $0xf4240,-0x18(%rbp)
jge    1190 <benchmark+0x60>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    117d <benchmark+0x4d>
lea    0xe8d(%rip),%rdi
call   1030 <printf@plt>
jmp    1190 <benchmark+0x60>
jmp    1182 <benchmark+0x52>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    114b <benchmark+0x1b>
mov    $0x0,%al
call   1040 <tic@plt>
subsd  -0x10(%rbp),%xmm0
movsd  %xmm0,-0x8(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11b7 <benchmark+0x87>
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
movsd  -0x8(%rbp),%xmm0
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<benchmark>:
push   %rbx
sub    $0x10,%rsp
xor    %eax,%eax
call   1040 <tic@plt>
movsd  %xmm0,0x8(%rsp)
mov    $0xf4240,%ebx
nopw   0x0(%rax,%rax,1)
xor    %eax,%eax
call   1050 <rand@plt>
test   %eax,%eax
js     1169 <benchmark+0x39>
add    $0xffffffff,%ebx
jne    1150 <benchmark+0x20>
xor    %eax,%eax
call   1040 <tic@plt>
jmp    1191 <benchmark+0x61>
lea    0xe90(%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    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [38 x i8] c"should return a value greater than 0\0A\00"
define double @benchmark() {
%1 = alloca double
%2 = alloca double
%3 = alloca i32
%4 = alloca i32
%5 = call double (...) @tic()
store double %5, double* %2
store i32 0, i32* %4
br label %6
6: ; preds = %16, %0
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 1000000
br i1 %8, label %9, label %19
9: ; preds = %6
%10 = call i32 (...) @rand()
store i32 %10, i32* %3
%11 = load i32, i32* %3
%12 = icmp slt i32 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %19
15: ; preds = %9
br label %16
16: ; preds = %15
%17 = load i32, i32* %4
%18 = add nsw i32 %17, 1
store i32 %18, i32* %4
br label %6
19: ; preds = %13, %6
%20 = call double (...) @tic()
%21 = load double, double* %2
%22 = fsub double %20, %21
store double %22, double* %1
%23 = load i32, i32* %3
%24 = icmp slt i32 %23, 0
br i1 %24, label %25, label %27
25: ; preds = %19
%26 = call i32 @printf(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %27
27: ; preds = %25, %19
%28 = load double, double* %1
ret double %28
}

LLVM IR (-O2):
@str.1 = [37 x i8] c"should return a value greater than 0\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 %9, label %5
5: ; preds = %0, %2
%6 = phi i32 [ 0, %0 ], [ %3, %2 ]
%7 = tail call i32 (...) @rand()
%8 = icmp slt i32 %7, 0
br i1 %8, label %11, label %2
9: ; preds = %2
%10 = tail call double (...) @tic()
br label %15
11: ; preds = %5
%12 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.1, i64 0, i64 0))
%13 = tail call double (...) @tic()
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @str.1, i64 0, i64 0))
br label %15
15: ; preds = %9, %11
%16 = phi double [ %13, %11 ], [ %10, %9 ]
%17 = fsub double %16, %1
ret double %17
}