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

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
struct timespec time_now(void) {
  struct timespec result = {0};
  struct timeval tmp = {0};
  gettimeofday(&tmp, NULL);
  result.tv_sec = tmp.tv_sec;
  result.tv_nsec = 1000 * tmp.tv_usec;
  return result;
}


x86 assembly (clang, -O0):
<time_now>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x8(%rbp)
movq   $0x0,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movq   $0x0,-0x20(%rbp)
xor    %eax,%eax
mov    %eax,%esi
lea    -0x20(%rbp),%rdi
call   1030 <gettimeofday@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0xc(%rbp)
mov    -0x20(%rbp),%eax
imul   $0x3e8,%eax,%eax
mov    %eax,-0x10(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
mov    -0x28(%rbp),%edx
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<time_now>:
sub    $0x18,%rsp
movl   $0x0,0x10(%rsp)
movq   $0x0,0x8(%rsp)
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
imul   $0x3e8,0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
shl    $0x20,%rcx
or     %rcx,%rax
xor    %edx,%edx
add    $0x18,%rsp
ret

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

LLVM IR (-O2):
%struct.timeval = type { i32, i32, i32 }
define { i64, i32 } @time_now() {
%1 = alloca %struct.timeval
%2 = bitcast %struct.timeval* %1 to i8*
%3 = call i32 @gettimeofday(%struct.timeval* %1, i32* null)
%4 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%5 = load i32, i32* %4
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%7 = load i32, i32* %6
%8 = mul nsw i32 %7, 1000
%9 = zext i32 %5 to i64
%10 = shl nuw i64 %9, 32
%11 = zext i32 %8 to i64
%12 = or i64 %10, %11
%13 = insertvalue { i64, i32 } poison, i64 %12, 0
%14 = insertvalue { i64, i32 } %13, i32 0, 1
ret { i64, i32 } %14
}