#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 /*<<< orphan*/ u_int64_t;
struct timespec {
  int /*<<< orphan*/ tv_nsec;
  int /*<<< orphan*/ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ clock_monotonic(struct timespec *);
void timestamp(u_int64_t *vts, struct timespec *ts) {
  struct timespec sts;
  if (ts == NULL) {
    clock_monotonic(&sts);
    ts = &sts;
  }
  vts[0] = ts->tv_sec;
  vts[1] = ts->tv_nsec;
  return;
}


x86 assembly (clang, -O0):
<timestamp>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    113c <timestamp+0x2c>
lea    -0x18(%rbp),%rdi
call   1030 <clock_monotonic@plt>
lea    -0x18(%rbp),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timestamp>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %rdi,%r14
test   %rsi,%rsi
jne    112a <timestamp+0x1a>
mov    %rsp,%rbx
mov    %rbx,%rdi
call   1030 <clock_monotonic@plt>
mov    0x4(%rbx),%eax
mov    %eax,(%r14)
mov    (%rbx),%eax
mov    %eax,0x4(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define void @timestamp(i32* %0, %struct.timespec* %1) {
%3 = alloca i32*
%4 = alloca %struct.timespec*
%5 = alloca %struct.timespec
store i32* %0, i32** %3
store %struct.timespec* %1, %struct.timespec** %4
%6 = load %struct.timespec*, %struct.timespec** %4
%7 = icmp eq %struct.timespec* %6, null
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = call i32 @clock_monotonic(%struct.timespec* %5)
store %struct.timespec* %5, %struct.timespec** %4
br label %10
10: ; preds = %8, %2
%11 = load %struct.timespec*, %struct.timespec** %4
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %11, i32 0, i32 1
%13 = load i32, i32* %12
%14 = load i32*, i32** %3
%15 = getelementptr inbounds i32, i32* %14, i64 0
store i32 %13, i32* %15
%16 = load %struct.timespec*, %struct.timespec** %4
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %16, i32 0, i32 0
%18 = load i32, i32* %17
%19 = load i32*, i32** %3
%20 = getelementptr inbounds i32, i32* %19, i64 1
store i32 %18, i32* %20
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define void @timestamp(i32* nocapture writeonly %0, %struct.timespec* %1) {
%3 = alloca %struct.timespec
%4 = bitcast %struct.timespec* %3 to i8*
%5 = icmp eq %struct.timespec* %1, null
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = call i32 @clock_monotonic(%struct.timespec* %3)
br label %8
8: ; preds = %6, %2
%9 = phi %struct.timespec* [ %3, %6 ], [ %1, %2 ]
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i64 0, i32 1
%11 = load i32, i32* %10
store i32 %11, i32* %0
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i64 0, i32 0
%13 = load i32, i32* %12
%14 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %13, i32* %14
ret void
}