#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 */
double CLOCKS_PER_SEC;
scalar_t__ clock();
int /*<<< orphan*/ printf(char *, ...);
int main(void) {
  int i = 0;
  printf("Clock started.\r\n");
  clock_t start = clock();
  for (i = i; i < 100000; i++) {
  }
  clock_t end = clock();
  double time_took = (double)(end - start) / CLOCKS_PER_SEC;
  printf("Clock done. Execution took %lf seconds.\r\n", time_took);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
lea    0xec3(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x8(%rbp)
cmpl   $0x186a0,-0x8(%rbp)
jge    1175 <main+0x55>
jmp    1167 <main+0x47>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    1155 <main+0x35>
mov    $0x0,%al
call   1030 <clock@plt>
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
sub    -0x10(%rbp),%rax
cvtsi2sd %rax,%xmm0
mov    0x2e54(%rip),%rax
divsd  (%rax),%xmm0
movsd  %xmm0,-0x20(%rbp)
movsd  -0x20(%rbp),%xmm0
lea    0xe68(%rip),%rdi
mov    $0x1,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
lea    0xef2(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
call   1040 <clock@plt>
mov    %rax,%rbx
xor    %eax,%eax
call   1040 <clock@plt>
sub    %rbx,%rax
cvtsi2sd %rax,%xmm0
mov    0x2e8b(%rip),%rax
divsd  (%rax),%xmm0
lea    0xe98(%rip),%rdi
mov    $0x1,%al
call   1050 <printf@plt>
xor    %eax,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [17 x i8] c"Clock started.\0D\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [42 x i8] c"Clock done. Execution took %lf seconds.\0D\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i64
%4 = alloca i64
%5 = alloca double
store i32 0, i32* %1
store i32 0, i32* %2
%6 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%7 = call i64 (...) @clock()
store i64 %7, i64* %3
%8 = load i32, i32* %2
store i32 %8, i32* %2
br label %9
9: ; preds = %13, %0
%10 = load i32, i32* %2
%11 = icmp slt i32 %10, 100000
br i1 %11, label %12, label %16
12: ; preds = %9
br label %13
13: ; preds = %12
%14 = load i32, i32* %2
%15 = add nsw i32 %14, 1
store i32 %15, i32* %2
br label %9
16: ; preds = %9
%17 = call i64 (...) @clock()
store i64 %17, i64* %4
%18 = load i64, i64* %4
%19 = load i64, i64* %3
%20 = sub nsw i64 %18, %19
%21 = sitofp i64 %20 to double
%22 = load double, double* @CLOCKS_PER_SEC
%23 = fdiv double %21, %22
store double %23, double* %5
%24 = load double, double* %5
%25 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), double %24)
%26 = load i32, i32* %1
ret i32 %26
}

LLVM IR (-O2):
@CLOCKS_PER_SEC = global double 0.000000e+00
@.str.1 = [42 x i8] c"Clock done. Execution took %lf seconds.\0D\0A\00"
@str = [16 x i8] c"Clock started.\0D\00"
define i32 @main() {
%1 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @str, i64 0, i64 0))
%2 = tail call i64 (...) @clock()
%3 = tail call i64 (...) @clock()
%4 = sub nsw i64 %3, %2
%5 = sitofp i64 %4 to double
%6 = load double, double* @CLOCKS_PER_SEC
%7 = fdiv double %5, %6
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([42 x i8], [42 x i8]* @.str.1, i64 0, i64 0), double %7)
ret i32 0
}