#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;
};

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
void getCurrentTime(int *seconds, int *milliseconds) {
  static bool first = true;
  static struct timespec origin;
  if (first) {
    clock_gettime(CLOCK_MONOTONIC, &origin);
    first = false;
  }
  struct timespec now;
  clock_gettime(CLOCK_MONOTONIC, &now);
  *seconds = (int)(now.tv_sec - origin.tv_sec);
  *milliseconds = (int)((now.tv_nsec - origin.tv_nsec) / 1000000);
}


x86 assembly (clang, -O0):
<getCurrentTime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x0,0x2f01(%rip)
je     114c <getCurrentTime+0x3c>
mov    0x2eb4(%rip),%rax
mov    (%rax),%edi
lea    0x2efb(%rip),%rsi
call   1030 <clock_gettime@plt>
movl   $0x0,0x2edc(%rip)
mov    0x2e95(%rip),%rax
mov    (%rax),%edi
lea    -0x20(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x18(%rbp),%rax
sub    0x2ed7(%rip),%rax
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x20(%rbp),%eax
sub    0x2ebe(%rip),%eax
mov    $0xf4240,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getCurrentTime>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
cmpb   $0x0,0x2f0c(%rip)
jne    1142 <getCurrentTime+0x32>
mov    0x2ebb(%rip),%rax
mov    (%rax),%edi
lea    0x2f02(%rip),%rsi
call   1030 <clock_gettime@plt>
movb   $0x1,0x2eee(%rip)
mov    0x2e9f(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
mov    0x10(%rsp),%eax
sub    0x2ee1(%rip),%eax
mov    %eax,(%rbx)
mov    0x8(%rsp),%eax
sub    0x2ecd(%rip),%eax
cltq
imul   $0x431bde83,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x32,%rax
add    %ecx,%eax
mov    %eax,(%r14)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
@getCurrentTime.first = internal global i32 1
@getCurrentTime.origin = internal global %struct.timespec zeroinitializer
@CLOCK_MONOTONIC = global i32 0
define void @getCurrentTime(i32* %0, i32* %1) {
%3 = alloca i32*
%4 = alloca i32*
%5 = alloca %struct.timespec
store i32* %0, i32** %3
store i32* %1, i32** %4
%6 = load i32, i32* @getCurrentTime.first
%7 = icmp ne i32 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = load i32, i32* @CLOCK_MONOTONIC
%10 = call i32 @clock_gettime(i32 %9, %struct.timespec* @getCurrentTime.origin)
store i32 0, i32* @getCurrentTime.first
br label %11
11: ; preds = %8, %2
%12 = load i32, i32* @CLOCK_MONOTONIC
%13 = call i32 @clock_gettime(i32 %12, %struct.timespec* %5)
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%15 = load i64, i64* %14
%16 = load i64, i64* getelementptr inbounds (%struct.timespec, %struct.timespec* @getCurrentTime.origin, i32 0, i32 1)
%17 = sub nsw i64 %15, %16
%18 = trunc i64 %17 to i32
%19 = load i32*, i32** %3
store i32 %18, i32* %19
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%21 = load i32, i32* %20
%22 = load i32, i32* getelementptr inbounds (%struct.timespec, %struct.timespec* @getCurrentTime.origin, i32 0, i32 0)
%23 = sub nsw i32 %21, %22
%24 = sdiv i32 %23, 1000000
%25 = load i32*, i32** %4
store i32 %24, i32* %25
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i64 }
@getCurrentTime.first = internal unnamed_addr global i1 false
@getCurrentTime.origin = internal global %struct.timespec zeroinitializer
@CLOCK_MONOTONIC = global i32 0
define void @getCurrentTime(i32* nocapture writeonly %0, i32* nocapture writeonly %1) {
%3 = alloca %struct.timespec
%4 = load i1, i1* @getCurrentTime.first
br i1 %4, label %8, label %5
5: ; preds = %2
%6 = load i32, i32* @CLOCK_MONOTONIC
%7 = tail call i32 @clock_gettime(i32 %6, %struct.timespec* @getCurrentTime.origin)
store i1 true, i1* @getCurrentTime.first
br label %8
8: ; preds = %5, %2
%9 = bitcast %struct.timespec* %3 to i8*
%10 = load i32, i32* @CLOCK_MONOTONIC
%11 = call i32 @clock_gettime(i32 %10, %struct.timespec* %3)
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 1
%13 = load i64, i64* %12
%14 = load i64, i64* getelementptr inbounds (%struct.timespec, %struct.timespec* @getCurrentTime.origin, i64 0, i32 1)
%15 = sub nsw i64 %13, %14
%16 = trunc i64 %15 to i32
store i32 %16, i32* %0
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i64 0, i32 0
%18 = load i32, i32* %17
%19 = load i32, i32* getelementptr inbounds (%struct.timespec, %struct.timespec* @getCurrentTime.origin, i64 0, i32 0)
%20 = sub nsw i32 %18, %19
%21 = sdiv i32 %20, 1000000
store i32 %21, i32* %1
ret void
}