#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 int /*<<< orphan*/ time_t;

/* Variables and functions */
double difftime(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, double);
int /*<<< orphan*/ time(int /*<<< orphan*/ *);
int main(void) {
  time_t start;
  time_t end;
  double elapsed;
  long i;
  start = time(NULL);
  for (i = 0; i != 1000000; i++) {
    printf("i = %ld\n", i);
  }
  printf("i = %ld\n", i);
  end = time(NULL);
  elapsed = difftime(end, start);
  printf("elapsed = %lf\n", elapsed);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0x8(%rbp)
movq   $0x0,-0x20(%rbp)
cmpq   $0xf4240,-0x20(%rbp)
je     1184 <main+0x54>
cvtsi2sdq -0x20(%rbp),%xmm0
lea    0xe92(%rip),%rdi
call   1030 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
jmp    1153 <main+0x23>
cvtsi2sdq -0x20(%rbp),%xmm0
lea    0xe6f(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1050 <time@plt>
mov    %eax,-0xc(%rbp)
mov    -0xc(%rbp),%edi
mov    -0x8(%rbp),%esi
call   1040 <difftime@plt>
movsd  %xmm0,-0x18(%rbp)
movsd  -0x18(%rbp),%xmm0
lea    0xe4b(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
xor    %ebp,%ebp
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%r14d
lea    0xec1(%rip),%rbx
nopw   0x0(%rax,%rax,1)
xorps  %xmm0,%xmm0
cvtsi2sd %rbp,%xmm0
mov    %rbx,%rdi
call   1030 <printf@plt>
add    $0x1,%rbp
cmp    $0xf4240,%rbp
jne    1150 <main+0x20>
lea    0xe94(%rip),%rdi
movsd  0xe84(%rip),%xmm0
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <time@plt>
mov    %eax,%edi
mov    %r14d,%esi
call   1040 <difftime@plt>
lea    0xe78(%rip),%rdi
call   1030 <printf@plt>
xor    %eax,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [9 x i8] c"i = %ld\0A\00"
@.str.1 = [15 x i8] c"elapsed = %lf\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca double
%5 = alloca i64
store i32 0, i32* %1
%6 = call i32 @time(i32* null)
store i32 %6, i32* %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 i32 @time(i32* null)
store i32 %21, i32* %3
%22 = load i32, i32* %3
%23 = load i32, i32* %2
%24 = call double @difftime(i32 %22, i32 %23)
store double %24, double* %4
%25 = load double, double* %4
%26 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %25)
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"i = %ld\0A\00"
@.str.1 = [15 x i8] c"elapsed = %lf\0A\00"
define i32 @main() {
%1 = tail call i32 @time(i32* null)
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 i32 @time(i32* null)
%11 = tail call double @difftime(i32 %10, i32 %1)
%12 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), double %11)
ret i32 0
}