#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 scalar_t__ time_t;
typedef int suseconds_t;
struct timeval {
  int tv_usec;
  scalar_t__ tv_sec;
};
struct timespec {
  long tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
void get_wait_timespec(time_t secs, suseconds_t microsec,
                       struct timespec *out) {
  struct timeval now;
  long nanosecs;
  gettimeofday(&now, NULL);
  nanosecs = now.tv_usec * 1000 + microsec * 1000;
  out->tv_sec = now.tv_sec + secs + nanosecs / (1000 * 1000 * 1000);
  out->tv_nsec = nanosecs % (1000 * 1000 * 1000);
}


x86 assembly (clang, -O0):
<get_wait_timespec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
lea    -0x28(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
imul   $0x3e8,-0x28(%rbp),%eax
imul   $0x3e8,-0xc(%rbp),%ecx
add    %ecx,%eax
cltq
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rcx
add    -0x8(%rbp),%rcx
mov    -0x30(%rbp),%rax
mov    $0x3b9aca00,%esi
cqto
idiv   %rsi
add    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x30(%rbp),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    -0x18(%rbp),%rax
mov    %rdx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_wait_timespec>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%rbx
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
add    (%rsp),%ebp
imul   $0x3e8,%ebp,%eax
add    0x8(%rsp),%rbx
cltq
imul   $0x44b82fa1,%rax,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x3c,%rcx
add    %edx,%ecx
movslq %ecx,%rcx
add    %rcx,%rbx
mov    %rbx,0x8(%r14)
imul   $0x3b9aca00,%ecx,%ecx
sub    %ecx,%eax
cltq
mov    %rax,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
%struct.timeval = type { i32, i64 }
define void @get_wait_timespec(i64 %0, i32 %1, %struct.timespec* %2) {
%4 = alloca i64
%5 = alloca i32
%6 = alloca %struct.timespec*
%7 = alloca %struct.timeval
%8 = alloca i64
store i64 %0, i64* %4
store i32 %1, i32* %5
store %struct.timespec* %2, %struct.timespec** %6
%9 = call i32 @gettimeofday(%struct.timeval* %7, i32* null)
%10 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 0
%11 = load i32, i32* %10
%12 = mul nsw i32 %11, 1000
%13 = load i32, i32* %5
%14 = mul nsw i32 %13, 1000
%15 = add nsw i32 %12, %14
%16 = sext i32 %15 to i64
store i64 %16, i64* %8
%17 = getelementptr inbounds %struct.timeval, %struct.timeval* %7, i32 0, i32 1
%18 = load i64, i64* %17
%19 = load i64, i64* %4
%20 = add nsw i64 %18, %19
%21 = load i64, i64* %8
%22 = sdiv i64 %21, 1000000000
%23 = add nsw i64 %20, %22
%24 = load %struct.timespec*, %struct.timespec** %6
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %24, i32 0, i32 1
store i64 %23, i64* %25
%26 = load i64, i64* %8
%27 = srem i64 %26, 1000000000
%28 = load %struct.timespec*, %struct.timespec** %6
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %28, i32 0, i32 0
store i64 %27, i64* %29
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
%struct.timeval = type { i32, i64 }
define void @get_wait_timespec(i64 %0, i32 %1, %struct.timespec* nocapture writeonly %2) {
%4 = alloca %struct.timeval
%5 = bitcast %struct.timeval* %4 to i8*
%6 = call i32 @gettimeofday(%struct.timeval* %4, i32* null)
%7 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 0
%8 = load i32, i32* %7
%9 = add i32 %8, %1
%10 = mul i32 %9, 1000
%11 = getelementptr inbounds %struct.timeval, %struct.timeval* %4, i64 0, i32 1
%12 = load i64, i64* %11
%13 = add nsw i64 %12, %0
%14 = sdiv i32 %10, 1000000000
%15 = sext i32 %14 to i64
%16 = add nsw i64 %13, %15
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 1
store i64 %16, i64* %17
%18 = srem i32 %10, 1000000000
%19 = sext i32 %18 to i64
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %2, i64 0, i32 0
store i64 %19, i64* %20
ret void
}