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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_MONOTONIC;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
time_t monotime(struct timeval *tvo) {
  struct timespec ts;
  clock_gettime(CLOCK_MONOTONIC, &ts);
  if (tvo) {
    do {
      (tvo)->tv_sec = (&ts)->tv_sec;
      (tvo)->tv_usec = (&ts)->tv_nsec / 1000;
    } while (0);
  }
  return ts.tv_sec;
}


x86 assembly (clang, -O0):
<monotime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    0x2ec5(%rip),%rax
mov    (%rax),%edi
lea    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
cmpq   $0x0,-0x8(%rbp)
je     1160 <monotime+0x50>
jmp    113e <monotime+0x2e>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
mov    -0x10(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
jmp    1160 <monotime+0x50>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<monotime>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    0x2ec9(%rip),%rax
mov    (%rax),%edi
lea    0x8(%rsp),%rsi
call   1030 <clock_gettime@plt>
mov    0xc(%rsp),%eax
test   %rbx,%rbx
je     1152 <monotime+0x42>
mov    %eax,0x4(%rbx)
movslq 0x8(%rsp),%rcx
imul   $0x10624dd3,%rcx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x26,%rcx
add    %edx,%ecx
mov    %ecx,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timeval = type { i32, i32 }
%struct.timespec = type { i32, i32 }
@CLOCK_MONOTONIC = global i32 0
define i32 @monotime(%struct.timeval* %0) {
%2 = alloca %struct.timeval*
%3 = alloca %struct.timespec
store %struct.timeval* %0, %struct.timeval** %2
%4 = load i32, i32* @CLOCK_MONOTONIC
%5 = call i32 @clock_gettime(i32 %4, %struct.timespec* %3)
%6 = load %struct.timeval*, %struct.timeval** %2
%7 = icmp ne %struct.timeval* %6, null
br i1 %7, label %8, label %20
8: ; preds = %1
br label %9
9: ; preds = %8
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%11 = load i32, i32* %10
%12 = load %struct.timeval*, %struct.timeval** %2
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %12, i32 0, i32 1
store i32 %11, i32* %13
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 0
%15 = load i32, i32* %14
%16 = sdiv i32 %15, 1000
%17 = load %struct.timeval*, %struct.timeval** %2
%18 = getelementptr inbounds %struct.timeval, %struct.timeval* %17, i32 0, i32 0
store i32 %16, i32* %18
br label %19
19: ; preds = %9
br label %20
20: ; preds = %19, %1
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %3, i32 0, i32 1
%22 = load i32, i32* %21
ret i32 %22
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.timespec = type { i32, i32 }
@CLOCK_MONOTONIC = global i32 0
define i32 @monotime(%struct.timeval* writeonly %0) {
%2 = alloca %struct.timespec
%3 = bitcast %struct.timespec* %2 to i8*
%4 = load i32, i32* @CLOCK_MONOTONIC
%5 = call i32 @clock_gettime(i32 %4, %struct.timespec* %2)
%6 = icmp eq %struct.timeval* %0, null
%7 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
%8 = load i32, i32* %7
br i1 %6, label %15, label %9
9: ; preds = %1
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 1
store i32 %8, i32* %10
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
%12 = load i32, i32* %11
%13 = sdiv i32 %12, 1000
%14 = getelementptr inbounds %struct.timeval, %struct.timeval* %0, i64 0, i32 0
store i32 %13, i32* %14
br label %15
15: ; preds = %1, %9
ret i32 %8
}