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

/* Variables and functions */
double CLOCKS_PER_SEC;
int /*<<< orphan*/ _SC_CLK_TCK;
double clock();
int /*<<< orphan*/ printf(char *, int, ...);
int sysconf(int /*<<< orphan*/);
double times(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  clock_t start = 0, stop = 0;
  clock_t begin = 0, end = 0;
  start = clock();
  begin = times(0);
  int n = 0;
  for (; n < 10000; ++n)
    printf("this is %d\n", n);
  end = times(0);
  stop = clock();
  printf(
      "CLOCKS_PER_SEC = %ld, start = %ld, stop = %ld, elapsed = %ld (%f s)\n",
      CLOCKS_PER_SEC, start, stop, stop - start,
      1.0 * (stop - start) / CLOCKS_PER_SEC);
  int clk_tck = sysconf(_SC_CLK_TCK);
  printf("clk_tck = %d, begin = %ld, end = %ld, elapsed = %ld (%f s)\n",
         clk_tck, begin, end, end - begin, 1.0 * (end - begin) / clk_tck);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x18(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x20(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x28(%rbp)
xorps  %xmm0,%xmm0
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x18(%rbp)
xor    %edi,%edi
call   1050 <times@plt>
movsd  %xmm0,-0x28(%rbp)
movl   $0x0,-0x34(%rbp)
cmpl   $0x2710,-0x34(%rbp)
jge    11c1 <main+0x81>
mov    -0x34(%rbp),%esi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x34(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x34(%rbp)
jmp    1195 <main+0x55>
xor    %edi,%edi
call   1050 <times@plt>
movsd  %xmm0,-0x30(%rbp)
mov    $0x0,%al
call   1030 <clock@plt>
movsd  %xmm0,-0x20(%rbp)
mov    0x2e08(%rip),%rax
cvttsd2si (%rax),%esi
movsd  -0x18(%rbp),%xmm0
movsd  -0x20(%rbp),%xmm1
movsd  -0x20(%rbp),%xmm2
subsd  -0x18(%rbp),%xmm2
movsd  -0x20(%rbp),%xmm4
subsd  -0x18(%rbp),%xmm4
movsd  0xdf6(%rip),%xmm3
mulsd  %xmm4,%xmm3
mov    0x2dd3(%rip),%rax
divsd  (%rax),%xmm3
lea    0xdf4(%rip),%rdi
mov    $0x4,%al
call   1040 <printf@plt>
mov    0x2daa(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
mov    %eax,-0x38(%rbp)
mov    -0x38(%rbp),%esi
movsd  -0x28(%rbp),%xmm0
movsd  -0x30(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm2
subsd  -0x28(%rbp),%xmm2
movsd  -0x30(%rbp),%xmm4
subsd  -0x28(%rbp),%xmm4
movsd  0xd9f(%rip),%xmm3
mulsd  %xmm4,%xmm3
cvtsi2sdl -0x38(%rbp),%xmm4
divsd  %xmm4,%xmm3
lea    0xde4(%rip),%rdi
mov    $0x4,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1030 <clock@plt>
movsd  %xmm0,0x8(%rsp)
xor    %edi,%edi
call   1050 <times@plt>
movsd  %xmm0,0x10(%rsp)
lea    0xe99(%rip),%rbx
xor    %ebp,%ebp
nopl   0x0(%rax)
mov    %rbx,%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1040 <printf@plt>
add    $0x1,%ebp
cmp    $0x2710,%ebp
jne    1170 <main+0x30>
xor    %edi,%edi
call   1050 <times@plt>
movsd  %xmm0,(%rsp)
xor    %eax,%eax
call   1030 <clock@plt>
movapd %xmm0,%xmm1
mov    0x2e43(%rip),%rax
movsd  (%rax),%xmm4
cvttsd2si %xmm4,%esi
movapd %xmm0,%xmm2
movsd  0x8(%rsp),%xmm0
subsd  %xmm0,%xmm2
movapd %xmm2,%xmm3
divsd  %xmm4,%xmm3
lea    0xe42(%rip),%rdi
mov    $0x4,%al
call   1040 <printf@plt>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
call   1060 <sysconf@plt>
movsd  (%rsp),%xmm1
movapd %xmm1,%xmm2
movsd  0x10(%rsp),%xmm0
subsd  %xmm0,%xmm2
xorps  %xmm4,%xmm4
cvtsi2sd %eax,%xmm4
movapd %xmm2,%xmm3
divsd  %xmm4,%xmm3
lea    0xe49(%rip),%rdi
mov    %eax,%esi
mov    $0x4,%al
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [12 x i8] c"this is %d\0A\00"
@.str.1 = [69 x i8] c"CLOCKS_PER_SEC = %ld, start = %ld, stop = %ld, elapsed = %ld (%f s)\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@_SC_CLK_TCK = global i32 0
@.str.2 = [60 x i8] c"clk_tck = %d, begin = %ld, end = %ld, elapsed = %ld (%f s)\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca double
%7 = alloca double
%8 = alloca double
%9 = alloca double
%10 = alloca i32
%11 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store double 0.000000e+00, double* %6
store double 0.000000e+00, double* %7
store double 0.000000e+00, double* %8
store double 0.000000e+00, double* %9
%12 = call double (...) @clock()
store double %12, double* %6
%13 = call double @times(i32 0)
store double %13, double* %8
store i32 0, i32* %10
br label %14
14: ; preds = %20, %2
%15 = load i32, i32* %10
%16 = icmp slt i32 %15, 10000
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load i32, i32* %10
%19 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %17
%21 = load i32, i32* %10
%22 = add nsw i32 %21, 1
store i32 %22, i32* %10
br label %14
23: ; preds = %14
%24 = call double @times(i32 0)
store double %24, double* %9
%25 = call double (...) @clock()
store double %25, double* %7
%26 = load double, double* @CLOCKS_PER_SEC
%27 = fptosi double %26 to i32
%28 = load double, double* %6
%29 = load double, double* %7
%30 = load double, double* %7
%31 = load double, double* %6
%32 = fsub double %30, %31
%33 = load double, double* %7
%34 = load double, double* %6
%35 = fsub double %33, %34
%36 = fmul double 1.000000e+00, %35
%37 = load double, double* @CLOCKS_PER_SEC
%38 = fdiv double %36, %37
%39 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i32 %27, double %28, double %29, double %32, double %38)
%40 = load i32, i32* @_SC_CLK_TCK
%41 = call i32 @sysconf(i32 %40)
store i32 %41, i32* %11
%42 = load i32, i32* %11
%43 = load double, double* %8
%44 = load double, double* %9
%45 = load double, double* %9
%46 = load double, double* %8
%47 = fsub double %45, %46
%48 = load double, double* %9
%49 = load double, double* %8
%50 = fsub double %48, %49
%51 = fmul double 1.000000e+00, %50
%52 = load i32, i32* %11
%53 = sitofp i32 %52 to double
%54 = fdiv double %51, %53
%55 = call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i32 %42, double %43, double %44, double %47, double %54)
ret i32 0
}

LLVM IR (-O2):
@.str = [12 x i8] c"this is %d\0A\00"
@.str.1 = [69 x i8] c"CLOCKS_PER_SEC = %ld, start = %ld, stop = %ld, elapsed = %ld (%f s)\0A\00"
@CLOCKS_PER_SEC = global double 0.000000e+00
@_SC_CLK_TCK = global i32 0
@.str.2 = [60 x i8] c"clk_tck = %d, begin = %ld, end = %ld, elapsed = %ld (%f s)\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = tail call double (...) @clock()
%4 = tail call double @times(i32 0)
br label %5
5: ; preds = %2, %5
%6 = phi i32 [ 0, %2 ], [ %8, %5 ]
%7 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = add nuw nsw i32 %6, 1
%9 = icmp eq i32 %8, 10000
br i1 %9, label %10, label %5
10: ; preds = %5
%11 = tail call double @times(i32 0)
%12 = tail call double (...) @clock()
%13 = load double, double* @CLOCKS_PER_SEC
%14 = fptosi double %13 to i32
%15 = fsub double %12, %3
%16 = fdiv double %15, %13
%17 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([69 x i8], [69 x i8]* @.str.1, i64 0, i64 0), i32 %14, double %3, double %12, double %15, double %16)
%18 = load i32, i32* @_SC_CLK_TCK
%19 = tail call i32 @sysconf(i32 %18)
%20 = fsub double %11, %4
%21 = sitofp i32 %19 to double
%22 = fdiv double %20, %21
%23 = tail call i32 (i8*, i32, ...) @printf(i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.2, i64 0, i64 0), i32 %19, double %4, double %11, double %20, double %22)
ret i32 0
}