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

/* Variables and functions */
int /*<<< orphan*/ timespec_now(struct timespec *);
void timespec_from_now_us(struct timespec *t, unsigned long long timeout_us) {
  timespec_now(t);
  unsigned long long nsec = t->tv_nsec + timeout_us * 1000UL;
  unsigned long long sec = nsec / 1000000000UL;
  t->tv_nsec = nsec - sec * 1000000000UL;
  t->tv_sec += sec;
}


x86 assembly (clang, -O0):
<timespec_from_now_us>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
call   1030 <timespec_now@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
imul   $0x3e8,-0x10(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x18(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x3b9aca00,%ecx
xor    %edx,%edx
div    %rcx
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rcx
imul   $0x3b9aca00,-0x20(%rbp),%rax
3b
sub    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
add    0x8(%rax),%rcx
mov    %rcx,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<timespec_from_now_us>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
call   1030 <timespec_now@plt>
imul   $0x3e8,%r14,%rcx
add    (%rbx),%rcx
mov    %rcx,%rax
shr    $0x9,%rax
movabs $0x44b82fa09b5a53,%rdx
mul    %rdx
shr    $0xb,%rdx
imul   $0xffffffffc4653600,%rdx,%rax
add    %rcx,%rax
mov    %rax,(%rbx)
add    %rdx,0x8(%rbx)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
define void @timespec_from_now_us(%struct.timespec* %0, i64 %1) {
%3 = alloca %struct.timespec*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i64
store %struct.timespec* %0, %struct.timespec** %3
store i64 %1, i64* %4
%7 = load %struct.timespec*, %struct.timespec** %3
%8 = call i32 @timespec_now(%struct.timespec* %7)
%9 = load %struct.timespec*, %struct.timespec** %3
%10 = getelementptr inbounds %struct.timespec, %struct.timespec* %9, i32 0, i32 0
%11 = load i64, i64* %10
%12 = load i64, i64* %4
%13 = mul i64 %12, 1000
%14 = add i64 %11, %13
store i64 %14, i64* %5
%15 = load i64, i64* %5
%16 = udiv i64 %15, 1000000000
store i64 %16, i64* %6
%17 = load i64, i64* %5
%18 = load i64, i64* %6
%19 = mul i64 %18, 1000000000
%20 = sub i64 %17, %19
%21 = load %struct.timespec*, %struct.timespec** %3
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %21, i32 0, i32 0
store i64 %20, i64* %22
%23 = load i64, i64* %6
%24 = load %struct.timespec*, %struct.timespec** %3
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %24, i32 0, i32 1
%26 = load i64, i64* %25
%27 = add i64 %26, %23
store i64 %27, i64* %25
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
define void @timespec_from_now_us(%struct.timespec* %0, i64 %1) {
%3 = tail call i32 @timespec_now(%struct.timespec* %0)
%4 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%5 = load i64, i64* %4
%6 = mul i64 %1, 1000
%7 = add i64 %5, %6
%8 = udiv i64 %7, 1000000000
%9 = mul i64 %8, -1000000000
%10 = add i64 %9, %7
store i64 %10, i64* %4
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%12 = load i64, i64* %11
%13 = add i64 %12, %8
store i64 %13, i64* %11
ret void
}