#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 rand();
int main() {
  long t0, t1;
  int i, n;
  printf("Testing...\n");
  t0 = getutime();
  for (i = 0; i < 50000000; ++i)
    n = rand();
  t1 = getutime();
  printf("Time %ld msec (%.3g nsec per cycle)\n", (t1 - t0) / 1000,
         (double)(t1 - t0) * 1000 / 50000000);
  printf("Rate %.3g megacalls per second\n", 50000000 / (double)(t1 - t0));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeca(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x0,%al
call   1040 <getutime@plt>
mov    %rax,-0x10(%rbp)
movl   $0x0,-0x1c(%rbp)
cmpl   $0x2faf080,-0x1c(%rbp)
jge    1184 <main+0x54>
mov    $0x0,%al
call   1050 <rand@plt>
mov    %eax,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    115f <main+0x2f>
mov    $0x0,%al
call   1040 <getutime@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,%rsi
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
cvtsi2sd %rax,%xmm0
movsd  0xe4f(%rip),%xmm1
mulsd  %xmm1,%xmm0
movsd  0xe3b(%rip),%xmm1
divsd  %xmm1,%xmm0
lea    0xe4c(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
cvtsi2sd %rax,%xmm1
movsd  0xe14(%rip),%xmm0
divsd  %xmm1,%xmm0
lea    0xe4a(%rip),%rdi
mov    $0x1,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
lea    0xf0b(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1050 <getutime@plt>
mov    %rax,%rbx
mov    $0x2faf080,%ebp
xchg   %ax,%ax
xor    %eax,%eax
call   1060 <rand@plt>
add    $0xffffffff,%ebp
jne    1160 <main+0x20>
xor    %eax,%eax
call   1050 <getutime@plt>
mov    %rax,%rcx
sub    %rbx,%rcx
movabs $0x20c49ba5e353f7cf,%rdx
9b c4 20
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rsi
shr    $0x3f,%rsi
sar    $0x7,%rdx
add    %rdx,%rsi
cvtsi2sd %rcx,%xmm1
movsd  %xmm1,(%rsp)
movsd  0xe57(%rip),%xmm0
mulsd  %xmm1,%xmm0
divsd  0xe53(%rip),%xmm0
lea    0xe54(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
movsd  0xe3d(%rip),%xmm0
divsd  (%rsp),%xmm0
lea    0xe5e(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
@.str.1 = [37 x i8] c"Time %ld msec (%.3g nsec per cycle)\0A\00"
@.str.2 = [32 x i8] c"Rate %.3g megacalls per second\0A\00"
@str = [11 x i8] c"Testing...\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
%2 = tail call i64 (...) @getutime()
br label %3
3: ; preds = %0, %3
%4 = phi i32 [ 0, %0 ], [ %6, %3 ]
%5 = tail call i32 (...) @rand()
%6 = add nuw nsw i32 %4, 1
%7 = icmp eq i32 %6, 50000000
br i1 %7, label %8, label %3
8: ; preds = %3
%9 = tail call i64 (...) @getutime()
%10 = sub nsw i64 %9, %2
%11 = sdiv i64 %10, 1000
%12 = sitofp i64 %10 to double
%13 = fmul double %12, 1.000000e+03
%14 = fdiv double %13, 5.000000e+07
%15 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.1, i64 0, i64 0), i64 %11, double %14)
%16 = fdiv double 5.000000e+07, %12
%17 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([32 x i8], [32 x i8]* @.str.2, i64 0, i64 0), double %16)
ret i32 0
}