#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_sec;
  int tv_nsec;
};
typedef int clock_t;

/* Variables and functions */
int CLOCKS_PER_SEC;
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
clock_t clock_now(void) {
  struct timespec tm;
  clock_gettime(CLOCK_MONOTONIC, &tm);
  return tm.tv_sec * CLOCKS_PER_SEC + (tm.tv_nsec * (CLOCKS_PER_SEC / 1e9));
}


x86 assembly (clang, -O0):
<clock_now>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2ec9(%rip),%rax
mov    (%rax),%edi
lea    -0x8(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x8(%rbp),%eax
mov    0x2eac(%rip),%rcx
imul   (%rcx),%eax
cvtsi2sd %eax,%xmm1
cvtsi2sdl -0x4(%rbp),%xmm0
mov    0x2e99(%rip),%rax
cvtsi2sdl (%rax),%xmm2
movsd  0xead(%rip),%xmm3
divsd  %xmm3,%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<clock_now>:
push   %rax
mov    0x2ed0(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
call   1030 <clock_gettime@plt>
mov    0x2eb7(%rip),%rax
mov    (%rax),%eax
mov    (%rsp),%ecx
imul   %eax,%ecx
cvtsi2sd %ecx,%xmm0
cvtsi2sdl 0x4(%rsp),%xmm1
cvtsi2sd %eax,%xmm2
divsd  0xeb9(%rip),%xmm2
mulsd  %xmm1,%xmm2
addsd  %xmm0,%xmm2
cvttsd2si %xmm2,%eax
pop    %rcx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
@CLOCK_MONOTONIC = global i32 0
@CLOCKS_PER_SEC = global i32 0
define i32 @clock_now() {
%1 = alloca %struct.timespec
%2 = load i32, i32* @CLOCK_MONOTONIC
%3 = call i32 @clock_gettime(i32 %2, %struct.timespec* %1)
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
%5 = load i32, i32* %4
%6 = load i32, i32* @CLOCKS_PER_SEC
%7 = mul nsw i32 %5, %6
%8 = sitofp i32 %7 to double
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
%10 = load i32, i32* %9
%11 = sitofp i32 %10 to double
%12 = load i32, i32* @CLOCKS_PER_SEC
%13 = sitofp i32 %12 to double
%14 = fdiv double %13, 1.000000e+09
%15 = call double @llvm.fmuladd.f64(double %11, double %14, double %8)
%16 = fptosi double %15 to i32
ret i32 %16
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
@CLOCK_MONOTONIC = global i32 0
@CLOCKS_PER_SEC = global i32 0
define i32 @clock_now() {
%1 = alloca %struct.timespec
%2 = bitcast %struct.timespec* %1 to i8*
%3 = load i32, i32* @CLOCK_MONOTONIC
%4 = call i32 @clock_gettime(i32 %3, %struct.timespec* %1)
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%6 = load i32, i32* %5
%7 = load i32, i32* @CLOCKS_PER_SEC
%8 = mul nsw i32 %7, %6
%9 = sitofp i32 %8 to double
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%11 = load i32, i32* %10
%12 = sitofp i32 %11 to double
%13 = sitofp i32 %7 to double
%14 = fdiv double %13, 1.000000e+09
%15 = call double @llvm.fmuladd.f64(double %12, double %14, double %9)
%16 = fptosi double %15 to i32
ret i32 %16
}