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

/* Variables and functions */
long long LONG_MAX;
void getTimeoutAbsolute(struct timespec *ts, long long millis,
                        long long nanos) {
  long long seconds = millis / 1000 + nanos / 1000000000;
  nanos %= 1000000000;
  nanos += (millis % 1000) * 1000000;
  if (nanos > 999999999) {
    seconds++;
    nanos -= 1000000000;
  }
  ts->tv_sec = seconds > LONG_MAX ? LONG_MAX : seconds;
  ts->tv_nsec = nanos;
}


x86 assembly (clang, -O0):
<getTimeoutAbsolute>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
mov    %rax,-0x28(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
add    %rcx,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    $0x3b9aca00,%ecx
cqto
idiv   %rcx
mov    %rdx,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    $0x3e8,%ecx
cqto
idiv   %rcx
imul   $0xf4240,%rdx,%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
cmpq   $0x3b9ac9ff,-0x18(%rbp)
3b
jle    1195 <getTimeoutAbsolute+0x95>
mov    -0x20(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
sub    $0x3b9aca00,%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rax
mov    0x2e40(%rip),%rcx
cmp    (%rcx),%rax
jle    11bc <getTimeoutAbsolute+0xbc>
mov    0x2e30(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x30(%rbp)
jmp    11c4 <getTimeoutAbsolute+0xc4>
mov    -0x20(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<getTimeoutAbsolute>:
mov    %rdx,%r8
movabs $0x112e0be826d694b3,%rcx
0b 2e 11
mov    %rdx,%rax
imul   %rcx
mov    %rdx,%rcx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x1a,%rcx
add    %rax,%rcx
movabs $0x20c49ba5e353f7cf,%rdx
9b c4 20
mov    %rsi,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x7,%rdx
add    %rax,%rdx
imul   $0x3b9aca00,%rcx,%rax
add    %rdx,%rcx
sub    %rax,%r8
imul   $0x3e8,%rdx,%rax
sub    %rax,%rsi
imul   $0xf4240,%rsi,%rax
lea    (%r8,%rax,1),%rdx
xor    %esi,%esi
cmp    $0x3b9aca00,%rdx
setge  %sil
lea    -0x3b9aca00(%rax,%r8,1),%rax
c4
cmovl  %rdx,%rax
add    %rcx,%rsi
mov    0x2e59(%rip),%rcx
mov    (%rcx),%rcx
cmp    %rcx,%rsi
cmovg  %rcx,%rsi
mov    %rsi,(%rdi)
mov    %rax,0x8(%rdi)
ret

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

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
@LONG_MAX = global i64 0
define void @getTimeoutAbsolute(%struct.timespec* nocapture writeonly %0, i64 %1, i64 %2) {
%4 = sdiv i64 %1, 1000
%5 = sdiv i64 %2, 1000000000
%6 = add nsw i64 %5, %4
%7 = srem i64 %2, 1000000000
%8 = srem i64 %1, 1000
%9 = mul nsw i64 %8, 1000000
%10 = add nsw i64 %7, %9
%11 = icmp sgt i64 %10, 999999999
%12 = add nsw i64 %10, -1000000000
%13 = select i1 %11, i64 %12, i64 %10
%14 = zext i1 %11 to i64
%15 = add nsw i64 %6, %14
%16 = load i64, i64* @LONG_MAX
%17 = icmp sgt i64 %15, %16
%18 = select i1 %17, i64 %16, i64 %15
%19 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
store i64 %18, i64* %19
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
store i64 %13, i64* %20
ret void
}