#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 */
typedef scalar_t__ time_t;
struct timespec {
  unsigned long long tv_nsec;
  scalar_t__ tv_sec;
};

/* Variables and functions */
void task_add_nanos_to_timespec(struct timespec *time, unsigned long long add) {
  unsigned long long nanoseconds = time->tv_nsec;
  time_t seconds = time->tv_sec;
  nanoseconds += add;
  time->tv_sec = seconds + nanoseconds / 1000000000;
  time->tv_nsec = nanoseconds % 1000000000;
}


x86 assembly (clang, -O0):
<task_add_nanos_to_timespec>:
push   %rbp
mov    %rsp,%rbp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
mov    -0x8(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
add    -0x18(%rbp),%rax
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    $0x3b9aca00,%esi
xor    %edx,%edx
div    %rsi
add    %rax,%rcx
mov    -0x8(%rbp),%rax
mov    %rcx,0x8(%rax)
mov    -0x18(%rbp),%rax
mov    $0x3b9aca00,%ecx
xor    %edx,%edx
div    %rcx
mov    -0x8(%rbp),%rax
mov    %rdx,(%rax)
pop    %rbp
ret

x86 assembly (clang, -O2):
<task_add_nanos_to_timespec>:
add    (%rdi),%rsi
mov    %rsi,%rax
shr    $0x9,%rax
movabs $0x44b82fa09b5a53,%rcx
mul    %rcx
shr    $0xb,%rdx
add    %rdx,0x8(%rdi)
imul   $0x3b9aca00,%rdx,%rax
sub    %rax,%rsi
mov    %rsi,(%rdi)
ret

LLVM IR (-O0):
%struct.timespec = type { i64, i64 }
define void @task_add_nanos_to_timespec(%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 = getelementptr inbounds %struct.timespec, %struct.timespec* %7, i32 0, i32 0
%9 = load i64, i64* %8
store i64 %9, i64* %5
%10 = load %struct.timespec*, %struct.timespec** %3
%11 = getelementptr inbounds %struct.timespec, %struct.timespec* %10, i32 0, i32 1
%12 = load i64, i64* %11
store i64 %12, i64* %6
%13 = load i64, i64* %4
%14 = load i64, i64* %5
%15 = add i64 %14, %13
store i64 %15, i64* %5
%16 = load i64, i64* %6
%17 = load i64, i64* %5
%18 = udiv i64 %17, 1000000000
%19 = add i64 %16, %18
%20 = load %struct.timespec*, %struct.timespec** %3
%21 = getelementptr inbounds %struct.timespec, %struct.timespec* %20, i32 0, i32 1
store i64 %19, i64* %21
%22 = load i64, i64* %5
%23 = urem i64 %22, 1000000000
%24 = load %struct.timespec*, %struct.timespec** %3
%25 = getelementptr inbounds %struct.timespec, %struct.timespec* %24, i32 0, i32 0
store i64 %23, i64* %25
ret void
}

LLVM IR (-O2):
%struct.timespec = type { i64, i64 }
define void @task_add_nanos_to_timespec(%struct.timespec* nocapture %0, i64 %1) {
%3 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 0
%4 = load i64, i64* %3
%5 = getelementptr inbounds %struct.timespec, %struct.timespec* %0, i64 0, i32 1
%6 = load i64, i64* %5
%7 = add i64 %4, %1
%8 = udiv i64 %7, 1000000000
%9 = add i64 %8, %6
store i64 %9, i64* %5
%10 = urem i64 %7, 1000000000
store i64 %10, i64* %3
ret void
}