#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;
};
typedef int int64_t;

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
scalar_t__ round(double);
int64_t getCurrentTimeMillis() {
  struct timespec spec;
  clock_gettime(CLOCK_REALTIME, &spec);
  const double seconds = (double)spec.tv_sec;
  const int64_t nanos = spec.tv_nsec / 1000000;
  return (int64_t)((seconds * 1000.0) + round((double)nanos));
}


x86 assembly (clang, -O0):
<getCurrentTimeMillis>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
cvtsi2sdq -0x8(%rbp),%xmm0
movsd  %xmm0,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,-0x1c(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  %xmm0,-0x28(%rbp)
cvtsi2sdl -0x1c(%rbp),%xmm0
call   1040 <round@plt>
movsd  -0x28(%rbp),%xmm0
cvtsi2sd %rax,%xmm1
movsd  0xe87(%rip),%xmm2
mulsd  %xmm2,%xmm0
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCurrentTimeMillis>:
sub    $0x18,%rsp
mov    0x2eb5(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
cvtsi2sdq 0x10(%rsp),%xmm0
movsd  %xmm0,(%rsp)
movslq 0x8(%rsp),%rax
imul   $0x431bde83,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x32,%rax
add    %ecx,%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
call   1040 <round@plt>
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
mulsd  0xe83(%rip),%xmm1
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@CLOCK_REALTIME = global i32 0
define i32 @getCurrentTimeMillis() {
%1 = alloca %struct.timespec
%2 = alloca double
%3 = alloca i32
%4 = load i32, i32* @CLOCK_REALTIME
%5 = call i32 @clock_gettime(i32 %4, %struct.timespec* %1)
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
%7 = load i64, i64* %6
%8 = sitofp i64 %7 to double
store double %8, double* %2
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
%10 = load i32, i32* %9
%11 = sdiv i32 %10, 1000000
store i32 %11, i32* %3
%12 = load double, double* %2
%13 = load i32, i32* %3
%14 = sitofp i32 %13 to double
%15 = call i64 @round(double %14)
%16 = sitofp i64 %15 to double
%17 = call double @llvm.fmuladd.f64(double %12, double 1.000000e+03, double %16)
%18 = fptosi double %17 to i32
ret i32 %18
}

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