#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__ CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, double);
int main(void) {
  clock_t start;
  clock_t end;
  double elapsed;
  long i;
  start = clock();
  for (i = 0; i != 1000000; i++) {
    printf("i = %ld\n", i);
  }
  printf("i = %ld\n", i);
  end = clock();
  elapsed = (double)(end - start) / (double)CLOCKS_PER_SEC;
  printf("elapsed = %lf\n", elapsed);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0xf4240,-0x28(%rbp)
je     1173 <main+0x53>
cvtsi2sdq -0x28(%rbp),%xmm0
lea    0xea3(%rip),%rdi
call   1040 <printf@plt>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1142 <main+0x22>
cvtsi2sdq -0x28(%rbp),%xmm0
lea    0xe80(%rip),%rdi
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e44(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xe4b(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
xor    %ebx,%ebx
xor    %eax,%eax
call   1030 <clock@plt>
mov    %rax,%r14
lea    0xed0(%rip),%r15
nopl   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %rbx,%xmm0
mov    %r15,%rdi
call   1040 <printf@plt>
add    $0x1,%rbx
cmp    $0xf4240,%rbx
jne    1140 <main+0x20>
lea    0xea4(%rip),%rdi
movsd  0xe94(%rip),%xmm0
call   1040 <printf@plt>
xor    %eax,%eax
call   1030 <clock@plt>
sub    %r14,%rax
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
mov    0x2e5e(%rip),%rax
cvtsi2sdq (%rax),%xmm1
divsd  %xmm1,%xmm0
lea    0xe77(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [9 x i8] c"i = %ld\0A\00"
@CLOCKS_PER_SEC = global i64 0
@.str.1 = [15 x i8] c"elapsed = %lf\0A\00"
define i32 @main() {
%1 = tail call i64 (...) @clock()
br label %2
2: ; preds = %0, %2
%3 = phi i64 [ 0, %0 ], [ %6, %2 ]
%4 = sitofp i64 %3 to double
%5 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %4)
%6 = add nuw nsw i64 %3, 1
%7 = icmp eq i64 %6, 1000000
br i1 %7, label %8, label %2
8: ; preds = %2
%9 = tail call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double 1.000000e+06)
%10 = tail call i64 (...) @clock()
%11 = sub nsw i64 %10, %1
%12 = sitofp i64 %11 to double
%13 = load i64, i64* @CLOCKS_PER_SEC
%14 = sitofp i64 %13 to double
%15 = fdiv double %12, %14
%16 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %15)
ret i32 0
}