#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 tv_nsec;
  scalar_t__ tv_sec;
};
typedef double offset;

/* Variables and functions */
long round(double);
scalar_t__ trunc(double);
void tplusdtime(struct timespec *ttp, double offset) {
  struct timespec tp;
  do {
    ((&tp)->tv_sec) = trunc(offset);
    ((&tp)->tv_nsec) =
        round((double)1000000000L * ((offset) - ((&tp)->tv_sec)));
  } while (0);
  do {
    ((ttp)->tv_sec) += ((&tp)->tv_sec);
    ((ttp)->tv_nsec) += ((&tp)->tv_nsec);
    if (((ttp)->tv_nsec) >= 1000000000L) {
      ((ttp)->tv_sec)++;
      ((ttp)->tv_nsec) -= 1000000000L;
    }
  } while (0);
}


x86 assembly (clang, -O0):
<tplusdtime>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movsd  %xmm0,-0x10(%rbp)
movsd  -0x10(%rbp),%xmm0
call   1030 <trunc@plt>
mov    %rax,-0x18(%rbp)
movsd  -0x10(%rbp),%xmm1
cvtsi2sdq -0x18(%rbp),%xmm0
subsd  %xmm0,%xmm1
movsd  0xeaa(%rip),%xmm0
mulsd  %xmm1,%xmm0
call   1040 <round@plt>
mov    %rax,-0x20(%rbp)
jmp    1168 <tplusdtime+0x48>
mov    -0x18(%rbp),%rcx
mov    -0x8(%rbp),%rax
add    0x8(%rax),%rcx
mov    %rcx,0x8(%rax)
mov    -0x20(%rbp),%rcx
mov    -0x8(%rbp),%rax
add    (%rax),%rcx
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rax
cmpq   $0x3b9aca00,(%rax)
jl     11b8 <tplusdtime+0x98>
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rcx
add    $0x1,%rcx
mov    %rcx,0x8(%rax)
mov    -0x8(%rbp),%rax
mov    (%rax),%rcx
sub    $0x3b9aca00,%rcx
mov    %rcx,(%rax)
jmp    11bd <tplusdtime+0x9d>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tplusdtime>:
push   %r14
push   %rbx
push   %rax
movsd  %xmm0,(%rsp)
mov    %rdi,%r14
call   1030 <trunc@plt>
mov    %rax,%rbx
xorps  %xmm0,%xmm0
cvtsi2sd %rax,%xmm0
movsd  (%rsp),%xmm1
subsd  %xmm0,%xmm1
mulsd  0xeb3(%rip),%xmm1
movapd %xmm1,%xmm0
call   1040 <round@plt>
add    0x8(%r14),%rbx
mov    %rbx,0x8(%r14)
add    (%r14),%rax
mov    %rax,(%r14)
cmp    $0x3b9aca00,%rax
jl     117d <tplusdtime+0x5d>
add    $0x1,%rbx
mov    %rbx,0x8(%r14)
add    $0xffffffffc4653600,%rax
mov    %rax,(%r14)
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
define void @tplusdtime(%struct.timespec* %0, double %1) {
%3 = alloca %struct.timespec*
%4 = alloca double
%5 = alloca %struct.timespec
store %struct.timespec* %0, %struct.timespec** %3
store double %1, double* %4
br label %6
6: ; preds = %2
%7 = load double, double* %4
%8 = call i64 @trunc(double %7)
%9 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
store i64 %8, i64* %9
%10 = load double, double* %4
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%12 = load i64, i64* %11
%13 = sitofp i64 %12 to double
%14 = fsub double %10, %13
%15 = fmul double 1.000000e+09, %14
%16 = call i64 @round(double %15)
%17 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
store i64 %16, i64* %17
br label %18
18: ; preds = %6
br label %19
19: ; preds = %18
%20 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%21 = load i64, i64* %20
%22 = load %struct.timespec*, %struct.timespec** %3
%23 = getelementptr inbounds %struct.timespec, %struct.timespec* %22, i32 0, i32 1
%24 = load i64, i64* %23
%25 = add nsw i64 %24, %21
store i64 %25, i64* %23
%26 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%27 = load i64, i64* %26
%28 = load %struct.timespec*, %struct.timespec** %3
%29 = getelementptr inbounds %struct.timespec, %struct.timespec* %28, i32 0, i32 0
%30 = load i64, i64* %29
%31 = add nsw i64 %30, %27
store i64 %31, i64* %29
%32 = load %struct.timespec*, %struct.timespec** %3
%33 = getelementptr inbounds %struct.timespec, %struct.timespec* %32, i32 0, i32 0
%34 = load i64, i64* %33
%35 = icmp sge i64 %34, 1000000000
br i1 %35, label %36, label %45
36: ; preds = %19
%37 = load %struct.timespec*, %struct.timespec** %3
%38 = getelementptr inbounds %struct.timespec, %struct.timespec* %37, i32 0, i32 1
%39 = load i64, i64* %38
%40 = add nsw i64 %39, 1
store i64 %40, i64* %38
%41 = load %struct.timespec*, %struct.timespec** %3
%42 = getelementptr inbounds %struct.timespec, %struct.timespec* %41, i32 0, i32 0
%43 = load i64, i64* %42
%44 = sub nsw i64 %43, 1000000000
store i64 %44, i64* %42
br label %45
45: ; preds = %36, %19
br label %46
46: ; preds = %45
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
define void @tplusdtime(%struct.timespec* nocapture %0, double %1) {
%3 = tail call i64 @trunc(double %1)
%4 = sitofp i64 %3 to double
%5 = fsub double %1, %4
%6 = fmul double %5, 1.000000e+09
%7 = tail call i64 @round(double %6)
%8 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%9 = load i64, i64* %8
%10 = add nsw i64 %9, %3
store i64 %10, i64* %8
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%12 = load i64, i64* %11
%13 = add nsw i64 %12, %7
store i64 %13, i64* %11
%14 = icmp sgt i64 %13, 999999999
br i1 %14, label %15, label %18
15: ; preds = %2
%16 = add nsw i64 %10, 1
store i64 %16, i64* %8
%17 = add nsw i64 %13, -1000000000
store i64 %17, i64* %11
br label %18
18: ; preds = %15, %2
ret void
}