#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 */
long getutime();
int /*<<< orphan*/ printf(char *, ...);
int rand15();
int main() {
  long t0, t1;
  int i, n, cycles;
  printf("Testing 10 seconds...\n");
  cycles = 0;
  t0 = getutime();
  do {
    for (i = 0; i < 100000000; ++i)
      n = rand15();
    cycles += 100000000;
    t1 = getutime();
  } while (t1 < t0 + 10000000);
  printf("Total %.3g nanoseconds per cycle\n",
         (double)(t1 - t0) * 1000 / cycles);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xec2(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x0,-0x24(%rbp)
mov    $0x0,%al
call   1050 <getutime@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x5f5e100,-0x1c(%rbp)
jge    118b <main+0x5b>
mov    $0x0,%al
call   1030 <rand15@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    1166 <main+0x36>
mov    -0x24(%rbp),%eax
add    $0x5f5e100,%eax
mov    %eax,-0x24(%rbp)
mov    $0x0,%al
call   1050 <getutime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    -0x10(%rbp),%rcx
add    $0x989680,%rcx
cmp    %rcx,%rax
jl     115f <main+0x2f>
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  0xe32(%rip),%xmm1
mulsd  %xmm1,%xmm0
cvtsi2sdl -0x24(%rbp),%xmm1
divsd  %xmm1,%xmm0
lea    0xe3d(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
lea    0xedc(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1060 <getutime@plt>
mov    %rax,%r14
lea    0x989680(%rax),%r15
xor    %ebp,%ebp
cs nopw 0x0(%rax,%rax,1)
mov    $0x5f5e100,%ebx
cs nopw 0x0(%rax,%rax,1)
nop
xor    %eax,%eax
call   1040 <rand15@plt>
add    $0xffffffff,%ebx
jne    1180 <main+0x40>
add    $0x5f5e100,%ebp
xor    %eax,%eax
call   1060 <getutime@plt>
cmp    %r15,%rax
jl     1170 <main+0x30>
sub    %r14,%rax
cvtsi2sd %rax,%xmm0
mulsd  0xe52(%rip),%xmm0
cvtsi2sd %ebp,%xmm1
divsd  %xmm1,%xmm0
lea    0xe4b(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [23 x i8] c"Testing 10 seconds...\0A\00"
@.str.1 = [34 x i8] c"Total %.3g nanoseconds per cycle\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i64
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32
store i32 0, i32* %1
%7 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i64 0, i64 0))
store i32 0, i32* %6
%8 = call i64 (...) @getutime()
store i64 %8, i64* %2
br label %9
9: ; preds = %22, %0
store i32 0, i32* %4
br label %10
10: ; preds = %15, %9
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 100000000
br i1 %12, label %13, label %18
13: ; preds = %10
%14 = call i32 (...) @rand15()
store i32 %14, i32* %5
br label %15
15: ; preds = %13
%16 = load i32, i32* %4
%17 = add nsw i32 %16, 1
store i32 %17, i32* %4
br label %10
18: ; preds = %10
%19 = load i32, i32* %6
%20 = add nsw i32 %19, 100000000
store i32 %20, i32* %6
%21 = call i64 (...) @getutime()
store i64 %21, i64* %3
br label %22
22: ; preds = %18
%23 = load i64, i64* %3
%24 = load i64, i64* %2
%25 = add nsw i64 %24, 10000000
%26 = icmp slt i64 %23, %25
br i1 %26, label %9, label %27
27: ; preds = %22
%28 = load i64, i64* %3
%29 = load i64, i64* %2
%30 = sub nsw i64 %28, %29
%31 = sitofp i64 %30 to double
%32 = fmul double %31, 1.000000e+03
%33 = load i32, i32* %6
%34 = sitofp i32 %33 to double
%35 = fdiv double %32, %34
%36 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), double %35)
ret i32 0
}

LLVM IR (-O2):
@.str.1 = [34 x i8] c"Total %.3g nanoseconds per cycle\0A\00"
@str = [22 x i8] c"Testing 10 seconds...\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%2 = tail call i64 (...) @getutime()
%3 = add nsw i64 %2, 10000000
br label %4
4: ; preds = %11, %0
%5 = phi i32 [ 0, %0 ], [ %12, %11 ]
br label %6
6: ; preds = %4, %6
%7 = phi i32 [ 0, %4 ], [ %9, %6 ]
%8 = tail call i32 (...) @rand15()
%9 = add nuw nsw i32 %7, 1
%10 = icmp eq i32 %9, 100000000
br i1 %10, label %11, label %6
11: ; preds = %6
%12 = add nuw nsw i32 %5, 100000000
%13 = tail call i64 (...) @getutime()
%14 = icmp slt i64 %13, %3
br i1 %14, label %4, label %15
15: ; preds = %11
%16 = sub nsw i64 %13, %2
%17 = sitofp i64 %16 to double
%18 = fmul double %17, 1.000000e+03
%19 = sitofp i32 %12 to double
%20 = fdiv double %18, %19
%21 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), double %20)
ret i32 0
}