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

/* Variables and functions */
int /*<<< orphan*/ CLOCK_REALTIME;
int /*<<< orphan*/ clock_gettime(int /*<<< orphan*/, struct timespec *);
void set_timeout(long long timeout, struct timespec *time) {
  long nsec = (timeout % 1000000) * 1000;
  clock_gettime(CLOCK_REALTIME, time);
  time->tv_sec += timeout / 1000000;
  if (time->tv_nsec + nsec >= 1000000000) {
    time->tv_nsec += nsec - 1000000000;
    time->tv_sec += 1;
  } else
    time->tv_nsec += nsec;
}


x86 assembly (clang, -O0):
<set_timeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
imul   $0x3e8,%rdx,%rax
mov    %rax,-0x18(%rbp)
mov    0x2ea0(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rsi
call   1030 <clock_gettime@plt>
mov    -0x8(%rbp),%rax
mov    $0xf4240,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
add    -0x18(%rbp),%rax
cmp    $0x3b9aca00,%rax
jl     11a8 <set_timeout+0x98>
mov    -0x18(%rbp),%rcx
sub    $0x3b9aca00,%rcx
mov    -0x10(%rbp),%rax
add    0x8(%rax),%rcx
mov    %rcx,0x8(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rcx
add    $0x1,%rcx
mov    %rcx,(%rax)
jmp    11b8 <set_timeout+0xa8>
mov    -0x18(%rbp),%rcx
mov    -0x10(%rbp),%rax
add    0x8(%rax),%rcx
mov    %rcx,0x8(%rax)
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<set_timeout>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
movabs $0x431bde82d7b634db,%rcx
de 1b 43
mov    %rdi,%rax
imul   %rcx
mov    %rdx,%rbx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x12,%rbx
add    %rax,%rbx
imul   $0xf4240,%rbx,%rax
sub    %rax,%rdi
imul   $0x3e8,%rdi,%r15
mov    0x2e8f(%rip),%rax
mov    (%rax),%edi
call   1030 <clock_gettime@plt>
add    (%r14),%rbx
mov    %rbx,(%r14)
add    0x8(%r14),%r15
cmp    $0x3b9aca00,%r15
jl     117f <set_timeout+0x6f>
add    $0xffffffffc4653600,%r15
mov    %r15,0x8(%r14)
add    $0x1,%rbx
mov    %rbx,(%r14)
jmp    1183 <set_timeout+0x73>
mov    %r15,0x8(%r14)
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@CLOCK_REALTIME = global i32 0
define void @set_timeout(i64 %0, %struct.timespec* %1) {
%3 = srem i64 %0, 1000000
%4 = mul nsw i64 %3, 1000
%5 = load i32, i32* @CLOCK_REALTIME
%6 = tail call i32 @clock_gettime(i32 %5, %struct.timespec* %1)
%7 = sdiv i64 %0, 1000000
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 0
%9 = load i64, i64* %8
%10 = add nsw i64 %9, %7
store i64 %10, i64* %8
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %1, i64 0, i32 1
%12 = load i64, i64* %11
%13 = add i64 %12, %4
%14 = icmp sgt i64 %13, 999999999
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = add nsw i64 %13, -1000000000
store i64 %16, i64* %11
%17 = add nsw i64 %10, 1
store i64 %17, i64* %8
br label %19
18: ; preds = %2
store i64 %13, i64* %11
br label %19
19: ; preds = %18, %15
ret void
}