#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 {
  double tv_nsec;
  scalar_t__ tv_sec;
  int /*<<< orphan*/ member_1;
  int /*<<< orphan*/ member_0;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
int /*<<< orphan*/ loop();
int /*<<< orphan*/ printf(char *, double);
void get_clock() {
  struct timespec tstart = {0, 0}, tend = {0, 0};
  clock_gettime(CLOCK_MONOTONIC, &tstart);
  loop();
  clock_gettime(CLOCK_MONOTONIC, &tend);
  printf("some_long_computation took about %.5f seconds\n",
         ((double)tend.tv_sec + 1.0e-9 * tend.tv_nsec) -
             ((double)tstart.tv_sec + 1.0e-9 * tstart.tv_nsec));
}


x86 assembly (clang, -O0):
<get_clock>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
lea    -0x18(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
lea    -0x30(%rbp),%rdi
xor    %esi,%esi
mov    $0x18,%edx
call   1060 <memset@plt>
mov    0x2e79(%rip),%rax
mov    (%rax),%edi
lea    -0x18(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    $0x0,%al
call   1040 <loop@plt>
mov    0x2e60(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
call   1030 <clock_gettime@plt>
cvtsi2sdq -0x28(%rbp),%xmm1
movsd  -0x30(%rbp),%xmm0
movsd  0xe5a(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvtsi2sdq -0x10(%rbp),%xmm2
movsd  -0x18(%rbp),%xmm1
movsd  0xe3f(%rip),%xmm3
mulsd  %xmm3,%xmm1
addsd  %xmm2,%xmm1
subsd  %xmm1,%xmm0
lea    0xe34(%rip),%rdi
call   1050 <printf@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_clock>:
push   %rbx
sub    $0x40,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,0x20(%rsp)
movq   $0x0,0x30(%rsp)
movaps %xmm0,(%rsp)
movq   $0x0,0x10(%rsp)
mov    0x2e8e(%rip),%rbx
mov    (%rbx),%edi
lea    0x20(%rsp),%rsi
call   1030 <clock_gettime@plt>
xor    %eax,%eax
call   1040 <loop@plt>
mov    (%rbx),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
cvtsi2sdq 0x8(%rsp),%xmm1
movsd  0xe7a(%rip),%xmm2
movsd  (%rsp),%xmm0
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
xorps  %xmm1,%xmm1
cvtsi2sdq 0x28(%rsp),%xmm1
mulsd  0x20(%rsp),%xmm2
addsd  %xmm1,%xmm2
subsd  %xmm2,%xmm0
lea    0xe56(%rip),%rdi
call   1050 <printf@plt>
add    $0x40,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { double, i64, i32, i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [47 x i8] c"some_long_computation took about %.5f seconds\0A\00"
define void @get_clock() {
%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_MONOTONIC
%6 = call i32 @clock_gettime(i32 %5, %struct.timespec* %1)
%7 = call i32 (...) @loop()
%8 = load i32, i32* @CLOCK_MONOTONIC
%9 = call i32 @clock_gettime(i32 %8, %struct.timespec* %2)
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 1
%11 = load i64, i64* %10
%12 = sitofp i64 %11 to double
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i32 0, i32 0
%14 = load double, double* %13
%15 = call double @llvm.fmuladd.f64(double 1.000000e-09, double %14, double %12)
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
%17 = load i64, i64* %16
%18 = sitofp i64 %17 to double
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
%20 = load double, double* %19
%21 = call double @llvm.fmuladd.f64(double 1.000000e-09, double %20, double %18)
%22 = fsub double %15, %21
%23 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), double %22)
ret void
}

LLVM IR (-O2):
%struct.timespec = type { double, i64, i32, i32 }
@CLOCK_MONOTONIC = global i32 0
@.str = [47 x i8] c"some_long_computation took about %.5f seconds\0A\00"
define void @get_clock() {
%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_MONOTONIC
%6 = call i32 @clock_gettime(i32 %5, %struct.timespec* %1)
%7 = call i32 (...) @loop()
%8 = load i32, i32* @CLOCK_MONOTONIC
%9 = call i32 @clock_gettime(i32 %8, %struct.timespec* %2)
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%11 = load i64, i64* %10
%12 = sitofp i64 %11 to double
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%14 = load double, double* %13
%15 = call double @llvm.fmuladd.f64(double %14, double 1.000000e-09, double %12)
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%17 = load i64, i64* %16
%18 = sitofp i64 %17 to double
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%20 = load double, double* %19
%21 = call double @llvm.fmuladd.f64(double %20, double 1.000000e-09, double %18)
%22 = fsub double %15, %21
%23 = call i32 @printf(i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str, i64 0, i64 0), double %22)
ret void
}