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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int UINT64_MAX;
int /*<<< orphan*/ assert(int);
int clock_gettime(int /*<<< orphan*/, struct timespec *);
int m_less(int, int);
int m_less_equal(scalar_t__, int);
uint64_t p_get_current_time(void) {
  struct timespec t;
  const int rv = clock_gettime(CLOCK_REALTIME, &t);
  assert(rv == 0);
  (void)rv;
  assert(m_less_equal(t.tv_sec, (UINT64_MAX - 1000) / 1000));
  assert(m_less(t.tv_nsec, (uint64_t)1000 * 1000 * 1000));
  return ((uint64_t)t.tv_sec) * 1000 + t.tv_nsec / (1000 * 1000);
}


x86 assembly (clang, -O0):
<p_get_current_time>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    0x2e91(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rdi
mov    0x2e57(%rip),%rax
mov    (%rax),%eax
sub    $0x3e8,%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
call   1060 <m_less_equal@plt>
mov    %eax,%edi
call   1040 <assert@plt>
mov    -0x10(%rbp),%edi
mov    $0x3b9aca00,%esi
call   1050 <m_less@plt>
mov    %eax,%edi
call   1040 <assert@plt>
mov    -0x8(%rbp),%rax
imul   $0x3e8,%eax,%eax
mov    %eax,-0x18(%rbp)
mov    -0x10(%rbp),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x18(%rbp),%eax
add    %ecx,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<p_get_current_time>:
sub    $0x18,%rsp
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1040 <assert@plt>
mov    0x10(%rsp),%rdi
mov    0x2e60(%rip),%rax
mov    $0xfffffc18,%ecx
add    (%rax),%ecx
movslq %ecx,%rax
imul   $0x10624dd3,%rax,%rsi
mov    %rsi,%rax
shr    $0x3f,%rax
sar    $0x26,%rsi
add    %eax,%esi
call   1060 <m_less_equal@plt>
mov    %eax,%edi
call   1040 <assert@plt>
mov    0x8(%rsp),%edi
mov    $0x3b9aca00,%esi
call   1050 <m_less@plt>
mov    %eax,%edi
call   1040 <assert@plt>
imul   $0x3e8,0x10(%rsp),%ecx
movslq 0x8(%rsp),%rax
imul   $0x431bde83,%rax,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x32,%rax
add    %edx,%eax
add    %ecx,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@CLOCK_REALTIME = global i32 0
@UINT64_MAX = global i32 0
define i32 @p_get_current_time() {
%1 = alloca %struct.timespec
%2 = alloca i32
%3 = load i32, i32* @CLOCK_REALTIME
%4 = call i32 @clock_gettime(i32 %3, %struct.timespec* %1)
store i32 %4, i32* %2
%5 = load i32, i32* %2
%6 = icmp eq i32 %5, 0
%7 = zext i1 %6 to i32
%8 = call i32 @assert(i32 %7)
%9 = load i32, i32* %2
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
%11 = load i64, i64* %10
%12 = load i32, i32* @UINT64_MAX
%13 = sub nsw i32 %12, 1000
%14 = sdiv i32 %13, 1000
%15 = call i32 @m_less_equal(i64 %11, i32 %14)
%16 = call i32 @assert(i32 %15)
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
%18 = load i32, i32* %17
%19 = call i32 @m_less(i32 %18, i32 1000000000)
%20 = call i32 @assert(i32 %19)
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
%22 = load i64, i64* %21
%23 = trunc i64 %22 to i32
%24 = mul nsw i32 %23, 1000
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
%26 = load i32, i32* %25
%27 = sdiv i32 %26, 1000000
%28 = add nsw i32 %24, %27
ret i32 %28
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@CLOCK_REALTIME = global i32 0
@UINT64_MAX = global i32 0
define i32 @p_get_current_time() {
%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 = icmp eq i32 %4, 0
%6 = zext i1 %5 to i32
%7 = call i32 @assert(i32 %6)
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%9 = load i64, i64* %8
%10 = load i32, i32* @UINT64_MAX
%11 = add nsw i32 %10, -1000
%12 = sdiv i32 %11, 1000
%13 = call i32 @m_less_equal(i64 %9, i32 %12)
%14 = call i32 @assert(i32 %13)
%15 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%16 = load i32, i32* %15
%17 = call i32 @m_less(i32 %16, i32 1000000000)
%18 = call i32 @assert(i32 %17)
%19 = load i64, i64* %8
%20 = trunc i64 %19 to i32
%21 = mul nsw i32 %20, 1000
%22 = load i32, i32* %15
%23 = sdiv i32 %22, 1000000
%24 = add nsw i32 %21, %23
ret i32 %24
}