#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 int time_t;
struct timespec {
  int tv_sec;
  double tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
long round(double);
long current_time_ms(void) {
  long ms;
  time_t s;
  struct timespec spec;
  clock_gettime(CLOCK_REALTIME, &spec);
  s = spec.tv_sec;
  ms = round(spec.tv_nsec / 1.0e6);
  return (spec.tv_sec) * 1000 + (spec.tv_nsec) / 1000000;
}


x86 assembly (clang, -O0):
<current_time_ms>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2eb1(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x20(%rbp),%eax
mov    %eax,-0xc(%rbp)
movsd  -0x18(%rbp),%xmm0
movsd  0xeb3(%rip),%xmm1
divsd  %xmm1,%xmm0
call   1040 <round@plt>
mov    %rax,-0x8(%rbp)
imul   $0x3e8,-0x20(%rbp),%eax
cvtsi2sd %eax,%xmm0
movsd  -0x18(%rbp),%xmm1
movsd  0xe8e(%rip),%xmm2
divsd  %xmm2,%xmm1
addsd  %xmm1,%xmm0
cvttsd2si %xmm0,%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<current_time_ms>:
sub    $0x18,%rsp
mov    0x2eb5(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
movsd  0x10(%rsp),%xmm0
divsd  0xebb(%rip),%xmm0
call   1040 <round@plt>
imul   $0x3e8,0x8(%rsp),%eax
xorps  %xmm0,%xmm0
cvtsi2sd %eax,%xmm0
movsd  0x10(%rsp),%xmm1
divsd  0xe99(%rip),%xmm1
addsd  %xmm0,%xmm1
cvttsd2si %xmm1,%rax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, double }
@CLOCK_REALTIME = global i32 0
define i64 @current_time_ms() {
%1 = alloca i64
%2 = alloca i32
%3 = alloca %struct.timespec
%4 = load i32, i32* @CLOCK_REALTIME
%5 = call i32 @clock_gettime(i32 %4, %struct.timespec* %3)
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%7 = load i32, i32* %6
store i32 %7, i32* %2
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%9 = load double, double* %8
%10 = fdiv double %9, 1.000000e+06
%11 = call i64 @round(double %10)
store i64 %11, i64* %1
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%13 = load i32, i32* %12
%14 = mul nsw i32 %13, 1000
%15 = sitofp i32 %14 to double
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%17 = load double, double* %16
%18 = fdiv double %17, 1.000000e+06
%19 = fadd double %15, %18
%20 = fptosi double %19 to i64
ret i64 %20
}

LLVM IR (-O2):
%struct.timespec = type { i32, double }
@CLOCK_REALTIME = global i32 0
define i64 @current_time_ms() {
%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 0
%6 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%7 = load double, double* %6
%8 = fdiv double %7, 1.000000e+06
%9 = call i64 @round(double %8)
%10 = load i32, i32* %5
%11 = mul nsw i32 %10, 1000
%12 = sitofp i32 %11 to double
%13 = load double, double* %6
%14 = fdiv double %13, 1.000000e+06
%15 = fadd double %14, %12
%16 = fptosi double %15 to i64
ret i64 %16
}