#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 {
  long tv_sec;
  long tv_usec;
};
struct timespec {
  long tv_sec;
  long tv_nsec;
};

/* Variables and functions */
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
void make_timespec(struct timespec *tsp, long delta_msec) {
  struct timeval now;
  gettimeofday(&now, NULL);
  tsp->tv_sec = now.tv_sec;
  tsp->tv_nsec = 1000L * now.tv_usec;
  tsp->tv_nsec += (delta_msec * 1000000L);
  if (tsp->tv_nsec > 1000000000L) {
    long secs = tsp->tv_nsec / 1000000000L;
    tsp->tv_sec += secs;
    tsp->tv_nsec -= (secs * 1000000000L);
  }
}


x86 assembly (clang, -O0):
<make_timespec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
imul   $0x3e8,-0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
imul   $0xf4240,-0x10(%rbp),%rcx
mov    -0x8(%rbp),%rax
add    0x8(%rax),%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x3b9aca00,0x8(%rax)
3b
jle    11a9 <make_timespec+0x99>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rcx
mov    -0x8(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
imul   $0x3b9aca00,-0x28(%rbp),%rdx
3b
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
sub    %rdx,%rcx
mov    %rcx,0x8(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<make_timespec>:
push   %r14
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r14
mov    %rdi,%rbx
lea    0x8(%rsp),%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
mov    0x8(%rsp),%rsi
mov    %rsi,(%rbx)
imul   $0x3e8,0x10(%rsp),%rax
imul   $0xf4240,%r14,%rcx
add    %rax,%rcx
mov    %rcx,0x8(%rbx)
cmp    $0x3b9aca01,%rcx
jl     117d <make_timespec+0x6d>
mov    %rcx,%rax
shr    $0x9,%rax
movabs $0x44b82fa09b5a53,%rdx
mul    %rdx
shr    $0xb,%rdx
add    %rdx,%rsi
mov    %rsi,(%rbx)
imul   $0xffffffffc4653600,%rdx,%rax
add    %rcx,%rax
mov    %rax,0x8(%rbx)
add    $0x18,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
%struct.timeval = type { i64, i64 }
define void @make_timespec(%struct.timespec* %0, i64 %1) {
%3 = alloca %struct.timespec*
%4 = alloca i64
%5 = alloca %struct.timeval
%6 = alloca i64
store %struct.timespec* %0, %struct.timespec** %3
store i64 %1, i64* %4
%7 = call i32 @gettimeofday(%struct.timeval* %5, i32* null)
%8 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 0
%9 = load i64, i64* %8
%10 = load %struct.timespec*, %struct.timespec** %3
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 0
store i64 %9, i64* %11
%12 = getelementptr inbounds %struct.timeval, %struct.timeval* %5, i32 0, i32 1
%13 = load i64, i64* %12
%14 = mul nsw i64 1000, %13
%15 = load %struct.timespec*, %struct.timespec** %3
%16 = getelementptr inbounds %struct.timespec, %struct.timespec* %15, i32 0, i32 1
store i64 %14, i64* %16
%17 = load i64, i64* %4
%18 = mul nsw i64 %17, 1000000
%19 = load %struct.timespec*, %struct.timespec** %3
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %19, i32 0, i32 1
%21 = load i64, i64* %20
%22 = add nsw i64 %21, %18
store i64 %22, i64* %20
%23 = load %struct.timespec*, %struct.timespec** %3
%24 = getelementptr inbounds %struct.timespec, %struct.timespec* %23, i32 0, i32 1
%25 = load i64, i64* %24
%26 = icmp sgt i64 %25, 1000000000
br i1 %26, label %27, label %43
27: ; preds = %2
%28 = load %struct.timespec*, %struct.timespec** %3
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %28, i32 0, i32 1
%30 = load i64, i64* %29
%31 = sdiv i64 %30, 1000000000
store i64 %31, i64* %6
%32 = load i64, i64* %6
%33 = load %struct.timespec*, %struct.timespec** %3
%34 = getelementptr inbounds %struct.timespec, %struct.timespec* %33, i32 0, i32 0
%35 = load i64, i64* %34
%36 = add nsw i64 %35, %32
store i64 %36, i64* %34
%37 = load i64, i64* %6
%38 = mul nsw i64 %37, 1000000000
%39 = load %struct.timespec*, %struct.timespec** %3
%40 = getelementptr inbounds %struct.timespec, %struct.timespec* %39, i32 0, i32 1
%41 = load i64, i64* %40
%42 = sub nsw i64 %41, %38
store i64 %42, i64* %40
br label %43
43: ; preds = %27, %2
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
%struct.timeval = type { i64, i64 }
define void @make_timespec(%struct.timespec* nocapture %0, i64 %1) {
%3 = alloca %struct.timeval
%4 = bitcast %struct.timeval* %3 to i8*
%5 = call i32 @gettimeofday(%struct.timeval* %3, i32* null)
%6 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 0
%7 = load i64, i64* %6
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
store i64 %7, i64* %8
%9 = getelementptr inbounds %struct.timeval, %struct.timeval* %3, i64 0, i32 1
%10 = load i64, i64* %9
%11 = mul nsw i64 %10, 1000
%12 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%13 = mul nsw i64 %1, 1000000
%14 = add nsw i64 %11, %13
store i64 %14, i64* %12
%15 = icmp sgt i64 %14, 1000000000
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = udiv i64 %14, 1000000000
%18 = add nsw i64 %17, %7
store i64 %18, i64* %8
%19 = mul nsw i64 %17, -1000000000
%20 = add nsw i64 %19, %14
store i64 %20, i64* %12
br label %21
21: ; preds = %16, %2
ret void
}