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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, struct timezone *);
void rtl_timespec(struct timespec *tv) {
  struct timeval now;
  struct timezone tz;
  gettimeofday(&now, &tz);
  tv->tv_sec = now.tv_sec;
  tv->tv_nsec = now.tv_usec * 1000;
}


x86 assembly (clang, -O0):
<rtl_timespec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <gettimeofday@plt>
mov    -0xc(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,0x4(%rax)
imul   $0x3e8,-0x10(%rbp),%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<rtl_timespec>:
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%rbx
mov    %rsp,%rdi
lea    0x8(%rsp),%rsi
call   1030 <gettimeofday@plt>
mov    0x4(%rsp),%eax
mov    %eax,0x4(%rbx)
imul   $0x3e8,(%rsp),%eax
mov    %eax,(%rbx)
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
define void @rtl_timespec(%struct.timespec* %0) {
%2 = alloca %struct.timespec*
%3 = alloca %struct.timeval
%4 = alloca %struct.timezone
store %struct.timespec* %0, %struct.timespec** %2
%5 = call i32 @gettimeofday(%struct.timeval* %3, %struct.timezone* %4)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 1
%7 = load i32, i32* %6
%8 = load %struct.timespec*, %struct.timespec** %2
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %8, i32 0, i32 1
store i32 %7, i32* %9
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i32 0, i32 0
%11 = load i32, i32* %10
%12 = mul nsw i32 %11, 1000
%13 = load %struct.timespec*, %struct.timespec** %2
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %13, i32 0, i32 0
store i32 %12, i32* %14
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i32, i32 }
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
define void @rtl_timespec(%struct.timespec* nocapture writeonly %0) {
%2 = alloca %struct.timeval
%3 = alloca %struct.timezone
%4 = bitcast %struct.timeval* %2 to i8*
%5 = bitcast %struct.timezone* %3 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %2, %struct.timezone* %3)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 1
%8 = load i32, i32* %7
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
store i32 %8, i32* %9
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i64 0, i32 0
%11 = load i32, i32* %10
%12 = mul nsw i32 %11, 1000
%13 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
store i32 %12, i32* %13
ret void
}