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

/* Variables and functions */
int /*<<< orphan*/ assert(int /*<<< orphan*/);
int /*<<< orphan*/ gettimeofday(struct timeval *, int /*<<< orphan*/ *);
void SetRelTimeout(struct timespec *time, int relMillis) {
  struct timeval now;
  int sec = relMillis / 1000;
  int milliSeconds = relMillis % 1000;
  assert(time != NULL);
  gettimeofday(&now, NULL);
  time->tv_sec = now.tv_sec + sec;
  time->tv_nsec = ((now.tv_usec / 1000) + milliSeconds) * 1000000;
}


x86 assembly (clang, -O0):
<SetRelTimeout>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %eax,-0x24(%rbp)
mov    -0xc(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
mov    %edx,-0x28(%rbp)
cmpq   $0x0,-0x8(%rbp)
setne  %al
and    $0x1,%al
movzbl %al,%edi
call   1040 <assert@plt>
lea    -0x20(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
call   1030 <gettimeofday@plt>
mov    -0x18(%rbp),%rcx
movslq -0x24(%rbp),%rax
add    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x20(%rbp),%eax
mov    $0x3e8,%ecx
cltd
idiv   %ecx
add    -0x28(%rbp),%eax
imul   $0xf4240,%eax,%ecx
mov    -0x8(%rbp),%rax
mov    %ecx,(%rax)
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<SetRelTimeout>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
movslq %esi,%r15
imul   $0x10624dd3,%r15,%rbx
mov    %rbx,%rax
shr    $0x3f,%rax
sar    $0x26,%rbx
add    %eax,%ebx
imul   $0x3e8,%ebx,%eax
sub    %eax,%r15d
xor    %edi,%edi
test   %r14,%r14
setne  %dil
call   1040 <assert@plt>
mov    %rsp,%rdi
xor    %esi,%esi
call   1030 <gettimeofday@plt>
movslq %ebx,%rax
add    0x8(%rsp),%rax
mov    %rax,0x8(%r14)
movslq (%rsp),%rax
imul   $0x10624dd3,%rax,%rax
mov    %rax,%rcx
shr    $0x3f,%rcx
sar    $0x26,%rax
add    %ecx,%eax
add    %r15d,%eax
imul   $0xf4240,%eax,%eax
mov    %eax,(%r14)
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

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

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