#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 */
int CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, double);
int main(void) {
  long loop = 10000000L;
  double duration;
  clock_t start, end;
  printf("CLOCKS_PER_SEC=%d\n", CLOCKS_PER_SEC);
  printf("Time to do %ld empty loops is ", loop);
  start = clock();
  while (loop--)
    ;
  end = clock();
  duration = (double)(end - start) / CLOCKS_PER_SEC;
  printf("%f seconds\n", duration);
  return (0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movq   $0x989680,-0x10(%rbp)
mov    0x2eaa(%rip),%rax
cvtsi2sdl (%rax),%xmm0
lea    0xeb7(%rip),%rdi
call   1040 <printf@plt>
cvtsi2sdq -0x10(%rbp),%xmm0
lea    0xeb8(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0xffffffffffffffff,%rcx
mov    %rcx,-0x10(%rbp)
cmp    $0x0,%rax
je     1189 <main+0x69>
jmp    116b <main+0x4b>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
sub    -0x20(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e40(%rip),%rax
cvtsi2sdl (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe71(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
mov    0x2ebd(%rip),%r14
cvtsi2sdl (%r14),%xmm0
lea    0xed1(%rip),%rdi
call   1040 <printf@plt>
lea    0xed8(%rip),%rdi
movsd  0xeb5(%rip),%xmm0
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1030 <clock@plt>
sub    %rbx,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
cvtsi2sdl (%r14),%xmm1
divsd  %xmm1,%xmm0
lea    0xebe(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [19 x i8] c"CLOCKS_PER_SEC=%d\0A\00"
@CLOCKS_PER_SEC = global i32 0
@.str.1 = [31 x i8] c"Time to do %ld empty loops is \00"
@.str.2 = [12 x i8] c"%f seconds\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca double
%4 = alloca i64
%5 = alloca i64
store i32 0, i32* %1
store i64 10000000, i64* %2
%6 = load i32, i32* @CLOCKS_PER_SEC
%7 = sitofp i32 %6 to double
%8 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), double %7)
%9 = load i64, i64* %2
%10 = sitofp i64 %9 to double
%11 = call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), double %10)
%12 = call i64 (...) @clock()
store i64 %12, i64* %4
br label %13
13: ; preds = %17, %0
%14 = load i64, i64* %2
%15 = add nsw i64 %14, -1
store i64 %15, i64* %2
%16 = icmp ne i64 %14, 0
br i1 %16, label %17, label %18
17: ; preds = %13
br label %13
18: ; preds = %13
%19 = call i64 (...) @clock()
store i64 %19, i64* %5
%20 = load i64, i64* %5
%21 = load i64, i64* %4
%22 = sub nsw i64 %20, %21
%23 = sitofp i64 %22 to double
%24 = load i32, i32* @CLOCKS_PER_SEC
%25 = sitofp i32 %24 to double
%26 = fdiv double %23, %25
store double %26, double* %3
%27 = load double, double* %3
%28 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %27)
ret i32 0
}

LLVM IR (-O2):
@.str = [19 x i8] c"CLOCKS_PER_SEC=%d\0A\00"
@CLOCKS_PER_SEC = global i32 0
@.str.1 = [31 x i8] c"Time to do %ld empty loops is \00"
@.str.2 = [12 x i8] c"%f seconds\0A\00"
define i32 @main() {
%1 = load i32, i32* @CLOCKS_PER_SEC
%2 = sitofp i32 %1 to double
%3 = tail call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0), double %2)
%4 = tail call i32 @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.1, i64 0, i64 0), double 1.000000e+07)
%5 = tail call i64 (...) @clock()
%6 = tail call i64 (...) @clock()
%7 = sub nsw i64 %6, %5
%8 = sitofp i64 %7 to double
%9 = load i32, i32* @CLOCKS_PER_SEC
%10 = sitofp i32 %9 to double
%11 = fdiv double %8, %10
%12 = tail call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), double %11)
ret i32 0
}