#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 */
struct timespec {
  int tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ printf(char *, scalar_t__);
int main(void) {
  int i = 0;
  int y = 0;
  struct timespec t0, t1;
  clock_gettime(CLOCK_REALTIME, &t0);
  while (i > 0) {
    i--;
    y = 0xFFFFFFF;
    while (y > 0)
      y--;
  }
  clock_gettime(CLOCK_REALTIME, &t1);
  printf("%lf nsecs elapsed \n",
         (t1.tv_sec - t0.tv_sec) + (t1.tv_nsec - t0.tv_nsec) * 1e-9);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0x0,-0x8(%rbp)
movl   $0x0,-0xc(%rbp)
mov    0x2e9c(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmpl   $0x0,-0x8(%rbp)
jle    1186 <main+0x66>
mov    -0x8(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0x8(%rbp)
movl   $0xfffffff,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jle    1181 <main+0x61>
mov    -0xc(%rbp),%eax
add    $0xffffffff,%eax
mov    %eax,-0xc(%rbp)
jmp    1169 <main+0x49>
jmp    114f <main+0x2f>
mov    0x2e53(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x28(%rbp),%rax
sub    -0x18(%rbp),%rax
cvtsi2sd %rax,%xmm1
mov    -0x30(%rbp),%eax
sub    -0x20(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  0xe49(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rsi
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x20,%rsp
mov    0x2eb4(%rip),%rbx
mov    (%rbx),%edi
lea    0x10(%rsp),%rsi
call   1030 <clock_gettime@plt>
mov    (%rbx),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
mov    0x8(%rsp),%rax
sub    0x18(%rsp),%rax
cvtsi2sd %rax,%xmm0
mov    (%rsp),%eax
sub    0x10(%rsp),%eax
cvtsi2sd %eax,%xmm1
mulsd  0xe9c(%rip),%xmm1
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rsi
lea    0xe94(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@CLOCK_REALTIME = global i32 0
@.str = [20 x i8] c"%lf nsecs elapsed \0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca %struct.timespec
%5 = alloca %struct.timespec
store i32 0, i32* %1
store i32 0, i32* %2
store i32 0, i32* %3
%6 = load i32, i32* @CLOCK_REALTIME
%7 = call i32 @clock_gettime(i32 %6, %struct.timespec* %4)
br label %8
8: ; preds = %20, %0
%9 = load i32, i32* %2
%10 = icmp sgt i32 %9, 0
br i1 %10, label %11, label %21
11: ; preds = %8
%12 = load i32, i32* %2
%13 = add nsw i32 %12, -1
store i32 %13, i32* %2
store i32 268435455, i32* %3
br label %14
14: ; preds = %17, %11
%15 = load i32, i32* %3
%16 = icmp sgt i32 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %14
%18 = load i32, i32* %3
%19 = add nsw i32 %18, -1
store i32 %19, i32* %3
br label %14
20: ; preds = %14
br label %8
21: ; preds = %8
%22 = load i32, i32* @CLOCK_REALTIME
%23 = call i32 @clock_gettime(i32 %22, %struct.timespec* %5)
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%25 = load i64, i64* %24
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
%27 = load i64, i64* %26
%28 = sub nsw i64 %25, %27
%29 = sitofp i64 %28 to double
%30 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%31 = load i32, i32* %30
%32 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
%33 = load i32, i32* %32
%34 = sub nsw i32 %31, %33
%35 = sitofp i32 %34 to double
%36 = call double @llvm.fmuladd.f64(double %35, double 1.000000e-09, double %29)
%37 = fptosi double %36 to i64
%38 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i64 %37)
ret i32 0
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@CLOCK_REALTIME = global i32 0
@.str = [20 x i8] c"%lf nsecs elapsed \0A\00"
define i32 @main() {
%1 = alloca %struct.timespec
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %1 to i8*
%4 = bitcast %struct.timespec* %2 to i8*
%5 = load i32, i32* @CLOCK_REALTIME
%6 = call i32 @clock_gettime(i32 %5, %struct.timespec* %1)
%7 = load i32, i32* @CLOCK_REALTIME
%8 = call i32 @clock_gettime(i32 %7, %struct.timespec* %2)
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%10 = load i64, i64* %9
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%12 = load i64, i64* %11
%13 = sub nsw i64 %10, %12
%14 = sitofp i64 %13 to double
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%18 = load i32, i32* %17
%19 = sub nsw i32 %16, %18
%20 = sitofp i32 %19 to double
%21 = call double @llvm.fmuladd.f64(double %20, double 1.000000e-09, double %14)
%22 = fptosi double %21 to i64
%23 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i64 %22)
ret i32 0
}