#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 *);
int /*<<< orphan*/ hton64(int /*<<< orphan*/);
void timestamp_tnbo(u_int64_t *vts, struct timespec *ts) {
  struct timespec sts;
  if (ts == NULL) {
    clock_monotonic(&sts);
    ts = &sts;
  }
  vts[0] = hton64(ts->tv_sec);
  vts[1] = hton64(ts->tv_nsec);
  return;
}


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

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

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
define void @timestamp_tnbo(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 = call i32 @hton64(i32 %13)
%15 = load i32*, i32** %3
%16 = getelementptr inbounds i32, i32* %15, i64 0
store i32 %14, i32* %16
%17 = load %struct.timespec*, %struct.timespec** %4
%18 = getelementptr inbounds %struct.timespec, %struct.timespec* %17, i32 0, i32 0
%19 = load i32, i32* %18
%20 = call i32 @hton64(i32 %19)
%21 = load i32*, i32** %3
%22 = getelementptr inbounds i32, i32* %21, i64 1
store i32 %20, i32* %22
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
define void @timestamp_tnbo(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
%12 = call i32 @hton64(i32 %11)
store i32 %12, i32* %0
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i64 0, i32 0
%14 = load i32, i32* %13
%15 = call i32 @hton64(i32 %14)
%16 = getelementptr inbounds i32, i32* %0, i64 1
store i32 %15, i32* %16
ret void
}