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

/* Variables and functions */
struct timespec Timespec_add3(const struct timespec x, long long nsec) {
  struct timespec retval;
  long long n, m;
  const long long K = (1000LL * 1000LL * 1000LL);
  m = nsec + (long long)x.tv_nsec;
  n = m / K;
  m = m % K;
  retval.tv_sec = x.tv_sec + (int)n;
  retval.tv_nsec = (int)m;
  return retval;
}


x86 assembly (clang, -O0):
<Timespec_add3>:
push   %rbp
mov    %rsp,%rbp
mov    %edi,-0x20(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x28(%rbp)
movq   $0x3b9aca00,-0x40(%rbp)
3b
mov    -0x28(%rbp),%rax
movslq -0x20(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
movabs $0x112e0be826d694b3,%rcx
0b 2e 11
imul   %rcx
mov    %rdx,%rax
mov    %rax,%rdx
shr    $0x3f,%rdx
sar    $0x1a,%rax
add    %rdx,%rax
mov    %rax,-0x30(%rbp)
mov    -0x38(%rbp),%rax
mov    %rax,-0x48(%rbp)
imul   %rcx
mov    -0x48(%rbp),%rax
mov    %rdx,%rcx
mov    %rcx,%rdx
shr    $0x3f,%rdx
sar    $0x1a,%rcx
add    %rdx,%rcx
imul   $0x3b9aca00,%rcx,%rcx
sub    %rcx,%rax
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x30(%rbp),%rcx
add    %rcx,%rax
mov    %rax,-0x8(%rbp)
mov    -0x38(%rbp),%eax
mov    %eax,-0x10(%rbp)
mov    -0x10(%rbp),%eax
mov    -0x8(%rbp),%rdx
pop    %rbp
ret

x86 assembly (clang, -O2):
<Timespec_add3>:
movslq %edi,%rcx
add    %rdx,%rcx
movabs $0x112e0be826d694b3,%rdx
0b 2e 11
mov    %rcx,%rax
imul   %rdx
mov    %rdx,%rax
shr    $0x3f,%rax
sar    $0x1a,%rdx
add    %rax,%rdx
imul   $0x3b9aca00,%edx,%eax
sub    %eax,%ecx
movslq %edx,%rdx
add    %rsi,%rdx
mov    %ecx,%eax
ret

LLVM IR (-O0):
%struct.timespec = type { i32, i64 }
define { i32, i64 } @Timespec_add3(i32 %0, i64 %1, i64 %2) {
%4 = alloca %struct.timespec
%5 = alloca %struct.timespec
%6 = alloca i64
%7 = alloca i64
%8 = alloca i64
%9 = alloca i64
%10 = bitcast %struct.timespec* %5 to { i32, i64 }*
%11 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %10, i32 0, i32 0
store i32 %0, i32* %11
%12 = getelementptr inbounds { i32, i64 }, { i32, i64 }* %10, i32 0, i32 1
store i64 %1, i64* %12
store i64 %2, i64* %6
store i64 1000000000, i64* %9
%13 = load i64, i64* %6
%14 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 0
%15 = load i32, i32* %14
%16 = sext i32 %15 to i64
%17 = add nsw i64 %13, %16
store i64 %17, i64* %8
%18 = load i64, i64* %8
%19 = sdiv i64 %18, 1000000000
store i64 %19, i64* %7
%20 = load i64, i64* %8
%21 = srem i64 %20, 1000000000
store i64 %21, i64* %8
%22 = getelementptr inbounds %struct.timespec, %struct.timespec* %5, i32 0, i32 1
%23 = load i64, i64* %22
%24 = load i64, i64* %7
%25 = trunc i64 %24 to i32
%26 = sext i32 %25 to i64
%27 = add nsw i64 %23, %26
%28 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 1
store i64 %27, i64* %28
%29 = load i64, i64* %8
%30 = trunc i64 %29 to i32
%31 = getelementptr inbounds %struct.timespec, %struct.timespec* %4, i32 0, i32 0
store i32 %30, i32* %31
%32 = bitcast %struct.timespec* %4 to { i32, i64 }*
%33 = load { i32, i64 }, { i32, i64 }* %32
ret { i32, i64 } %33
}

LLVM IR (-O2):
define { i32, i64 } @Timespec_add3(i32 %0, i64 %1, i64 %2) {
%4 = sext i32 %0 to i64
%5 = add nsw i64 %4, %2
%6 = sdiv i64 %5, 1000000000
%7 = srem i64 %5, 1000000000
%8 = shl i64 %6, 32
%9 = ashr exact i64 %8, 32
%10 = add nsw i64 %9, %1
%11 = trunc i64 %7 to i32
%12 = insertvalue { i32, i64 } poison, i32 %11, 0
%13 = insertvalue { i32, i64 } %12, i64 %10, 1
ret { i32, i64 } %13
}