#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*/ exit(int);
scalar_t__ gettimeofday(struct timeval *, struct timezone *);
int /*<<< orphan*/ perror(char *);
struct timespec wall_now() {
  struct timespec now_ts;
  struct timeval now_tv;
  struct timezone tz;
  if (0 != gettimeofday(&now_tv, &tz)) {
    perror("gettimeofday");
    exit(1);
  }
  {
    (&now_ts)->tv_sec = (&now_tv)->tv_sec;
    (&now_ts)->tv_nsec = (&now_tv)->tv_usec * 1000;
  };
  return now_ts;
}


x86 assembly (clang, -O0):
<wall_now>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    -0x10(%rbp),%rdi
lea    -0x18(%rbp),%rsi
call   1030 <gettimeofday@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1169 <wall_now+0x39>
lea    0xea6(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x4(%rbp)
imul   $0x3e8,-0x10(%rbp),%eax
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<wall_now>:
sub    $0x18,%rsp
lea    0x8(%rsp),%rdi
lea    0x10(%rsp),%rsi
call   1030 <gettimeofday@plt>
test   %rax,%rax
jne    1160 <wall_now+0x30>
imul   $0x3e8,0x8(%rsp),%eax
mov    0xc(%rsp),%ecx
shl    $0x20,%rcx
or     %rcx,%rax
add    $0x18,%rsp
ret
lea    0xe99(%rip),%rdi
call   1040 <perror@plt>
mov    $0x1,%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.timespec = type { i32, i32 }
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
@.str = [13 x i8] c"gettimeofday\00"
define i64 @wall_now() {
%1 = alloca %struct.timespec
%2 = alloca %struct.timeval
%3 = alloca %struct.timezone
%4 = call i64 @gettimeofday(%struct.timeval* %2, %struct.timezone* %3)
%5 = icmp ne i64 0, %4
br i1 %5, label %6, label %9
6: ; preds = %0
%7 = call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%8 = call i32 @exit(i32 1)
unreachable
9: ; preds = %0
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 1
%11 = load i32, i32* %10
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 1
store i32 %11, i32* %12
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %2, i32 0, i32 0
%14 = load i32, i32* %13
%15 = mul nsw i32 %14, 1000
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i32 0, i32 0
store i32 %15, i32* %16
%17 = bitcast %struct.timespec* %1 to i64*
%18 = load i64, i64* %17
ret i64 %18
}

LLVM IR (-O2):
%struct.timeval = type { i32, i32 }
%struct.timezone = type { i32 }
@.str = [13 x i8] c"gettimeofday\00"
define i64 @wall_now() {
%1 = alloca %struct.timeval
%2 = alloca %struct.timezone
%3 = bitcast %struct.timeval* %1 to i8*
%4 = bitcast %struct.timezone* %2 to i8*
%5 = call i64 @gettimeofday(%struct.timeval* %1, %struct.timezone* %2)
%6 = icmp eq i64 %5, 0
br i1 %6, label %10, label %7
7: ; preds = %0
%8 = tail call i32 @perror(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %0
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 1
%12 = load i32, i32* %11
%13 = getelementptr inbounds %struct.timeval, %struct.timeval* %1, i64 0, i32 0
%14 = load i32, i32* %13
%15 = mul nsw i32 %14, 1000
%16 = zext i32 %12 to i64
%17 = shl nuw i64 %16, 32
%18 = zext i32 %15 to i64
%19 = or i64 %17, %18
ret i64 %19
}