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

/* Variables and functions */
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, double, ...);
int /*<<< orphan*/ putchar(char);
int main(void) {
  int e;
  int loopn = 10000000;
  clock_t timeA, timeB;
  double runtime = 0;
  for (e = 0; e < 10; ++e) {
    printf("Random clock() value %d = [%d]\n", e, (int)clock());
  }
  putchar('\n');
  timeA = clock();
  for (e = 0; e < loopn; ++e) {
    timeB = clock();
    runtime = (runtime + (double)(timeB - timeA)) / 2;
    timeA = clock();
  }
  printf("\nAverage run-time of a fairly simple for loop = [%f] microseconds\n",
         runtime);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x989680,-0xc(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x8(%rbp)
cmpl   $0xa,-0x8(%rbp)
jge    1193 <main+0x63>
cvtsi2sdl -0x8(%rbp),%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
movsd  -0x30(%rbp),%xmm0
mov    %eax,%esi
lea    0xe8a(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1155 <main+0x25>
mov    $0xa,%edi
call   1030 <putchar@plt>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x18(%rbp)
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0xc(%rbp),%eax
jge    1206 <main+0xd6>
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x20(%rbp)
movsd  -0x28(%rbp),%xmm0
mov    -0x20(%rbp),%rax
sub    -0x18(%rbp),%rax
cvtsi2sd %rax,%xmm1
addsd  %xmm1,%xmm0
movsd  0xe1c(%rip),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x28(%rbp)
mov    $0x0,%al
call   1040 <clock@plt>
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11af <main+0x7f>
movsd  -0x28(%rbp),%xmm0
lea    0xe16(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
xor    %eax,%eax
call   1040 <clock@plt>
lea    0xf0f(%rip),%rbx
xorps  %xmm0,%xmm0
movsd  %xmm0,(%rsp)
xorps  %xmm0,%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  0xe99(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  0xe86(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  0xe73(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  0xe60(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  0xe4d(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  0xe3a(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  0xe27(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  0xe14(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
call   1040 <clock@plt>
movsd  0xe01(%rip),%xmm0
mov    %rbx,%rdi
mov    %eax,%esi
mov    $0x1,%al
call   1050 <printf@plt>
mov    $0xa,%edi
call   1030 <putchar@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbx
mov    $0x989680,%ebp
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
xor    %eax,%eax
call   1040 <clock@plt>
sub    %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
addsd  %xmm0,%xmm1
mulsd  0xdb5(%rip),%xmm1
movsd  %xmm1,(%rsp)
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbx
add    $0xffffffff,%ebp
jne    1270 <main+0x140>
lea    0xdc2(%rip),%rdi
movsd  (%rsp),%xmm0
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [32 x i8] c"Random clock() value %d = [%d]\0A\00"
@.str.1 = [67 x i8] c"\0AAverage run-time of a fairly simple for loop = [%f] microseconds\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i64
%5 = alloca i64
%6 = alloca double
store i32 0, i32* %1
store i32 10000000, i32* %3
store double 0.000000e+00, double* %6
store i32 0, i32* %2
br label %7
7: ; preds = %16, %0
%8 = load i32, i32* %2
%9 = icmp slt i32 %8, 10
br i1 %9, label %10, label %19
10: ; preds = %7
%11 = load i32, i32* %2
%12 = sitofp i32 %11 to double
%13 = call i64 (...) @clock()
%14 = trunc i64 %13 to i32
%15 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double %12, i32 %14)
br label %16
16: ; preds = %10
%17 = load i32, i32* %2
%18 = add nsw i32 %17, 1
store i32 %18, i32* %2
br label %7
19: ; preds = %7
%20 = call i32 @putchar(i8 signext 10)
%21 = call i64 (...) @clock()
store i64 %21, i64* %4
store i32 0, i32* %2
br label %22
22: ; preds = %36, %19
%23 = load i32, i32* %2
%24 = load i32, i32* %3
%25 = icmp slt i32 %23, %24
br i1 %25, label %26, label %39
26: ; preds = %22
%27 = call i64 (...) @clock()
store i64 %27, i64* %5
%28 = load double, double* %6
%29 = load i64, i64* %5
%30 = load i64, i64* %4
%31 = sub nsw i64 %29, %30
%32 = sitofp i64 %31 to double
%33 = fadd double %28, %32
%34 = fdiv double %33, 2.000000e+00
store double %34, double* %6
%35 = call i64 (...) @clock()
store i64 %35, i64* %4
br label %36
36: ; preds = %26
%37 = load i32, i32* %2
%38 = add nsw i32 %37, 1
store i32 %38, i32* %2
br label %22
39: ; preds = %22
%40 = load double, double* %6
%41 = call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), double %40)
ret i32 0
}

LLVM IR (-O2):
@.str = [32 x i8] c"Random clock() value %d = [%d]\0A\00"
@.str.1 = [67 x i8] c"\0AAverage run-time of a fairly simple for loop = [%f] microseconds\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @clock()
%2 = trunc i64 %1 to i32
%3 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 0.000000e+00, i32 %2)
%4 = tail call i64 (...) @clock()
%5 = trunc i64 %4 to i32
%6 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 1.000000e+00, i32 %5)
%7 = tail call i64 (...) @clock()
%8 = trunc i64 %7 to i32
%9 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 2.000000e+00, i32 %8)
%10 = tail call i64 (...) @clock()
%11 = trunc i64 %10 to i32
%12 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 3.000000e+00, i32 %11)
%13 = tail call i64 (...) @clock()
%14 = trunc i64 %13 to i32
%15 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 4.000000e+00, i32 %14)
%16 = tail call i64 (...) @clock()
%17 = trunc i64 %16 to i32
%18 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 5.000000e+00, i32 %17)
%19 = tail call i64 (...) @clock()
%20 = trunc i64 %19 to i32
%21 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 6.000000e+00, i32 %20)
%22 = tail call i64 (...) @clock()
%23 = trunc i64 %22 to i32
%24 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 7.000000e+00, i32 %23)
%25 = tail call i64 (...) @clock()
%26 = trunc i64 %25 to i32
%27 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 8.000000e+00, i32 %26)
%28 = tail call i64 (...) @clock()
%29 = trunc i64 %28 to i32
%30 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str, i64 0, i64 0), double 9.000000e+00, i32 %29)
%31 = tail call i32 @putchar(i8 signext 10)
%32 = tail call i64 (...) @clock()
br label %33
33: ; preds = %0, %33
%34 = phi double [ 0.000000e+00, %0 ], [ %41, %33 ]
%35 = phi i32 [ 0, %0 ], [ %43, %33 ]
%36 = phi i64 [ %32, %0 ], [ %42, %33 ]
%37 = tail call i64 (...) @clock()
%38 = sub nsw i64 %37, %36
%39 = sitofp i64 %38 to double
%40 = fadd double %34, %39
%41 = fmul double %40, 5.000000e-01
%42 = tail call i64 (...) @clock()
%43 = add nuw nsw i32 %35, 1
%44 = icmp eq i32 %43, 10000000
br i1 %44, label %45, label %33
45: ; preds = %33
%46 = tail call i32 (i8*, double, ...) @printf(i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0), double %41)
ret i32 0
}